/** * Embedding index store — in-memory HNSW-like nearest-neighbor search. * * Stores embedding vectors alongside chunk metadata for semantic retrieval. * Uses brute-force cosine similarity for simplicity and correctness. * For large codebases, a future version can swap in SQLite vss or HNSW. * * Design: all in-memory, rebuilt on startup from indexed chunks. */ import type { CodeChunk } from './chunker'; import type { EmbeddingProvider } from './provider'; export interface IndexedChunk { chunk: CodeChunk; embedding: Float32Array; } export interface SearchResult { chunk: CodeChunk; score: number; } export interface IndexStore { /** Number of indexed chunks. */ readonly size: number; /** Add chunks with their embeddings. */ add(items: IndexedChunk[]): void; /** Remove all chunks for a given file path. */ removeFile(filePath: string): void; /** Search for the top-k most similar chunks to a query embedding. */ search(queryEmbedding: Float32Array, topK?: number): SearchResult[]; /** Clear the entire index. */ clear(): void; /** Get all indexed file paths. */ indexedFiles(): string[]; /** * Optional BM25 keyword search. Stores that do not support keyword search * omit this method; callers must check before invoking. */ keywordSearch?(query: string, topK?: number): SearchResult[]; } /** * Create an in-memory index store. */ export declare function createIndexStore(): IndexStore; export interface IndexingResult { chunksIndexed: number; filesIndexed: number; durationMs: number; } /** * Index a set of code chunks using the given embedding provider. * Processes in batches for efficiency. */ export declare function indexChunks(chunks: CodeChunk[], provider: EmbeddingProvider, store: IndexStore, batchSize?: number): Promise; /** * Search the index with a natural language query. * * Modes: * - `semantic` (default): cosine similarity over dense embeddings. * - `keyword`: BM25 via the store's `keywordSearch` (FTS5). Requires a store * that implements `keywordSearch` (e.g., `createSqliteIndexStore`). * - `hybrid`: fuse semantic + keyword rankings with Reciprocal Rank Fusion. * Falls back to `semantic` if the store has no `keywordSearch`. */ export declare function semanticSearch(query: string, provider: EmbeddingProvider, store: IndexStore, topK?: number, mode?: 'semantic' | 'keyword' | 'hybrid'): Promise; //# sourceMappingURL=index-store.d.ts.map