/** A section of the docs, as the vector database keeps it. */ export interface StoredSection { /** Hash of the embeddings model and the section's headings and text. */ id: string; /** Where the section came from: `readme`, `help-docs`, `saved-replies`, `file:`. */ source: string; /** The embeddings model that made the vector, e.g. `openai:text-embedding-3-small`. */ embedder: string; headings: string[]; text: string; /** Unit length, so the dot product of two vectors is their cosine similarity. */ vector: number[]; } /** A section a query found, most alike first. */ export interface SectionMatch { id: string; source: string; headings: string[]; text: string; /** Cosine similarity to the query, -1 to 1. */ score: number; } export interface QueryOptions { /** Only sections embedded by this model: vectors of different models can't be compared. */ embedder: string; /** How many sections to return. */ k: number; /** Sections less alike than this are left out. */ minScore?: number; /** Sources to leave out (the widget doesn't answer from the desk's saved replies). */ exclude?: string[]; } export interface VectorStore { /** Vectors already stored for these ids, in any source: a section is embedded once, wherever it appears. */ get(ids: string[]): Promise>; /** Adds sections, or replaces those with the same source and id. */ upsert(rows: StoredSection[]): Promise; /** Deletes the sections of `source` whose id isn't in `keep` (the docs changed); returns how many went. */ prune(source: string, keep: string[]): Promise; /** Every source the database holds sections of. */ sources(): Promise; /** The `k` stored sections most like `vector`, computed in the database. */ query(vector: number[], options: QueryOptions): Promise; /** Where it keeps them, for messages (a file path, or a description). */ location?: string; } /** The part of a better-sqlite3 or node:sqlite database this uses. */ export interface SqliteDatabase { exec(sql: string): unknown; prepare(sql: string): { run(...params: unknown[]): unknown; all(...params: unknown[]): unknown[]; }; /** Registers a SQL function; both drivers have it. Without it, similarity is computed after reading the rows. */ function?(name: string, options: { deterministic?: boolean; }, fn: (...args: any[]) => unknown): unknown; } /** A vector database in a SQLite database: better-sqlite3's `Database`, or node:sqlite's `DatabaseSync`. */ export declare function sqliteVectorStore(db: SqliteDatabase, options?: { table?: string; }): VectorStore; /** * A vector database in Postgres, through any client's query function: `(text, params) => rows`. * postgres.js: postgresVectorStore((text, params) => sql.unsafe(text, params)) * node-postgres: postgresVectorStore((text, params) => pool.query(text, params).then((r) => r.rows)) * Vectors are a `real[]` column and scored in SQL, so no extension (such as pgvector) is needed. */ export declare function postgresVectorStore(query: (text: string, params: unknown[]) => Promise, options?: { table?: string; }): VectorStore; /** * The default store: a SQLite file through Node's built-in SQLite. `path` defaults to BLAZE_VECTOR_DB, else * `.blazeresolver/vectors.db` at the root of the enclosing git repo (or the working directory), falling back to the * temp directory where that can't be written (read-only serverless filesystems). Undefined when there's no disk or no * built-in SQLite; search then keeps vectors in memory only. */ export declare function localVectorStore(options?: { path?: string; }): VectorStore | undefined; /** * The store handlers use by default: `localVectorStore()`, opened on first use rather than when the handler is created, * so building or importing an app (Next.js evaluates route modules while it builds) never touches the disk. */ export declare function defaultVectorStore(): VectorStore;