/** * Retrieval over a product's help docs: split into sections, ranked against a question. * `retrieve` is keyword ranking (BM25): no API, same result every time. `search` adds semantic ranking when an * embedder is configured, fused with the keyword ranking (reciprocal rank fusion), so "delete my account" also finds * a section that only says "close". Section vectors are computed once and kept in memory; any failure or slowness * in the embeddings provider falls back to keyword ranking alone. */ import type { Embedder } from './embed.js'; import type { VectorStore } from './vector-store.js'; export interface Chunk { /** The headings the chunk sits under, outermost first. */ headings: string[]; text: string; } /** Splits Markdown or plain text into sections of at most ~MAX_CHUNK characters, each tagged with its headings. */ export declare function chunkDocs(docs: string): Chunk[]; export declare function tokenize(text: string): string[]; /** The `k` sections that best match the question by keywords, best first. Sections sharing no term with it are never returned. */ export declare function retrieve(docs: string, question: string, k?: number): Chunk[]; /** Docs from one place: `readme`, `help-docs`, `saved-replies`, `file:docs/guide.md`. */ export interface DocSource { name: string; text: string; } /** A section, with the source it came from. */ export interface SourcedChunk extends Chunk { source: string; } /** Forgets what's kept in memory (vectors, and which sources are in sync), as a restart would. The database keeps its own. */ export declare function clearVectorCache(): void; export interface SyncResult { /** Sections the sources hold. */ sections: number; /** Sections embedded now: new, or changed since they were last embedded. */ embedded: number; /** Sections whose vectors the database already had. */ reused: number; /** Sections the database dropped because the docs no longer have them. */ removed: number; } /** * Puts the sources into the vector database: every section is stored under its source, with a vector reused from the * database or embedded now, and sections a source no longer has are deleted. A source already in sync is skipped, so * this is cheap to call before every query. Throws when the embedder or the store fails. */ export declare function syncSources(sources: DocSource[], options: { embedder: Embedder; store: VectorStore; }): Promise; export interface SearchOptions { /** How many sections to return. Default 4. */ k?: number; /** Adds semantic ranking. Without one, `search` is keyword ranking alone. */ embedder?: Embedder; /** * The vector database: sections are kept in it and retrieved from it by similarity, including sections of sources * this call wasn't given (docs indexed with `blazeresolver index --docs`). Without one, sections are embedded and * ranked in memory. */ store?: VectorStore; /** Sources in the database to leave out of this search. */ exclude?: string[]; /** * How long to wait for embeddings before answering from keywords alone. Default 4s. The docs keep being embedded * in the background, so the next question gets the semantic ranking. */ timeoutMs?: number; /** Cosine similarity below which a section doesn't count as a semantic match. Default 0.25, or BLAZE_EMBED_MIN_SIMILARITY. */ minSimilarity?: number; } /** * The `k` sections that best match the question, best first: keyword and semantic rankings fused (reciprocal rank * fusion), or keywords alone without an embedder or when it fails. With a vector database, the semantic ranking is the * database's nearest neighbours. Empty when nothing matches either way. */ export declare function search(docs: string | DocSource[], question: string, options?: SearchOptions): Promise;