import {z} from 'zod' export type Memory = 'cold' | 'cached' | 'pinned'; export type HnswConfigDiff = {m?: (number | null) | undefined, ef_construct?: (number | null) | undefined, full_scan_threshold?: (number | null) | undefined, max_indexing_threads?: (number | null) | undefined, on_disk?: (boolean | null) | undefined, memory?: (Memory | unknown) | undefined, payload_m?: (number | null) | undefined, inline_storage?: (boolean | null) | undefined}; export type ScalarType = 'int8'; export type ScalarQuantizationConfig = {type: ScalarType, quantile?: (number | null) | undefined, always_ram?: (boolean | null) | undefined, memory?: (Memory | unknown) | undefined}; export type ScalarQuantization = {scalar: ScalarQuantizationConfig}; export type CompressionRatio = 'x4' | 'x8' | 'x16' | 'x32' | 'x64'; export type ProductQuantizationConfig = {compression: CompressionRatio, always_ram?: (boolean | null) | undefined, memory?: (Memory | unknown) | undefined}; export type ProductQuantization = {product: ProductQuantizationConfig}; export type BinaryQuantizationEncoding = 'one_bit' | 'two_bits' | 'one_and_half_bits'; export type BinaryQuantizationQueryEncoding = 'default' | 'binary' | 'scalar4bits' | 'scalar8bits'; export type BinaryQuantizationConfig = {always_ram?: (boolean | null) | undefined, memory?: (Memory | unknown) | undefined, encoding?: (BinaryQuantizationEncoding | unknown) | undefined, query_encoding?: (BinaryQuantizationQueryEncoding | unknown) | undefined}; export type BinaryQuantization = {binary: BinaryQuantizationConfig}; export type TurboQuantBitSize = 'bits1' | 'bits1_5' | 'bits2' | 'bits4' | 'bits8'; export type TurboQuantQuantizationConfig = {always_ram?: (boolean | null) | undefined, memory?: (Memory | unknown) | undefined, bits?: (TurboQuantBitSize | unknown) | undefined}; export type TurboQuantization = {turbo: TurboQuantQuantizationConfig}; export type Disabled = 'Disabled'; export type QuantizationConfigDiff = ScalarQuantization | ProductQuantization | BinaryQuantization | TurboQuantization | Disabled; export type VectorParamsDiff = {hnsw_config?: (HnswConfigDiff | unknown) | undefined, quantization_config?: (QuantizationConfigDiff | unknown) | undefined, on_disk?: (boolean | null) | undefined, memory?: (Memory | unknown) | undefined}; export type VectorsConfigDiff = {[key: string]: VectorParamsDiff}; export type MaxOptimizationThreadsSetting = 'auto'; export type MaxOptimizationThreads = MaxOptimizationThreadsSetting | number; export type OptimizersConfigDiff = {deleted_threshold?: (number | null) | undefined, vacuum_min_vector_number?: (number | null) | undefined, default_segment_number?: (number | null) | undefined, max_segment_size?: (number | null) | undefined, memmap_threshold?: (number | null) | undefined, indexing_threshold?: (number | null) | undefined, flush_interval_sec?: (number | null) | undefined, max_optimization_threads?: (MaxOptimizationThreads | unknown) | undefined, prevent_unoptimized?: (boolean | null) | undefined}; export type PayloadStorageParams = {memory?: (Memory | unknown) | undefined}; export type IdTrackerParams = {memory?: (Memory | unknown) | undefined}; export type CollectionParamsDiff = {replication_factor?: (number | null) | undefined, write_consistency_factor?: (number | null) | undefined, read_fan_out_factor?: (number | null) | undefined, read_fan_out_delay_ms?: (number | null) | undefined, on_disk_payload?: (boolean | null) | undefined, payload?: (PayloadStorageParams | unknown) | undefined, id_tracker?: (IdTrackerParams | unknown) | undefined}; export type Datatype = 'float32' | 'uint8' | 'float16' | 'turbo4' | 'turbo8' | 'turbo16'; export type SparseIndexParams = {full_scan_threshold?: (number | null) | undefined, on_disk?: (boolean | null) | undefined, memory?: (Memory | unknown) | undefined, datatype?: (Datatype | unknown) | undefined}; export type Modifier = 'none' | 'idf'; export type SparseVectorParams = {index?: (SparseIndexParams | unknown) | undefined, modifier?: (Modifier | unknown) | undefined}; export type SparseVectorsConfig = {[key: string]: SparseVectorParams}; export type StrictModeMultivector = {max_vectors?: (number | null) | undefined}; export type StrictModeMultivectorConfig = {[key: string]: StrictModeMultivector}; export type StrictModeSparse = {max_length?: (number | null) | undefined}; export type StrictModeSparseConfig = {[key: string]: StrictModeSparse}; export type StrictModeConfig = {enabled?: (boolean | null) | undefined, max_query_limit?: (number | null) | undefined, max_timeout?: (number | null) | undefined, unindexed_filtering_retrieve?: (boolean | null) | undefined, unindexed_filtering_update?: (boolean | null) | undefined, search_max_hnsw_ef?: (number | null) | undefined, search_allow_exact?: (boolean | null) | undefined, search_max_oversampling?: (number | null) | undefined, upsert_max_batchsize?: (number | null) | undefined, search_max_batchsize?: (number | null) | undefined, max_collection_vector_size_bytes?: (number | null) | undefined, read_rate_limit?: (number | null) | undefined, write_rate_limit?: (number | null) | undefined, max_collection_payload_size_bytes?: (number | null) | undefined, max_points_count?: (number | null) | undefined, filter_max_conditions?: (number | null) | undefined, condition_max_size?: (number | null) | undefined, multivector_config?: (StrictModeMultivectorConfig | unknown) | undefined, sparse_config?: (StrictModeSparseConfig | unknown) | undefined, max_payload_index_count?: (number | null) | undefined, max_resident_memory_percent?: (number | null) | undefined}; export type Payload = {[key: string]: unknown}; export type UpdateCollection = {vectors?: (VectorsConfigDiff | unknown) | undefined, optimizers_config?: (OptimizersConfigDiff | unknown) | undefined, params?: (CollectionParamsDiff | unknown) | undefined, hnsw_config?: (HnswConfigDiff | unknown) | undefined, quantization_config?: (QuantizationConfigDiff | unknown) | undefined, sparse_vectors?: (SparseVectorsConfig | unknown) | undefined, strict_mode_config?: (StrictModeConfig | unknown) | undefined, metadata?: (Payload | unknown) | undefined}; export type PatchApiCollectionsCollectionNameArgs = {collection_name: string, timeout?: number | undefined, body: UpdateCollection}; export type PatchApiCollectionsCollectionNameOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const hardwareUsage = z.object({cpu: z.number().int().gte(0), payload_io_read: z.number().int().gte(0), payload_io_write: z.number().int().gte(0), payload_index_io_read: z.number().int().gte(0), payload_index_io_write: z.number().int().gte(0), vector_io_read: z.number().int().gte(0), vector_io_write: z.number().int().gte(0)}); export const modelUsage = z.object({tokens: z.number().int().gte(0)}); export const inferenceUsage = z.object({models: z.record(z.string(), modelUsage)}); export const usage = z.object({hardware: z.union([hardwareUsage, z.unknown()]).optional(), inference: z.union([inferenceUsage, z.unknown()]).optional()}); export const patchApiCollectionsCollectionNameResponse = z.object({usage: z.union([usage, z.unknown()]).optional(), time: z.number().optional(), status: z.string().optional(), result: z.boolean().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update collection parameters * * PATCH /collections/{collection_name} * * Also accepts auth: bearerAuth */ export const patchApiCollectionsCollectionName = async (args: PatchApiCollectionsCollectionNameArgs, options?: PatchApiCollectionsCollectionNameOptions) => { const {baseUrl = "http://localhost:6333", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.timeout != null) query.append("timeout", String(args.timeout)) if (apiKey !== undefined) headers.set("api-key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/collections/${encodeURIComponent(String(args.collection_name))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(patchApiCollectionsCollectionNameResponse, await res.json()) };