/** * SQLite database abstraction for the search index. * * Uses `node:sqlite` (built-in Node 22+). Feature-gated — callers must check * availability via `isSqliteAvailable()` before constructing a SearchDatabase. */ import type { ChunkKind, FileType, IndexedFile, StoredChunk } from "./types.js"; /** Check whether `node:sqlite` is available in this Node.js runtime. */ export declare function isSqliteAvailable(): boolean; /** Wrapper around `node:sqlite` DatabaseSync for the search index. */ export declare class SearchDatabase { private db; constructor(dbPath: string); /** Create or migrate the database schema. */ private initSchema; /** Insert or update a file record. Returns the file ID. */ upsertFile(filePath: string, mtime: number, fileType: FileType): number; /** Get a file by path. */ getFile(filePath: string): IndexedFile | null; /** Get all indexed files. */ getAllFiles(): IndexedFile[]; /** Delete a file and all its chunks/embeddings/symbols (cascading). */ deleteFile(fileId: number): void; /** Insert a chunk. Returns the chunk ID. */ insertChunk(fileId: number, filePath: string, startLine: number, endLine: number, kind: ChunkKind, name: string | null, content: string, fileType: FileType): number; /** Delete all chunks for a file. */ deleteChunksForFile(fileId: number): void; /** Get all chunks. */ getAllChunks(): StoredChunk[]; /** Get chunks by file ID. */ getChunksByFileId(fileId: number): StoredChunk[]; /** Get a chunk by ID. */ getChunk(chunkId: number): StoredChunk | null; /** Get multiple chunks by IDs. Batches queries to avoid exceeding SQLite's bind variable limit. */ getChunksById(chunkIds: number[]): StoredChunk[]; private rowToChunk; /** Store an embedding vector for a chunk. */ upsertEmbedding(chunkId: number, modelName: string, vector: Float32Array): void; /** Batch insert embeddings. Uses a transaction for performance. */ batchUpsertEmbeddings(items: Array<{ chunkId: number; modelName: string; vector: Float32Array; }>): void; /** Get the embedding for a chunk. */ getEmbedding(chunkId: number, modelName: string): Float32Array | null; /** Get all embeddings for a model. Returns map of chunkId → vector. */ getAllEmbeddings(modelName: string): Map; /** Get chunk IDs that have no embedding for a given model. */ getChunkIdsWithoutEmbedding(modelName: string): number[]; /** Rebuild the FTS5 index (use after bulk operations). */ rebuildFts(): void; /** * Search via FTS5 with BM25 ranking. * Returns chunk IDs with their BM25 scores (negated so higher = better). */ ftsSearch(query: string, limit: number): Array<{ chunkId: number; score: number; }>; /** Record an import edge. */ insertImport(sourceFileId: number, targetFilePath: string): void; /** Delete all imports for a source file. */ deleteImportsForFile(sourceFileId: number): void; /** Get files imported by a given source file. */ getImportsFrom(sourceFileId: number): string[]; /** Get file IDs that import a given target path. */ getImportersOf(targetFilePath: string): number[]; /** Get all import edges. */ getAllImports(): Array<{ sourceFileId: number; targetFilePath: string; }>; /** Insert a symbol. */ insertSymbol(chunkId: number, name: string, kind: string): void; /** Delete symbols for a chunk. */ deleteSymbolsForChunk(chunkId: number): void; /** Get all symbols. Returns map of chunkId → symbol names. */ getAllSymbols(): Map; /** Run a function inside a transaction. */ transaction(fn: () => T): T; /** Get the total number of chunks. */ getChunkCount(): number; /** Get the total number of files. */ getFileCount(): number; /** Close the database connection. */ close(): void; } //# sourceMappingURL=db.d.ts.map