Repository navigation
fix: ground on a cosine margin and the matched document pool - #65
Merged
Merged
Conversation
Project search counted document frequency on sources only, so a term that matched a journal or distilled item showed df 0. Project ids, names, and glossary terms are no longer common. With embeddings, strong and weak use the margin over a cached area or project centroid instead of an absolute cosine. Lexical-only grounding is 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.
Project-scoped grounding counted document frequency on sources only, and absolute E5 cosines overlap. This uses the same pool search matches, keeps project identity terms rare, and scores embeddings by the margin over a cached centroid.
Document frequency
documentFrequencynow counts the records that search can return. A project pool is that project's current sources plus its journals, decisions, facts, and other knowledge. An area pool leaves journals, decisions, and facts out. A document filter still counts only current documents. A term that occurs only in a distilled item is no longerdf0. The project's id, name, and glossary terms are never common. Synonyms are not protected.Margin
With embeddings,
strong/weak/noneuses the evidence cosine minus the cosine of the query to a cached centroid of the passage vectors in that area, or in that project. The centroid is recomputed when the chunk count or max rowid changes.explainprintsbackgroundandmargin.explain --filealready accepted a per-questionproject; the summary now adds margin distributions, a margin cut, and a combined rare-share and margin rule. Lexical-only grounding is unchanged.Defaults, from the public fixture with
Xenova/multilingual-e5-small(not from the 2374-source set):CONTEXT_GROUNDING_MARGIN_WEAK=0.03CONTEXT_GROUNDING_MARGIN_STRONG=0.08Curated on-topic margin was 0.014–0.081 (median 0.032) and off-topic margin was about -0.81 to -0.75, because those neighbours stayed under the 0.80 retrieval floor. On the mixed corpus, off-topic cosine reached 0.928 while off-topic margin reached only 0.109 (median 0.069). Calibrate both variables with
context grounding explain --fileon the database you search. Not deployed.Evidence
pnpm run check: lint, typecheck, 269 tests passedpnpm run eval:grounding: curated lexical 10/10 and 10/10 none; curated semantic 10/10 and 10/10 none; mixed lexical 10/10 and 10/10 not-strong (none 9, weak 1, strong 0); mixed semantic 10/10 and 10/10 not-strong (none 2, weak 8, strong 0)pnpm run eval:projects: context recall 1 pack-hit 1; expi recall 1 pack-hit 1pnpm run eval:retrieval: completed, lexical only (semantic: unavailablebecause that fixture database has no vectors). Isolation violations 0Friction
bddbfb4vsde464de) was a fetch, not a rebuild. The first semantic grounding pass reported one mixed on-topic cosine of 0 (margin -0.801); the rerun of the same command put every on-topic cosine at 0.853–0.906 (margin min 0.067). That miss did not reproduce, so the cause is unknown.nodeis/exec-daemon/nodev22 untilPATHputs nvm 24.22.1 first.scripts/download-search-model.tsimports../src/embedding-model.js, so it cannot run untiltsc. The pinned files were fetched with curl instead. The ONNX file is 118,308,185 bytes, matching the documented q8 build.eval:retrievalprintssemantic: unavailablewhenmodels/Xenova/multilingual-e5-smallis on disk, becausesrc/eval-search.tsloads the model only if the eval database already has vectors and it never reindexes.scripts/download-search-model.tshas nopnpmscript and fails on the TypeScript source.pnpmdownload script that works beforetsc, plus an eval:retrieval line that says "fixture database has no vectors" when the model is present, would remove the two detours. Putting Node 24.22.1 onPATHin the environment would remove the third.