Skip to content

fix: return none when only common terms match below the cosine floor - #64

Merged
hmbanan666 merged 1 commit into
mainfrom
cursor/grounding-explain-bdd0
Nov 15, 2026
Merged

hmbanan666 merged 1 commit into
mainfrom
cursor/grounding-explain-bdd0

Conversation

@hmbanan666

Copy link
Copy Markdown
Owner

After #63, a large corpus still returned weak for every query. Any in-window term counted, including words that are common across the collection, and strong still needs a passage cosine of 0.92. Real passages do not reach that, and none never appeared. This does not change those default thresholds. It makes none reachable, and adds a local command that prints the features so they can be calibrated on the production database without publishing the text.

search and pack grounding now return none when no passage matches a rare (non-common) query term and the best cosine is below CONTEXT_GROUNDING_COSINE_WEAK (default 0.84). A common-only match at or above that floor stays weak, including a cosine of 0.99. A neighbour that matches no query term can still be strong at 0.92. Rare-term strong is unchanged: uncommon share 0.5 with embeddings (and cosine 0.92 on that same passage) or 0.75 with no embeddings.

context grounding explain runs 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 explain against the production database and decide whether any threshold should change. Merging this does not by itself retune strong.

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):

Corpus Lexical
Curated on-topic 10/10 not-none with the right source, off-topic 10/10 none
Mixed (336 distractors) on-topic 10/10, off-topic 10/10 not-strong (none 9, weak 1, strong 0)

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

  1. The first read of src/grounding.ts was the pre-fix: keep search grounding honest on a large mixed corpus #63 term-overlap rule. This VM's checkout was behind origin/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.
  2. PATH has to prefer ~/.nvm/versions/node/v24.22.1/bin because /exec-daemon/node v22 stays ahead of nvm. The explain test shells out to dist/scripts/context.js, so it only sees the command after tsc, which is the existing CLI test pattern.
  3. package.json requires Node 24.22.1; the process on PATH at start is Node 22 at /exec-daemon/node. pnpm run eval:grounding cannot score cosine here: neither models/ nor .output/models/ contains Xenova/multilingual-e5-small, and the script correctly says semantic is unavailable instead of failing.
  4. Snapshot the agent image from current main, and put Node 24.22.1 ahead of /exec-daemon/node on the default PATH. That removes the stale-code reread and the nvm setup from this same task. Keep the model out of the default models/ directory so pnpm test does not load it; point eval:grounding at a cached .output/models when a semantic run is part of the gate.
Open in Web Open in Cursor 

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>
@hmbanan666
hmbanan666 merged commit de464de into main Nov 15, 2026
2 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.

2 participants