import type { DistanceMetric } from './HNSWIndex.js'; /** JSON values accepted as collection metadata. */ export type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue; }; /** A metadata object that can be persisted by Verso. */ export type Metadata = Record; /** Public vector input accepted by insert and search operations. */ export type VectorInput = number[] | Float32Array; export type { DistanceMetric }; export type CollectionProfile = 'low-memory' | 'balanced' | 'high-recall' | 'low-latency'; export interface VectorSchema { dimensions: number; metric?: DistanceMetric; } export type MetadataFieldType = 'string' | 'number' | 'boolean' | 'string[]' | 'number[]' | 'boolean[]' | 'object' | 'any'; export interface MetadataFieldSchema { type: MetadataFieldType; index?: true | 'exact' | 'range' | 'contains' | false; } export type MetadataSchema = Record; /** Adapter shape supported by schema validators such as Zod or Valibot. */ export interface MetadataValidator { parse(value: unknown): TMetadata; } export type MetadataSchemaOption = MetadataSchema | MetadataValidator; export interface HNSWIndexConfig { type: 'hnsw'; m?: number; efConstruction?: number; profile?: CollectionProfile; } export type IndexConfig = 'auto' | HNSWIndexConfig; export interface CollectionConfig { vector: VectorSchema; index?: IndexConfig; profile?: CollectionProfile; metadataSchema?: MetadataSchemaOption; /** Shorthand for a persisted descriptor schema. */ metadata?: MetadataSchema; } export type CollectionSchema = CollectionConfig; export interface VectorRecordInput { id: string; vector: VectorInput; metadata?: TMetadata; } export interface VectorRecord { id: string; vector?: Float32Array; metadata?: TMetadata; } export interface InsertOptions { signal?: AbortSignal; } export interface InsertManyOptions extends InsertOptions { batchSize?: number; concurrency?: number | 'auto'; onProgress?: (count: number) => void; } export interface ImportOptions extends InsertManyOptions { /** `insert` rejects existing IDs; `upsert` replaces them. */ mode?: 'insert' | 'upsert'; } export interface PackedInsert extends InsertOptions { ids: readonly string[]; vectors: Float32Array; metadata?: readonly TMetadata[]; } export interface UpdatePatch extends InsertOptions { /** Shallow-merged into the existing metadata object. */ metadata?: Partial; /** Replaces the vector while retaining the merged metadata. */ vector?: VectorInput; } export interface UpdateManyRequest extends InsertOptions { filter?: Filter; set: Partial; } export interface IncludeOptions { metadata?: boolean; vector?: boolean; } export interface SearchTuning { efSearch?: number; quantization?: 'auto' | 'enabled' | 'disabled'; oversampling?: number; } export type SearchAccuracy = 'fast' | 'balanced' | 'high' | 'exact'; export type SearchStrategy = 'auto' | 'exact' | { type: 'auto'; accuracy?: SearchAccuracy; } | { type: 'hnsw'; efSearch?: number; quantization?: 'auto' | 'enabled' | 'disabled'; oversampling?: number; } | { type: 'exact'; }; export interface SearchStats { strategy: 'hnsw' | 'exact'; visitedNodes?: number; candidateCount: number; filteredCandidates: number; exactRescoreCount?: number; quantizedTraversal: boolean; durationMs: number; } export interface SearchMatch { id: string; /** Metric-native distance. Lower is always better. */ distance: number; /** Stable application-facing ranking score. Higher is always better. */ score: number; metadata?: TMetadata; vector?: Float32Array; rank?: number; } export interface SearchResult { matches: Array>; stats?: SearchStats; } export type QueryOptions = SearchOptions; export type QueryMatch = SearchMatch; export type QueryResult = SearchResult; export interface SearchOptions { vector: VectorInput; limit: number; filter?: Filter; include?: IncludeOptions; accuracy?: SearchAccuracy; strategy?: SearchStrategy; tuning?: SearchTuning; signal?: AbortSignal; explain?: boolean; } export interface SearchManyOptions extends InsertOptions { concurrency?: number | 'auto'; } export interface ListOptions { limit?: number; cursor?: string; filter?: Filter; include?: IncludeOptions; signal?: AbortSignal; } export interface ListPage { records: Array>; nextCursor?: string; } export interface GetOptions extends InsertOptions { include?: IncludeOptions; } export interface ScanOptions extends GetOptions { filter?: Filter; batchSize?: number; } export interface DeleteRequest extends InsertOptions { ids?: readonly string[]; filter?: Filter; all?: boolean; } export interface CompactOptions extends InsertOptions { onProgress?: (progress: { phase: string; completed: number; total: number; }) => void; } export interface CompactResult { recordsBefore: number; recordsAfter: number; tombstonesRemoved: number; bytesBefore?: number; bytesAfter?: number; durationMs: number; } export interface CollectionDescription { name: string; count: number; deletedCount: number; vector: VectorSchema; index: { type: 'hnsw'; m: number; efConstruction: number; quantization: { enabled: boolean; }; }; storage: { persisted: boolean; bytes?: number; dirty: boolean; }; metadataSchema?: MetadataSchema; } export interface CollectionStats extends CollectionDescription { records: number; liveRecords: number; tombstones: number; dimensions: number; indexBytes?: number; metadataBytes?: number; quantizationEnabled: boolean; lastFlushedAt?: Date; } export interface VerificationReport { ok: boolean; records: number; tombstones: number; errors: string[]; } export interface DurabilityBatchOptions { mode: 'batched'; maxOperations?: number; maxDelayMs?: number; } export type Durability = 'immediate' | 'manual' | DurabilityBatchOptions; export type StorageKind = 'auto' | 'file' | 'opfs' | 'memory'; export interface StorageOptions { type?: StorageKind; path?: string; namespace?: string; fallback?: 'error' | 'memory' | 'warn'; } export interface StorageAdapter { readonly type?: string; read(key: string): Promise; write(key: string, data: ArrayBuffer | Uint8Array): Promise; append?(key: string, data: ArrayBuffer | Uint8Array): Promise; delete(key: string): Promise; exists(key: string): Promise; list(prefix?: string): Promise; mkdir(path: string): Promise; } export interface ConcurrencyOptions { /** OPFS uses the Web Locks API when available; file backends serialize in-process. */ mode?: 'single-writer'; lockTimeoutMs?: number; } export interface VectorDBOptions { path?: string; storage?: StorageOptions | 'memory' | StorageAdapter; durability?: Durability; workers?: 'auto' | number | { count: number; }; concurrency?: ConcurrencyOptions; } export interface StorageStatus { kind: string; persistent: boolean; path?: string; namespace?: string; quota?: { usage?: number; available?: number; }; workers?: number; } export interface DatabaseDescription { collections: number; storage: StorageStatus; names: string[]; } export interface CollectionListOptions { includeStats?: boolean; } export interface CollectionListEntry extends CollectionDescription { } export interface Snapshot { version: 1; createdAt: string; entries: Record; files: Record; checksum?: string; } export interface BackupOptions { /** Refuse to write into a non-empty destination unless explicitly enabled. */ overwrite?: boolean; } export interface CollectionSnapshot { version: 1; collection: string; config: CollectionConfig; files: Record; checksum?: string; } export interface WriteSession { insert(records: readonly VectorRecordInput[], options?: InsertOptions): Promise; upsert(records: readonly VectorRecordInput[], options?: InsertOptions): Promise; update(id: string, patch: UpdatePatch): Promise; delete(request: DeleteRequest): Promise; } export type SearchMethod = (options: SearchOptions) => Promise>; /** A small typed filter language; unsupported operators are rejected at runtime. */ export type FieldFilter = { $eq?: T; $ne?: T; $gt?: T; $gte?: T; $lt?: T; $lte?: T; $in?: readonly T[] | readonly unknown[]; $nin?: readonly T[] | readonly unknown[]; $exists?: boolean; $contains?: unknown; $containsAny?: readonly unknown[]; $containsAll?: readonly unknown[]; $startsWith?: string; $between?: readonly [T, T] | readonly [unknown, unknown]; }; export type FilterLogic = { $and?: readonly Filter[]; $or?: readonly Filter[]; $not?: Filter; }; export type Filter = { [K in keyof TMetadata]?: TMetadata[K] | FieldFilter; } & FilterLogic; export interface WhereBuilder { eq(field: string, value: T): Filter; ne(field: string, value: T): Filter; gt(field: string, value: T): Filter; gte(field: string, value: T): Filter; lt(field: string, value: T): Filter; lte(field: string, value: T): Filter; in(field: string, value: readonly T[]): Filter; nin(field: string, value: readonly T[]): Filter; exists(field: string, value?: boolean): Filter; contains(field: string, value: T): Filter; containsAny(field: string, value: readonly T[]): Filter; containsAll(field: string, value: readonly T[]): Filter; startsWith(field: string, value: string): Filter; between(field: string, value: readonly [T, T]): Filter; and(...filters: Filter[]): Filter; or(...filters: Filter[]): Filter; not(filter: Filter): Filter; } export declare function defineCollection(config: CollectionConfig): CollectionConfig; //# sourceMappingURL=public-api.d.ts.map