Skip to content

fix: ground small mixed corpora and warm embeddings after listen - #69

Merged
hmbanan666 merged 1 commit into
mainfrom
fix/small-corpus-grounding-warmup
Nov 17, 2026
Merged

hmbanan666 merged 1 commit into
mainfrom
fix/small-corpus-grounding-warmup

Conversation

@hmbanan666

Copy link
Copy Markdown
Owner

Function words and a title stored outside the body were keeping English questions and title-shaped questions at weak on a corpus below the margin floor. This keeps the public tools as search, remember, read, and timeline.

Done

  • Grounding share. Russian and English function words (как, о, чём, how, what, where, can, you, explain, and a one-letter token such as the s in bot's) are left out of the uncommon-share numerator and denominator. They are not removed from FTS, so retrieval on a large corpus is unchanged.
  • Title. A stored title is scored with the first passage window only. Chunk offsets stay on the body, so a stored vector still lines up.
  • Card floor. On a scoped corpus smaller than CONTEXT_GROUNDING_MARGIN_MIN_CORPUS (default 6), source cards below CONTEXT_SEARCH_CARD_FLOOR (default 0.5, 0 disables) times the best source card are omitted. The compared score is the hybrid rank score plus the number of matched query terms, because reciprocal-rank scores on a few notes sit within a couple of percent of each other. A larger corpus does not use the floor. Knowledge cards are unchanged.
  • Warmup. The server listens first. It then loads the embedding model and embeds one dummy query in the background. Success is {"event":"embeddings_ready"} on stderr, never on stdout. /health reports embeddings as warming, ready, or off.
  • Docs: docs/search.md, docs/curated-instance.md, docs/architecture.md, README settings.

Tests

pnpm run check — lint, typecheck, and 287 tests passed.

node dist/test/evaluate-grounding.js (lexical, no model files present):

  • curated: on-topic 10/10 not-none with the right source, off-topic 10/10 none
  • mixed: on-topic 10/10 not-none with the right source, off-topic 10/10 not-strong (none 10)

New coverage: a 3-note RU/EN fixture. An English paraphrase of the English paragraph is strong and returns only that note. «Как устроена память бота?» and «О чём отвечает AI Бот?» are strong. «Where is the cobalt lantern?» is none with no cards. At 6 notes the same English question stays strong and the one-word neighbours come back, so the floor does not apply to the public eval size.

Skipped

  • No new MCP tools.
  • FTS and questionTerms are unchanged, so function words can still match a row. Only the share math ignores them.
  • The card floor does not apply to knowledge cards.
  • Semantic grounding eval was not run. Model files are not in this checkout (curated semantic: unavailable).
  • Not merged and not deployed. That still needs a separate owner approval.

Friction

  1. What took long. About 20 minutes of reading before a failing fixture existed. questionTerms already drops how/what/как/о, so the first reading of the stop list looked like the bug was already fixed. The remaining misses were words outside that list (чём, can, you, explain, the possessive s) and titles that live in metadata, not in the passage. A pure relative rank floor also does not drop the extra notes: on three hits the reciprocal-rank scores differ by about 2%. Confirming that needed a small script, and Node cannot import these sources directly because they use .js specifiers (Cannot find module .../package-query.js from search-lexical.ts). One tsc was required first. After that, pnpm run check was 28s and the lexical grounding eval was 1.5s. No flake loop and no model download.
  2. Hacks. /health tests that used to deepEqual the whole body now accept embeddings of warming, ready, or off. The warmup task races the first health read, so a single expected state would be flaky. The card floor adds matched term count to the rank score because rank alone cannot see the irrelevant neighbour. That is the comparison the small corpus needs, and it is documented, but it is not the hybrid score by itself.
  3. Misleading spots. src/package-query.ts calls its stop list "small" and it omits чём, where, can, you, and explain, which is exactly the gap. docs/search.md did not say function words still count in the share. src/embedding-index.ts start() already called load() before listen and the comment said that removed the first-query cost; the first inference was still cold, which is the ~1s the website client cannot spend. Health assertions in test/backup-cli.test.ts, test/restart.test.ts, test/processor-status.test.ts, and test/server.test.ts snapshot the entire JSON object, so an added field touches all of them.
  4. Faster next time. Teach context grounding explain to print the terms dropped as function words and whether the title was outside the matched window. That would have shown the cause without a custom script. A Node loader that resolves the repo's .js imports to .ts (or a pnpm exec tsx path that works here) would skip the tsc detour. Health tests should assert status and processor fields, not the whole object.
Open in Web Open in Cursor 

Function words and a title stored off the body were keeping English and
title-shaped questions at weak when the margin is skipped. On that small
corpus, drop source cards far below the best match. After listen, load the
model and embed one dummy query so the first search does not pay startup.

Co-authored-by: Nick Kosarev <nick@kosarev.space>
@hmbanan666
hmbanan666 merged commit 8570737 into main Nov 17, 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