Repository navigation
feat(query): a natural-language question leads with its best-matching file (#4480) - #4481
devkancheti4-design wants to merge 1 commit into
Conversation
… file On a question of three or more terms, the single best-scoring node is often a test, or a same-named helper in another file, while the file the question is about matches it through several nodes at once. `_lead_by_file` sums the scores of the 50 best-scored candidates per file and puts the best node of the best file first among the start nodes; the other seeds keep their order. A test file leads only when the question names tests or nothing else matches. Short queries (identifier lookups) are unchanged. SWE-bench Lite, 285 issues across 12 repos, default BFS depth 2, 2,000-token budget, fixed file printed first: 78 -> 88 asked by the issue title, 67 -> 80 by title plus 400 characters (first five files: 131 -> 136, 122 -> 140). The constants were chosen on django and sympy; on the 10 other repos alone: 24 -> 27 and 20 -> 29. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the pull request, @devkancheti4-design. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.
Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 sampled, not proven).
Formal verification. PR-changed functions: 1/1 verified (0 proven, 1 may-equivalent, 0 distinguished) · 0 not verified.
Graphify review — findings
Adds file-aware lead selection to natural-language queries: with 3+ search terms, _query_graph_text now starts from the best node of the file whose top-50 scored candidates have the highest summed score, instead of the single best-scoring node. The other seeds keep their order behind it. Test files are skipped as the lead unless the question mentions tests or only test files match, and ties break by path so the result is deterministic. Short queries (under 3 terms) skip this and keep their exact match first, so identifier lookups behave as before. The commit comment reports SWE-bench Lite gains (fixed file printed first: 78 → 88 by title, 67 → 80 by title plus 400 characters), with the constants tuned on django and sympy. New tests cover the ranking, test-file handling, tie-breaks and the candidate cutoff.
No blocking issues surfaced. 4 lower-confidence candidates did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 648 functions depend on the 170 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
_query_graph_text()— 51 callers, 7 callees
Verification — 648 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 460 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
17 of 423 test file(s) selected (4%) via static blast radius.
tests/test_benchmark.py— impacttests/test_benchmark_raw_graph.py— impacttests/test_benchmark_real_query.py— impacttests/test_explain_same_file_tie.py— impacttests/test_file_label_disambiguation.py— impacttests/test_mcp_graph_view_cache.py— impacttests/test_path_cli.py— impacttests/test_query_induced_edges.py— impacttests/test_query_lead_file.py— impact, changed-testtests/test_query_mcp_direction.py— impacttests/test_query_names_its_graph.py— impacttests/test_query_seed_order.py— impacttests/test_query_seeds.py— impacttests/test_serve.py— impacttests/test_serve_http.py— impacttests/test_terraform.py— impacttests/test_truncation_full_answer.py— impact
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Formal verification
No difference found (not proven): No behavior difference found in \_query\_graph\_text (not a proof).
The verifier ran both versions of \_query\_graph\_text on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.
Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.
Note: An input the sampler did not try could still differ.
· 1 more finding(s) on lines outside this diff (see the check run).
|
@safishamsi Devieswar here (Model D; this PR, #4470 and #4478). I'd like to give Graphify Model D's core, written natively into Graphify under its Apache-2.0 license, with no dependency on Model D:
If the metrics convince you, I'd like the title of core performance engineer on Graphify. I can start with (1) as a PR this week, so you can judge the work first. The evaluation, with its scripts and raw rows: https://optimal-context-mapping-site.vercel.app/independent/ |
What does this PR do?
Closes #4480. On a natural-language question, the query now starts from the file that matches the question best, instead of the single best-scoring node. The renderer prints the start nodes first, so this is the file an agent reads first.
_lead_by_file(G, ranked, terms)runs on questions of three or more terms:_pick_seedskeep their order behind it;graphify.paths._is_test_path) leads only when the question names tests (test,pytest,fixture,spec, …), or when only test files match;Short queries return None and are unchanged, so an identifier lookup keeps its exact match first. Explicit
--seedvalues never reach this code._pick_seeds,_score_queryand_subgraph_to_textare untouched.Measured
SWE-bench Lite: 285 issues across 12 repos, graphs from
graphify update, default BFS depth 2, 2,000-token budget. Each count is how often the fix's changed file is printed first, in the first 3 files, and in the first 5:Neither part works alone. Test files gather many matching nodes, so summing without the test rule makes the first file worse. The test rule without the sum fixes the first file but not the top five.
The constants (50 candidates, 3 terms) were chosen on django and sympy. On the 10 other repos alone, right file first goes 24 → 27 by title and 20 → 29 by title + 400.
Type of change
Verification & Invariants
Invariants:
a query of fewer than three terms renders exactly as before;
the lead is always a node the ranking already scored, so a question that matches nothing still says so;
the lead is deterministic: ties break by path;
no generated or persisted state changes; it is query-time only.
Read the CONTRIBUTING.md guide.
Reproduced the issue and identified the invariant.
Made the smallest fix necessary.
Added isolated boundary tests and end-to-end tests.
Kept the PR description synchronized with the final implementation.
Documented any limitations / unsupported cases explicitly:
_pick_seedshadn't already picked it;How was this tested?
The new tests cover:
_query_graph_text: a 4-term question leads with the best file, a 2-term query is unchanged, and a question about tests leads with the test.With the lead switched off, the first end-to-end test fails.
Graphify-specific checklist
🤖 Generated with Claude Code