MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / searchSqlite

Function searchSqlite

src/context/sqlite-index.ts:185–201  ·  view source on GitHub ↗
(handle: SqliteIndexHandle, queryEmbedding: number[], topK: number)

Source from the content-addressed store, hash-verified

183 * project ever needs ANN, hnswlib-node can be slotted in behind this same API.)
184 */
185export function searchSqlite(handle: SqliteIndexHandle, queryEmbedding: number[], topK: number): SqliteScored[] {
186 const rows: any[] = handle.db.prepare('SELECT id,file,start_line,end_line,symbol,text,hash,scale,vec FROM chunks').all();
187 const scored: SqliteScored[] = [];
188 for (const r of rows) {
189 const bytes = new Int8Array(r.vec.buffer, r.vec.byteOffset, r.vec.byteLength);
190 const score = cosineQuantized(queryEmbedding, { scale: r.scale, bytes });
191 scored.push({
192 chunk: {
193 file: r.file, startLine: r.start_line, endLine: r.end_line,
194 symbol: r.symbol ?? undefined, text: r.text, hash: r.hash,
195 } as Chunk,
196 score,
197 });
198 }
199 scored.sort((a, b) => b.score - a.score);
200 return scored.slice(0, topK);
201}
202
203/** Read every chunk's text (for BM25 in hybrid mode) without the vectors. */
204export function allChunksFromSqlite(handle: SqliteIndexHandle): Chunk[] {

Callers 1

searchPersistedFunction · 0.85

Calls 2

cosineQuantizedFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected