import { type EmbeddingProvider, type VectorDocument, type VectorSearchOptions, type VectorSearchResult, type VectorStore } from '../hallucination/retrieval.js'; import type { MigrationResult, SchemaMigration } from '../utils/schema-migrations.js'; import { type SqliteDatabaseLike, type SqliteLikeClient } from './client.js'; import type { SqliteMigrateOptions } from './migrations.js'; /** Options for the SQLite vector store. */ export interface SqliteVectorStoreOptions { /** Width of every vector. Must match the embedding function's output. */ dimensions: number; /** The table chunks are kept in. Defaults to `nexus_vectors`. */ table?: string; /** * How similarity is computed. `sqlite-vec` ranks inside SQLite with the extension's * `vec_distance_cosine()`, so only the best rows leave the database; load the extension into the * handle first. `scan` needs no extension and ranks in JavaScript, reading every row that passes the * filter. Defaults to `scan`. */ search?: 'sqlite-vec' | 'scan'; /** Embeds chunks that arrive without a vector, and search queries. Defaults to hashed term vectors. */ embed?: EmbeddingProvider; } /** The statement that creates the vector table, for a migration tool that runs SQL itself. */ export declare function sqliteVectorStoreMigration(options?: { table?: string; }): string; /** The versioned schema, which `migrate()` applies. Version 1 is the 2.0 table. */ export declare function sqliteVectorStoreMigrations(options?: { table?: string; }): SchemaMigration[]; /** * Retrieval chunks in SQLite: one file, no server, the same contract as every other store. * * Vectors are stored as float32 blobs, the format sqlite-vec reads. Filters run in SQL against the * metadata JSON, matching type as well as value, as the memory store does. Search is exact in both * modes, which suits a single node's corpus; beyond a few hundred thousand chunks, use pgvector or a * dedicated vector database. */ export declare class SqliteVectorStore implements VectorStore { private readonly options; private readonly client; private readonly table; private readonly embed; constructor(database: SqliteLikeClient | SqliteDatabaseLike, options: SqliteVectorStoreOptions); /** * Applies this store's pending migrations, recorded in `nexus_schema_migrations`, each inside * `BEGIN IMMEDIATE`. Never runs implicitly. Safe on a file an older release created. */ migrate(options?: SqliteMigrateOptions): Promise; /** Adds chunks, or replaces those whose id exists, embedding those without a vector in one batch. */ add(documents: VectorDocument[]): Promise; /** The chunks most similar to a query, best first. */ search(query: string, options?: VectorSearchOptions): Promise; /** The chunks most similar to a vector, best first. */ searchVector(vector: number[], options?: VectorSearchOptions): Promise; /** Removes chunks by id. */ delete(ids: readonly string[]): Promise; }