Repository navigation
0.46.2
What changed
Knowledge search breaks a score tie by chunk id in every dense and lexical leg, so equal-scored passages come back in the same order whichever plan Postgres picks.
apps/web/src/api/services/ai/retrieval.ts: the tenant, platform and shared dense legs order by<=>thenasc(chunks.id); the lexical leg byts_rank_cd DESCthenasc(chunks.id). The HNSW index is still used (an incremental sort over it).apps/web/tests/api/ingest-retrieval.test.ts: two passages tied in both legs, the later-stored one with the smaller id, rank in chunk-id order.docs/CONCEPTS.md§9 andapps/web/src/api/services/ai/CLAUDE.mdsay so.
How to apply
- In
apps/web/src/api/services/ai/retrieval.ts, addascto thedrizzle-ormimport and appendasc(chunks.id)to the.orderBy(...)of every dense query and of the lexical query. - Take the new
itinapps/web/tests/api/ingest-retrieval.test.tsas it is. - Take the one-sentence hunks in
docs/CONCEPTS.mdandapps/web/src/api/services/ai/CLAUDE.md.
Conflicts to expect
apps/web/src/api/services/ai/retrieval.ts→ a copy that changed a leg'sorderBy→ keep the copy's ordering and appendasc(chunks.id)as its last key.
Verify
pnpm test api apps/web/tests/api/ingest-retrieval.test.ts apps/web/tests/api/knowledge-rerank.test.tspasses.