Skip to content

feat: v0.4 search improvements — ranking, round-trip reduction, token efficiency, infrastructure#9

Merged
jahala merged 12 commits into
mainfrom
feat/v0.4-search-improvements
Feb 17, 2026
Merged

feat: v0.4 search improvements — ranking, round-trip reduction, token efficiency, infrastructure#9
jahala merged 12 commits into
mainfrom
feat/v0.4-search-improvements

Conversation

@jahala

@jahala jahala commented Feb 15, 2026

Copy link
Copy Markdown
Owner

Summary

Major search quality and efficiency improvements across 4 tiers, plus instruction tuning for near-total tool adoption.

  • Tier 1 — Search ranking: Semantic def_weight scoring by AST node kind, basename_boost for file-stem matching, impl/interface collector for auto-surfacing trait implementations
  • Tier 2 — Round-trip reduction: Sibling surfacing (── siblings ── footer), transitive callee expansion (2-hop BFS with cycle detection), faceted result grouping (definitions/implementations/tests/usages)
  • Tier 3 — Token efficiency: Cognitive load stripping (remove debug logs, collapse blanks, filter comments preserving TODO/FIXME/doc), smart truncation (compress >80-line functions to ~40 most diverse lines)
  • Tier 4 — Infrastructure: Materialized symbol index (DashMap + rayon parallel build), bloom filter cache (per-file probabilistic membership with mtime invalidation), pipeline wiring into search/callees/callers
  • v0.4.1 — Instruction tuning: Tool descriptions say "Replaces X and the host Y tool", SERVER_INSTRUCTIONS explicitly name host tools (Read, Grep, Glob) to replace

Benchmark results (Sonnet 4.5, 52 runs)

Baseline tilth Change
$/correct $0.26 $0.19 -29%
Accuracy 96% (25/26) 92% (24/26) -4pp
Avg cost $0.25 $0.17 -32%
Context tokens 225,570 163,521 -28%
Tool adoption 98%

W19 T3 L4 — tilth wins 19 of 26 tasks on cost.

Multi-model: Opus 5/5 hard tasks (100% adoption), Haiku 18/26 (42% adoption).

Review fixes

  • Deduplicated package_root() across rank.rs and facets.rs into shared mod.rs function
  • Hoisted detect_file_type above both uses in format_matches()
  • Removed premature index.build() call (index not yet used for search fast-path)

Stats

  • 18 files changed, +2,701 / -69 lines (Rust)
  • 11 files changed, +404 / -203 lines (benchmark + docs)
  • 55 unit tests + 1 doc-test, all passing
  • cargo clippy clean, cargo fmt clean

Test plan

  • cargo build && cargo clippy -- -D warnings && cargo test — all clean
  • cargo build --release — optimized build succeeds
  • Benchmark: Sonnet 52 runs — 29% cost reduction, 98% tilth adoption
  • Benchmark: Opus 5 hard tasks — 5/5 correct, 100% adoption
  • Benchmark: Haiku 26 runs — 69% accuracy, 42% adoption
  • Verify callee/sibling footers appear on expanded definitions
  • Verify faceting kicks in on >5 matches

🤖 Generated with Claude Code

jahala and others added 12 commits February 15, 2026 14:45
Three changes that directly address 13/13 benchmark failures (all search misses):

- def_weight: semantic scoring per AST node kind (100 for fn/struct/trait,
  90 for impl, 80 for const, 30 for export) replaces flat +1000 bonus
- basename_boost: file stem matching (exact +300, prefix +150, substr +100)
  so Walk→walk.rs ranks first
- impl collector: piggybacks on definition walker to detect trait impls
  and interface implementations, surfaced with [impl] label

Also: split early quit thresholds (50 defs / 30 usages), trait_item
in outline collection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…eted results

Three features that reduce search round-trips:

- Siblings: expanded methods show `── siblings ──` footer with
  referenced fields/methods from the same struct/class (tree-sitter
  queries for Rust/Python/TS/JS/Go/Java, cap at 6)
- Transitive callees: `── calls ──` footer now shows 2-hop callees
  with tree indentation (→ prefix), BFS with cycle detection,
  budget=15 for 2nd hop
- Faceted results: >5 matches grouped into Definitions,
  Implementations, Tests, Usages (same/other package)

Also: Clone derive on Match for faceting, removed dead code from
FacetedResult.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…annel noise

Three optimizations reducing token output per expanded match:

- strip.rs: cognitive load stripping — removes debug logging, plain
  comments (preserving TODO/FIXME/doc), collapses consecutive blanks.
  Per-language rules for Rust/Python/Go/JS/TS/Java/C.
- truncate.rs: smart truncation — functions >80 lines compressed to
  ~40 most diverse lines (control flow, calls, error handling scored
  highest). Gap markers show omitted line count.
- Channel noise: skip outline context for <50-line files, skip leading
  import blocks in expanded defs, collapse blank line runs.

35 unit tests covering all three modules.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…iring

Symbol index (src/index/symbol.rs):
- DashMap<Arc<str>, Vec<SymbolLocation>> for O(1) symbol→file lookup
- Lazy build on first search via rayon parallel walker
- Per-file mtime tracking for incremental invalidation
- Reuses existing tree-sitter definition extraction

Bloom filters (src/index/bloom.rs):
- Per-file probabilistic set membership (1% FPR, ~120 bytes/filter)
- Byte-level identifier extraction (no tree-sitter needed)
- DashMap cache with mtime invalidation
- Pre-filters callee/caller resolution: skip files that
  definitely don't contain target symbol

Wiring (mcp.rs, search/mod.rs, callees.rs, callers.rs):
- Index + bloom threaded through MCP server → search → callee/caller
- Bloom pre-filter in resolve_callees and find_callers

55 unit tests + 1 doc-test, all passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…move premature index build

- Extract shared package_root() to search/mod.rs, rank.rs and facets.rs delegate
- Hoist detect_file_type() above both truncation and callee sections in format_matches
- Remove index.build() from search path — index not yet used for lookup

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
MCP instruction changes:
- Tool descriptions: "Replaces X and the host Y tool — use this for all Z"
- SERVER_INSTRUCTIONS: explicitly name host tools (Read, Grep, Glob) to replace
- EDIT_MODE_INSTRUCTIONS: consistent host tool naming

Benchmark infrastructure:
- Strip backticks in ground truth checking (markdown formatting)
- Relax rg_trait_implementors ground truth (word order)
- Add parse.py for result analysis, improve run.py verbosity

Results (Sonnet 4.5, 52 runs):
- $/correct: $0.26 baseline → $0.19 tilth (-29%)
- Accuracy: 96% baseline, 92% tilth
- Tool adoption: 98% (185/188 calls used tilth)
- W19 T3 L4

Multi-model:
- Opus 4.6: 5/5 hard tasks, 100% adoption, $0.23/correct
- Haiku 4.5: 18/26 (69%), 42% adoption, $0.19/correct

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Haiku (52 runs): +12pp accuracy (58% → 69%) but +12% $/correct
Opus (10 runs): -22% $/correct, 100% accuracy both modes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Average across 114 runs (3 models): -18% $/correct, 79% → 82% accuracy.
9/26 Haiku tilth runs used zero tilth tools — flagged in README.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verified against raw JSONL result files. Percentages (98%, 42%) unchanged.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jahala jahala merged commit 2a1601b into main Feb 17, 2026
1 check 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.

1 participant