import type { DatabaseHandle } from './db.js'; import type { Chunk } from '../embeddings/chunker.js'; /** * Row as stored in the chunks table. Vector lives in chunks_vec keyed by * rowid; callers that need it look it up via joinChunkVector. */ export interface ChunkRow { id: string; nodeId: string; chunkIndex: number; heading: string | null; headingLevel: number | null; content: string; contentHash: string; startLine: number | null; endLine: number | null; rowid: number; } /** * Upsert a single chunk row. Returns the assigned rowid — callers pair it * with upsertChunkVector to keep chunks_vec in sync. */ export declare function upsertChunkRow(db: DatabaseHandle, nodeId: string, chunk: Chunk): number; /** * Write `vector` into chunks_vec at `rowid`, replacing any existing row. */ export declare function upsertChunkVector(db: DatabaseHandle, rowid: number, vector: Float32Array): void; /** * Look up a chunk by composite id (returns undefined if missing). Used by * the indexer to cheap-skip re-embedding when content_hash matches. */ export declare function getChunk(db: DatabaseHandle, id: string): ChunkRow | undefined; /** * IDs of every chunk currently stored for `nodeId`. Used by the indexer to * diff fresh-vs-stale chunks after a note is re-parsed. */ export declare function getChunkIdsForNode(db: DatabaseHandle, nodeId: string): string[]; /** * Delete a set of chunks (and their vectors) by composite id. */ export declare function deleteChunks(db: DatabaseHandle, ids: string[]): void; /** * Delete every chunk for `nodeId`. Called when a note is removed (the * chunks table's ON DELETE CASCADE covers the SQL rows, but chunks_vec is * a separate virtual table without FK cascade — so we vacuum it here). */ export declare function deleteChunksForNode(db: DatabaseHandle, nodeId: string): void; /** * Total number of chunks in the store. Used at startup to decide whether a * chunk-level reindex is needed (new DB, or pre-1.4.0 upgrade). */ export declare function countChunks(db: DatabaseHandle): number; /** * kNN search over chunks_vec, joining chunks for metadata. * * Returns one row per matching chunk. Callers that want one-per-note * dedup should group by nodeId and keep the max-scoring chunk (see * Search.semanticChunks in src/search/unified.ts). */ export interface ChunkSearchHit { chunkId: string; nodeId: string; chunkIndex: number; heading: string | null; headingLevel: number | null; content: string; startLine: number | null; endLine: number | null; score: number; title: string; } export declare function searchChunkVectors(db: DatabaseHandle, vector: Float32Array, limit: number): ChunkSearchHit[];