Repository navigation
fix: return none when only common terms match below the cosine floor - #64
Merged
Merged
Conversation
Search treated any in-window term, including words that are common in a large corpus, as at least weak. That made none unreachable. A match with no rare term now follows the weak cosine floor. context grounding explain prints those features and, for a labeled file, the cuts that separate on-topic from off-topic. Threshold defaults are unchanged. Co-authored-by: Nick Kosarev <nick@kosarev.space>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After #63, a large corpus still returned
weakfor every query. Any in-window term counted, including words that are common across the collection, andstrongstill needs a passage cosine of 0.92. Real passages do not reach that, andnonenever appeared. This does not change those default thresholds. It makesnonereachable, and adds a local command that prints the features so they can be calibrated on the production database without publishing the text.searchand pack grounding now returnnonewhen no passage matches a rare (non-common) query term and the best cosine is belowCONTEXT_GROUNDING_COSINE_WEAK(default 0.84). A common-only match at or above that floor staysweak, including a cosine of 0.99. A neighbour that matches no query term can still bestrongat 0.92. Rare-termstrongis unchanged: uncommon share 0.5 with embeddings (and cosine 0.92 on that same passage) or 0.75 with no embeddings.context grounding explainruns that same search. It is not an MCP tool.context grounding explain --query "..." [--area personal] [--project id] [--json] context grounding explain --file questions.yaml [--area personal] [--json]The file is a list of
{query, project?, expect: on|off}. Each query prints the label, best passage cosine, rare-term share, matched rare terms, common terms dropped, corpus size and document frequency, the threshold inputs, and the top hit id and title. A file also prints, for cosine and rare-term share, the on/off distribution and the single cuts plus a combined and/or rule that separate the two classes, with on/off accuracy. It does not write the thresholds back.Not deployed. The next step is to run
grounding explainagainst the production database and decide whether any threshold should change. Merging this does not by itself retunestrong.Evidence
pnpm run check: format and lint clean, typecheck clean, 266 tests passed.pnpm run eval:grounding(model files were not in this checkout, so semantic reported unavailable):The mixed off-topic count moved from the #63 result (none 1, weak 9) because common-only matches with no cosine are now
none. On-topic stayed not-none.pnpm run eval:projects:context recall 1 pack-hit 1; expi recall 1 pack-hit 1.pnpm run eval:retrieval: completed, isolation violations 0. Lexical hit@1 / hit@k / MRR 0.75 on the context-package questions (the two paraphrase cases remain misses) and hit@k 1 on the project questions.Friction
src/grounding.tswas the pre-fix: keep search grounding honest on a large mixed corpus #63 term-overlap rule. This VM's checkout was behindorigin/main(bddbfb4, merged minutes before the task). Re-reading the wrong algorithm cost a few minutes of design, not a long wait. Install,pnpm run check(about 25s), and the three evals (about 7s, lexical only) were ordinary.PATHhas to prefer~/.nvm/versions/node/v24.22.1/binbecause/exec-daemon/nodev22 stays ahead of nvm. The explain test shells out todist/scripts/context.js, so it only sees the command aftertsc, which is the existing CLI test pattern.package.jsonrequires Node 24.22.1; the process onPATHat start is Node 22 at/exec-daemon/node.pnpm run eval:groundingcannot score cosine here: neithermodels/nor.output/models/containsXenova/multilingual-e5-small, and the script correctly says semantic is unavailable instead of failing.main, and put Node 24.22.1 ahead of/exec-daemon/nodeon the defaultPATH. That removes the stale-code reread and the nvm setup from this same task. Keep the model out of the defaultmodels/directory sopnpm testdoes not load it; pointeval:groundingat a cached.output/modelswhen a semantic run is part of the gate.