Memory/QMD: prefer exact docid lookup in index

This commit is contained in:
Vignesh Natarajan
2026-02-14 14:56:15 -08:00
parent f9f816d139
commit 6bf333bf31
3 changed files with 77 additions and 3 deletions

View File

@@ -692,9 +692,17 @@ export class QmdMemoryManager implements MemorySearchManager {
const db = this.ensureDb();
let row: { collection: string; path: string } | undefined;
try {
row = db
.prepare("SELECT collection, path FROM documents WHERE hash LIKE ? AND active = 1 LIMIT 1")
.get(`${normalized}%`) as { collection: string; path: string } | undefined;
const exact = db
.prepare("SELECT collection, path FROM documents WHERE hash = ? AND active = 1 LIMIT 1")
.get(normalized) as { collection: string; path: string } | undefined;
row = exact;
if (!row) {
row = db
.prepare(
"SELECT collection, path FROM documents WHERE hash LIKE ? AND active = 1 LIMIT 1",
)
.get(`${normalized}%`) as { collection: string; path: string } | undefined;
}
} catch (err) {
if (this.isSqliteBusyError(err)) {
log.debug(`qmd index is busy while resolving doc path: ${String(err)}`);