Skip to content

feat(search): rerank symbol and document search with Jev - #60

Merged
hungpham10 merged 2 commits into
feat/jev-context-rerankfrom
feat/jev-rerank-search
Oct 28, 2026
Merged

hungpham10 merged 2 commits into
feat/jev-context-rerankfrom
feat/jev-rerank-search

Conversation

@hungpham10

Copy link
Copy Markdown
Owner

Tóm tắt

Mở rộng rerank Jev (TypeSafe SystemOne) từ codegraph_context sang symbol search và 3 tool document search. Stacked trên #59.

Thay đổi

codegraph_search_symbol

  • Arg mới rerank = "none" | "jev" (default none).
  • Pool = limit × 4, cap [jev] max_candidates (40) → model có lựa chọn rồi cắt về limit.
  • Mỗi hit có match_score.probability; response có no_match + rerank { used, reason }.
  • Chỉ trang đầu: offset > 0 hoặc có resume → lỗi rõ ràng (rerank phá tính ổn định phân trang). Binary rows giữ nguyên thứ tự.

Document search (graphdoc_search, graphdoc_search_value, graphdoc_search_struct)

  • Cùng arg rerank. Khi bật, response thành { results, no_match, rerank }; khi tắt vẫn là array như cũ (không breaking).
  • Candidate label: kind `key_path` in `doc_path`.
  • Pool rộng hơn limit (search_value lấy thêm limit × 4; struct search rerank trên rows đã sort IDF).

Config [jev]

Key Default Ý nghĩa
doc_include_values false Đưa value của node vào mô tả option. Key một mình không phân biệt được (spec.replicas ở nhiều file); value giúp Jev chọn đúng nhưng tốn token theo số candidate
doc_value_chars 120 Cắt value còn bao nhiêu ký tự

Kiến trúc

  • codegraph_context::rank() + RankOutcome dùng chung cho context / symbol / doc → không lặp logic fail-open.
  • codegraph-api::search_symbol_reranked() giữ phần lọc binary/timing ở tầng API.

Fail-open

Jev tắt, thiếu token, timeout, 4xx, JSON lạ → giữ thứ tự cũ, rerank.used = false + reason. Không tool nào hỏng vì Jev.

Test

  • MCP: rerank_tests.rs — candidate doc (doc_include_values on/off, cắt value), apply_doc_outcome (fail-open / no_match / sort + match_score), dispatch thật qua doc graph (array vs object), guard offset/resume cho symbol search.
  • API: search_symbol_reranked với judge giả (đổi thứ tự, cắt theo limit, total gốc), no_match, fail-open khi jev tắt.
  • Live #[ignore]: thêm case doc-node — chạy thật, Jev chọn đúng node nhờ value (id 2, p=0.81, none=0.05).

Verify

  • cargo fmt --all -- --check ✅
  • cargo clippy --workspace --all-targets -- -D warnings ✅
  • cargo clippy -p codegraph-graph --features postgres,mysql,redis --tests -- -D warnings ✅
  • cargo test --workspace ✅ (4 test storage::redis fail Connection refused — pre-existing, không có redis-server)
  • cargo test -p codegraph-context --test jev_live -- --ignored ✅ (2/2 pass, gọi API thật)

Mở rộng rerank Jev (TypeSafe SystemOne) từ `codegraph_context` sang
`codegraph_search_symbol` và 3 tool document search
(`graphdoc_search`, `graphdoc_search_value`, `graphdoc_search_struct`).

- `codegraph_search_symbol`: arg `rerank = "jev"`, pool = `limit × 4`
  (cap `[jev] max_candidates`), gắn `match_score.probability`, trả
  `no_match`/`rerank`. Chỉ trang đầu — `offset > 0` hoặc `resume` bị từ
  chối vì rerank phá tính ổn định phân trang.
- Doc search: cùng arg `rerank`; response đổi thành object
  `{results, no_match, rerank}` khi bật (mặc định vẫn là array).
  Candidate = `kind \`key\` in \`doc\`` + value tuỳ chọn.
- Config `[jev] doc_include_values` (default false) và `doc_value_chars`
  (default 120): value giúp phân biệt node trùng key ở nhiều file nhưng
  tốn token nên là opt-in.
- Fail-open toàn bộ: Jev lỗi/tắt/timeout → giữ thứ tự cũ + `rerank.used=false`.
- Gộp phần chọn candidate + fail-open vào `codegraph_context::rank()`
  dùng chung cho cả 3 nguồn.

Test: unit cho candidate/apply outcome (MCP), `search_symbol_reranked`
với judge giả (API), live test `#[ignore]` thêm case doc-node-nhờ-value
(đã chạy thật: chọn đúng id 2, p=0.81).
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 548b7067-7250-45e5-b854-b2ba6e808cfe

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@hungpham10
hungpham10 merged commit 8694fe0 into feat/jev-context-rerank Oct 28, 2026
18 checks passed
hungpham10 added a commit that referenced this pull request Oct 28, 2026
* feat(context): rerank candidates with Jev (TypeSafe SystemOne)

`codegraph_context` chỉ biết `Contains` trên tên symbol, nên query tự nhiên
("where do we validate config.toml") trả rỗng hoặc trả symbol không liên quan.

Thêm `rerank = "jev"` (MCP arg + GraphQL field, mặc định off):

- Pool: query gốc + từng token (camelCase/snake_case, bỏ stopword) qua
  `Contains`, lọc kind code và loại test/bench, cap `max_candidates`.
- Một request Jev: Choice (mỗi candidate một option + `none_of_the_above`)
  cộng Noul để chẩn đoán. Trả `probabilities` → xếp hạng, `no_match` khi
  `none` thắng xác suất hạng 1 hoặc hạng 1 dưới `min_probability`.
- Pool < 3 candidate → `no_match` luôn, không gọi API.
- Fail-open: thiếu token, timeout, 4xx, JSON lỗi → giữ thứ tự pool cũ kèm
  `rerank.used = false` + `reason`; không bao giờ làm hỏng context.
- Response: `ContextHit.match_score { probability, confidence }`,
  `ContextResponse.no_match`/`rerank`, markdown in thêm `(p=0.62)`.
- Config `[jev]` opt-in (dữ liệu rời máy): endpoint/model/api_key_env/
  timeout_ms/max_candidates/min_probability/repo. Token chỉ đọc từ env.

Đo với jev-1.13-free: 4 candidate → 1.0s, ~530 input token, cost 0; chọn
đúng `parse_config` (p=0.62, none 0.38). Choice một mình luôn `confidence`
cao kể cả với pool rác (đo được 1.0 với 8 candidate sai), nên `none` +
`min_probability` mới là tín hiệu "không khớp" — không dùng Noul làm cổng
vì Jev trả noul thấp (0.33) ngay cả khi đã chọn đúng.

Test: 18 unit test (pool/tokenize/ngưỡng/fail-open/markdown) + 1 live
`#[ignore]` gọi API thật.

* feat(search): rerank symbol and document search with Jev (#60)

* feat(search): rerank symbol and document search with Jev

Mở rộng rerank Jev (TypeSafe SystemOne) từ `codegraph_context` sang
`codegraph_search_symbol` và 3 tool document search
(`graphdoc_search`, `graphdoc_search_value`, `graphdoc_search_struct`).

- `codegraph_search_symbol`: arg `rerank = "jev"`, pool = `limit × 4`
  (cap `[jev] max_candidates`), gắn `match_score.probability`, trả
  `no_match`/`rerank`. Chỉ trang đầu — `offset > 0` hoặc `resume` bị từ
  chối vì rerank phá tính ổn định phân trang.
- Doc search: cùng arg `rerank`; response đổi thành object
  `{results, no_match, rerank}` khi bật (mặc định vẫn là array).
  Candidate = `kind \`key\` in \`doc\`` + value tuỳ chọn.
- Config `[jev] doc_include_values` (default false) và `doc_value_chars`
  (default 120): value giúp phân biệt node trùng key ở nhiều file nhưng
  tốn token nên là opt-in.
- Fail-open toàn bộ: Jev lỗi/tắt/timeout → giữ thứ tự cũ + `rerank.used=false`.
- Gộp phần chọn candidate + fail-open vào `codegraph_context::rank()`
  dùng chung cho cả 3 nguồn.

Test: unit cho candidate/apply outcome (MCP), `search_symbol_reranked`
với judge giả (API), live test `#[ignore]` thêm case doc-node-nhờ-value
(đã chạy thật: chọn đúng id 2, p=0.81).

* Bump version to v2.2.13

* Potential fix for pull request finding 'CodeQL / Cleartext logging of sensitive information'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* docs(config): thêm block [jev] vào config.toml mặc định

Theo quy ước: thêm config key phải cập nhật DEFAULT_CONFIG_TOML để
 sinh file mẫu có đủ key (kèm ghi chú opt-in + token chỉ
đọc từ env).

---------

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.37657% with 46 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.28%. Comparing base (023644b) to head (ca08bbf).
⚠️ Report is 3 commits behind head on feat/jev-context-rerank.

Files with missing lines Patch % Lines
crates/codegraph-mcp/src/tools.rs 82.65% 30 Missing ⚠️
crates/codegraph-api/src/lib.rs 89.61% 8 Missing ⚠️
crates/codegraph-context/src/jev.rs 97.35% 4 Missing ⚠️
crates/codegraph-mcp/src/lib.rs 33.33% 4 Missing ⚠️

❌ Your patch status has failed because the patch coverage (90.37%) 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                     @@
##           feat/jev-context-rerank      #60      +/-   ##
===========================================================
+ Coverage                    80.77%   81.28%   +0.51%     
===========================================================
  Files                          105      105              
  Lines                        30205    30561     +356     
===========================================================
+ Hits                         24398    24843     +445     
+ Misses                        5807     5718      -89     

☔ 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.

@codspeed

codspeed Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 22 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 38 untouched benchmarks


Comparing feat/jev-rerank-search (c28291a) with feat/jev-context-rerank (677659e)

Open in CodSpeed

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