Skip to content

Add fuzzy key match, pattern mining (P#) and IDF ranking to document … - #30

Merged
hungpham10 merged 4 commits into
mainfrom
feature/fuzzy-structure-matching
Sep 12, 2026
Merged

hungpham10 merged 4 commits into
mainfrom
feature/fuzzy-structure-matching

Conversation

@hungpham10

Copy link
Copy Markdown
Owner

…graph

Phase 3 of the structured document graph: fuzzy retrieval, cross-document pattern mining and rarity-based ranking (rare structure = high information, IDF-style scoring).

  • Fuzzy key match: search_key_fuzzy scores distinct keys by exact/prefix/ contains/Levenshtein similarity with an IDF bonus (rarer keys score higher). doc_search accepts ~segment to force fuzzy and falls back exact-substring -> fuzzy when the full-path trie misses.
  • Pattern mining: mine_patterns() counts kind chains (wildcard FIELD/IDX payloads) ending at scalar leaves over a max_depth window, assigns stable pattern ids (P#, registry persisted in storage and restored on open) and indexes chains into the previously dead pattern_trie. Results carry node_count / doc_count / doc_freq, sorted by document frequency ascending so characteristic patterns surface first and background (~1.0) sinks.
  • Structural search: search_kind_chain() matches nodes whose ancestor kind window ends with the query chain (e.g. "MAP, FIELD, NUMBER"); results are ranked by pattern uniqueness IDF. search_path_scan() complements the radix trie whose leaf holds a single record per chain, returning all nodes with the same key path across documents (spec.replicas: 97 hits on the infra repo instead of 1).
  • Depth semantics fixed in doc_search: depth counts extra levels BELOW the pattern, so the radix key-length filter gets pattern_len + depth.
  • New MCP tools: doc_mine_patterns, doc_list_patterns, doc_search_struct. New CLI commands: codegraph doc patterns, codegraph doc struct.

…graph

Phase 3 of the structured document graph: fuzzy retrieval, cross-document
pattern mining and rarity-based ranking (rare structure = high information,
IDF-style scoring).

- Fuzzy key match: search_key_fuzzy scores distinct keys by exact/prefix/
  contains/Levenshtein similarity with an IDF bonus (rarer keys score
  higher). `doc_search` accepts `~segment` to force fuzzy and falls back
  exact-substring -> fuzzy when the full-path trie misses.
- Pattern mining: mine_patterns() counts kind chains (wildcard FIELD/IDX
  payloads) ending at scalar leaves over a max_depth window, assigns stable
  pattern ids (P#, registry persisted in storage and restored on open) and
  indexes chains into the previously dead pattern_trie. Results carry
  node_count / doc_count / doc_freq, sorted by document frequency ascending
  so characteristic patterns surface first and background (~1.0) sinks.
- Structural search: search_kind_chain() matches nodes whose ancestor kind
  window ends with the query chain (e.g. "MAP, FIELD, NUMBER"); results are
  ranked by pattern uniqueness IDF. search_path_scan() complements the radix
  trie whose leaf holds a single record per chain, returning all nodes with
  the same key path across documents (spec.replicas: 97 hits on the infra
  repo instead of 1).
- Depth semantics fixed in doc_search: depth counts extra levels BELOW the
  pattern, so the radix key-length filter gets pattern_len + depth.
- New MCP tools: doc_mine_patterns, doc_list_patterns, doc_search_struct.
  New CLI commands: `codegraph doc patterns`, `codegraph doc struct`.
@coderabbitai

coderabbitai Bot commented Sep 12, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: b3cab63b-5da1-4d5b-8fd0-028f38f91bed


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codspeed

codspeed Bot commented Sep 12, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 28 untouched benchmarks


Comparing feature/fuzzy-structure-matching (50a6c1f) with main (6a75ca7)

Open in CodSpeed

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.75460% with 295 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.32%. Comparing base (6a75ca7) to head (50a6c1f).

Files with missing lines Patch % Lines
crates/codegraph-mcp/src/tools.rs 0.00% 121 Missing ⚠️
crates/codegraph-docs/src/graph.rs 82.25% 77 Missing ⚠️
crates/codegraph/src/main.rs 0.00% 63 Missing ⚠️
crates/codegraph-mcp/src/lib.rs 0.00% 34 Missing ⚠️

❌ Your patch status has failed because the patch coverage (54.75%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #30      +/-   ##
==========================================
- Coverage   73.84%   73.32%   -0.53%     
==========================================
  Files          87       87              
  Lines       19286    19915     +629     
==========================================
+ Hits        14242    14602     +360     
- Misses       5044     5313     +269     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hungpham10
hungpham10 merged commit 457db80 into main Sep 12, 2026
18 of 19 checks passed
@hungpham10
hungpham10 deleted the feature/fuzzy-structure-matching branch September 12, 2026 14:54
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