Skip to content

Promote beta → main: keyword RAG ranks before it truncates - #524

Merged
pushkarverma3698 merged 3 commits into
mainfrom
beta
Aug 20, 2026
Merged

Promote beta → main: keyword RAG ranks before it truncates#524
pushkarverma3698 merged 3 commits into
mainfrom
beta

Conversation

@pushkarverma3698

Copy link
Copy Markdown
Owner

One change on top of main: #523.

Fixes the 0.0% keyword-only recall that #515 measured. keywordSearchRagTable applied LIMIT 20 to an unordered OR-match, so rankByTerms ranked an arbitrary sample of up to 256 matching chunks.

Measured on the live prod corpus (golden case adr-langgraph, 7 terms, 256 of 478 chunks match):

candidates target-doc chunks in pool term overlap
before 20 0 1–2 of 7
after 20 3 2–6 of 7

Read-path only — no migration, no schema change.

Evidence

Not verified

pnpm eval:retrieval recall@5/MRR has not been re-run — it needs a local corpus + Ollama and this machine has no local Postgres up. Whether RRF fusion is still negative-value (hybrid MRR 0.674 vs vector-only 0.761) is therefore still open.

pushkarverma3698 and others added 3 commits August 20, 2026 12:09
keywordSearchRagTable ORed the per-term ILIKE patterns and then applied
LIMIT 20 with no ORDER BY, so Postgres could return any 20 of the matching
rows. rankByTerms then ranked that arbitrary sample precisely. The comment
claimed "over-fetch, then rank precisely" and did neither.

Measured on the prod corpus for golden case adr-langgraph (7 terms, 256 of
478 chunks match at least one):

  before  20 candidates, 0 chunks of the target doc, overlap 1-2 of 7
  after   20 candidates, 3 chunks of the target doc, overlap 2-6 of 7

The target was never in the candidate pool, which is why keyword-only
recall@5 measured 0.0% on 37/37 golden queries with no error and no empty
result to make it visible.

Fix: build the SQL mirror of scoreByTerms (one CASE arm per term, summed),
ORDER BY match_count DESC, content — the second key keeps ties deterministic
per rule #16 — then LIMIT. rankByTerms still refines the top candidates.

Gate: 298 files / 3198 tests green; all six architecture gates at baseline.
fix(rag): rank keyword candidates in SQL before the LIMIT truncates them
@pushkarverma3698
pushkarverma3698 merged commit 6aad1d4 into main Aug 20, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant