Repository navigation
feat(context): rerank candidates with Jev (TypeSafe SystemOne) - #59
Conversation
`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.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Codecov Report❌ Patch coverage is ❌ Your patch status has failed because the patch coverage (93.12%) 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 #59 +/- ##
==========================================
+ Coverage 80.46% 81.29% +0.83%
==========================================
Files 103 105 +2
Lines 29526 30561 +1035
==========================================
+ Hits 23758 24846 +1088
+ Misses 5768 5715 -53 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will not alter performance1 warning
Comparing |
* 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
… sensitive information' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
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).
Vấn đề
codegraph_contextchỉ tìm symbol bằngContainstrên tên. Query tự nhiên("where do we validate that config.toml parses") trả
_No matches._, còn querymột từ thì trả symbol đầu tiên khớp chuỗi, không liên quan ngữ nghĩa — trong khi
callers/callees chỉ có giá trị khi symbol gốc đúng.
Cách giải
Thêm
rerank = "jev"(MCP arg, GraphQL field; mặc địnhnone). Khi bật:Contains, lọc kind code (bỏ variable/parameter/field/constant) và loạitest/bench, cap
[jev] max_candidates(mặc định 40).best_symbol(Choice): mỗi candidate là một option, cộngnone_of_the_above.any_fits(Noul): 0–1, chỉ để chẩn đoán.probabilities(giữ đủ thứ tự, ngưỡng chỉ áp chohạng 1);
no_matchkhinonethắng/hoà xác suất hạng 1, hoặc hạng 1 dướimin_probability. Pool < 3 →no_matchluôn, không gọi API.pool, kèm
rerank.used = false+reason. Không bao giờ làm hỏng context.ContextHit.match_score { probability, confidence },ContextResponse.no_match/rerank, markdown in(p=0.62)và_No symbol matches "<query>"._khi không có gì đủ liên quan.Config opt-in (dữ liệu rời máy), token chỉ đọc từ env:
Đo thực tế (jev-1.13-free)
choice+none+noul(4 candidate)parse_config, p=0.62 / none 0.38choicekhông cónoneconfidence= 1.0 kể cả pool rácnoul/ candidate→ Chọn
choice+none; không dùng Noul làm cổng: Jev trảnoul = 0.33ngay cả khi đã chọn đúng p=0.75. Jev cũng từng chọn một
#[test]fn trong fileđúng → pool loại test/bench mặc định.
Test
crates/codegraph-context): tokenize, pool, lọc test/kind,ngưỡng
no_match, sort + cắtlimit, markdown có p, fail-open, pool nhỏ khônggọi API, parse
[jev].#[ignore]gọi API thật:cargo test -p codegraph-context --test jev_live -- --ignored --nocapture.Verify
cargo fmt --all✅cargo clippy --workspace --all-targets -- -D warnings✅cargo test --workspace✅ (4 teststorage::redisfail do không córedis-server — pre-existing, đã xác nhận chạy standalone)
cargo test -p codegraph-context --test jev_live -- --ignored✅Ghi chú
min_probabilitychỉnh đượctrong config nên không phải build lại.
codegraph_search_symbolchưa rerank — đợt sau nếu context chứng minh hiệu quả.