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 PostgresLikeClient } from './client.js'; import type { PostgresMigrateOptions } from './migrations.js'; /** Options for the pgvector store. */ export interface PostgresVectorStoreOptions { /** Width of every vector. Must match the embedding function's output. */ dimensions: number; /** Embeds chunks that arrive without a vector, and search queries. Defaults to hashed term vectors. */ embed?: EmbeddingProvider; /** Table name, optionally schema-qualified. Defaults to `nexus_vectors`. */ table?: string; /** * The approximate index created by `migrate()`. `hnsw` (the default) answers a search without * scanning every row, at the cost of slower writes; `none` scans exactly, which suits a few * thousand chunks. */ index?: 'hnsw' | 'none'; } /** * The versioned schema, which `migrate()` and `nexus db migrate` apply. Version 1 is the 2.0 schema. */ export declare function vectorStoreMigrations(options: Omit): SchemaMigration[]; /** The schema, as statements: the pgvector extension, the table, and its index. */ export declare function vectorStoreMigration(options: Omit): string[]; /** * Retrieval chunks in Postgres with pgvector, ranked by cosine similarity in the database. * * The same contract as `MemoryVectorStore`, checked by the same tests. Only the nearest chunks leave * the database, so a search costs the same whether the table holds a thousand chunks or ten million. * Adding a chunk whose id exists replaces it, and a metadata filter runs in SQL. */ export declare class PostgresVectorStore implements VectorStore { private readonly client; private readonly options; private readonly table; private readonly embed; constructor(client: PostgresLikeClient, options: PostgresVectorStoreOptions); /** * Applies this store's pending migrations, recorded in `nexus_schema_migrations`, under a lock. * Never runs implicitly. Safe on a database an older release created: what exists is kept. */ migrate(options?: PostgresMigrateOptions): 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; /** Chunks stored. */ size(): Promise; private assertWidth; }