Skip to content

feat: short-chunk coalescing, rerank truncation, query vector cache - #5

Merged
Verdenroz merged 9 commits into
mainfrom
feat/chunk-coalesce-rerank-cache
Sep 5, 2026
Merged

Verdenroz merged 9 commits into
mainfrom
feat/chunk-coalesce-rerank-cache

Conversation

@Verdenroz

@Verdenroz Verdenroz commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Description

A fifth of finance-query's 16k chunks were one or two lines. The gap between two definitions, a doc comment, a #[cfg] line, a pub mod x;, got windowed into its own chunk and embedded on little more than its path header, and those chunks were the top sources for -a questions, which the answer route never reranked anyway. Leading comments and attributes now belong to their definition, spans under four lines merge into a neighbour, @generated files are skipped, and answers go through the same rerank as search. The reranker also reads at most 3000 chars per document, which measured better than full length and not merely faster, and the server keeps the last 256 query vectors so a repeated query skips HyDE and embedding.

Changes

  • Extended each tree-sitter definition upward over adjacent comment, attribute, and decorator siblings.
  • Added chunker/coalesce.rs: spans shorter than four lines merge forward into the next span, or back into the previous one at the end of a file. Sibling symbols merge under their common parent path.
  • Skipped files carrying @generated in their first five lines.
  • Added scry index --full, which re-uploads every file regardless of the manifest. A chunker change does not reach existing files otherwise.
  • Routed the answer route's sources through the reranker with the same pool and budget as search, raised the per-source snippet to 1600 chars, and added rerank to AnswerRequest. The prompt asks the model to say what is missing instead of guessing.
  • Added max_chars to [rerank] (default 3000); RerankClient::document cuts each embedding input there on a char boundary.
  • Added scry-server/src/query_cache.rs, a 256-entry FIFO of query vectors used by the search and answer routes.
  • Changed changelog.yml to open an auto-merging PR from bot/changelog-update instead of committing to main, minting its token from the same GitHub App soothfast and finance-query use (CHANGELOG_APP_CLIENT_ID variable, CHANGELOG_APP_PRIVATE_KEY secret).
  • Documented chunking, truncation, and the cache in docs/search.md and the re-chunk requirement in CLAUDE.md.
  • Bumped the workspace version to 0.2.0.

Testing

  • cargo test --workspace: 57 core unit tests plus the integration suites pass; cargo clippy --workspace --all-targets -- -D warnings clean. New tests cover trivia attachment, detached comments, one-line mod runs, coalescing rules, @generated skipping, rerank document truncation, and cache eviction.
  • finance-query chunk count after scry index --full: 16,331 to 10,438; chunks of one or two lines 3,267 to 33.
  • scry eval eval/finance-query.toml, 60 cases, HyDE on, bge-reranker-v2-m3 top 20, each configuration run alone on the iGPU: start of branch 0.717 recall@10 / 0.577 MRR / p50 1804ms; chunker only 0.817 / 0.570 / 3232ms; with 3000-char truncation 0.833 / 0.572 / 2336ms, reproduced twice; second run with the cache warm 0.833 / 0.572 / 1459ms.
  • Truncation sweep on the same setup: 1200 chars 0.783 / 0.575 / 1990ms, 2000 chars 0.817 / 0.567 / 2149ms, full length 0.817 / 0.570 / 3232ms.
  • Rejected on the same eval and not included: a shorter HyDE prompt (0.817), HyDE on qwen3.5:0.8b (0.767), and jina-reranker-v1-tiny-en (0.767, below no rerank at 0.783).
  • The changelog workflow change is untested until it runs on main; it needs the App installed on this repo, the CHANGELOG_APP_PRIVATE_KEY secret, and auto-merge enabled in the repo settings.
  • cargo soothfast gate -p scry-core --against-ref origin/main --filter chunk: bench_chunk_rust instructions +1.7% after replacing the per-definition prev_named_sibling walk, which had pushed it to +9.6%.

@Verdenroz
Verdenroz force-pushed the feat/chunk-coalesce-rerank-cache branch from 3c0ab28 to 63e2fa2 Compare September 5, 2026 21:24
- Gap lines between definitions (doc comments, attributes, one-line
  mod declarations) embedded on their own and ranked on their path
  header alone; a fifth of finance-query's chunks were one or two lines.
- recall@10 on eval/finance-query.toml goes from 0.717 to 0.817.
- Files are only re-chunked when their content hash changes, so a
  chunker change never reaches an existing index without this.
- The answer route took the fused top eight while search reranked a
  pool of twenty, so answers saw worse sources than search showed.
- The prompt now asks for what is missing rather than a guess.
- On eval/finance-query.toml with BGE v2-m3: 1200 chars 0.783 recall,
  2000 0.817, 3000 0.833 at p50 2.3s, full length 0.817 at p50 3.2s.
- A repeated natural-language query skips HyDE and embedding: 3.6s to
  2.1s with the reranker, 0.69s to 0.04s without.
@Verdenroz
Verdenroz force-pushed the feat/chunk-coalesce-rerank-cache branch from 63e2fa2 to 5262100 Compare September 5, 2026 21:29
- main only accepts pull requests now, so the workflow opens one and
  lets auto-merge land it once the required checks pass.
- The token is minted from the same GitHub App soothfast and
  finance-query use; a PR made with the workflow token triggers no CI.
@Verdenroz
Verdenroz force-pushed the feat/chunk-coalesce-rerank-cache branch from 5262100 to ceb8801 Compare September 5, 2026 21:47
@Verdenroz
Verdenroz merged commit 497183f into main Sep 5, 2026
2 checks passed
@Verdenroz
Verdenroz deleted the feat/chunk-coalesce-rerank-cache branch September 5, 2026 22:02
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