Skip to content

fix(query): demote image caption nodes in seed scoring alongside docs - #5394

Closed
ayushcodes10 wants to merge 1 commit into
Graphify-Labs:v8from
ayushcodes10:fix-query-image-caption-demotion
Closed

ayushcodes10 wants to merge 1 commit into
Graphify-Labs:v8from
ayushcodes10:fix-query-image-caption-demotion

Conversation

@ayushcodes10

Copy link
Copy Markdown
Contributor

Bug

Fixes #445 (the remaining gap after #4601 was closed; see that PR's closing comment for context).

/graphify query seed selection already demotes test, document and paper nodes, and nodes without a source file, to _QUERY_DEMOTE_WEIGHT (0.3) unless the question itself asks about tests or docs (_query_path_weight in graphify/serve.py, introduced by a50ad2b4 for the same issue #445 and since hardened by 0caa1c39/01c0a859). Image nodes got no such treatment at all, so a golden test render whose caption happens to mention the same terms as the question still wins the seed slot a precise code node should get — exactly the issue's own repro: three *.png territory renders outranking the fifteen actual mutation sites for a cross cutting query.

Fix

Add "image" to the same file_type check the document/paper demotion already uses (graphify/serve.py), so it rides the same demote_docs toggle (the per corpus escape hatch for a doc first corpus, #5084) rather than a separate flag. No new weight tier, no new config surface — just closing the one file_type this mechanism forgot.

Tests

Extended tests/test_query_source_first.py:

  • Added an img node (file_type="image") to the shared graph fixture, sharing src's own label so name matching alone cannot tell them apart, mirroring how the existing tst node is set up.
  • test_image_caption_nodes_are_weighted_down: the image node scores competitively on label match alone, _query_path_weight demotes it to _QUERY_DEMOTE_WEIGHT, and the combined ranking puts the source node ahead of it.
  • test_disabling_doc_demotion_also_preserves_full_weight_for_images: demote_docs=False keeps the image node at full weight, same escape hatch as docs.

Verification

  • 1 of 2 new tests fails against unmodified upstream/v8 (confirmed by temporarily restoring the unmodified file); the demote_docs=False control passes unmodified too, as expected (that toggle already defeats all demotion regardless of file type).
  • tests/test_query_source_first.py full file: 12 passed.
  • Query/serve sweep (pytest -k "query or serve"): 840 passed, 11 skipped, no regressions.
  • Full suite: 1 failed, 11711 passed, 234 skipped, 1 xfailed — the one failure (test_erlang_extractor.py::test_erlang_attributes_includes_and_remote_calls) confirmed pre-existing and unrelated to this change.
  • python3 -m tools.skillgen --check: check OK: 134 artifact(s) match committed output and expected/.

Query seed selection already demotes test, document and paper nodes
and nodes without a source file, unless the question itself asks
about tests or docs, so a precise code symbol is not beaten by a
test or doc whose own label repeats the question's words. Image
nodes got no such treatment at all, so a golden test render whose
caption happens to mention the same terms as the question still won
the seed slot a code node should get, exactly the repro issue Graphify-Labs#445
reported, three planes render images outranking the fifteen actual
mutation sites for a cross cutting query.

Add image to the same file_type check the document and paper
demotion already uses, so it rides the same demote_docs toggle (the
per corpus escape hatch for a doc first corpus) rather than a
separate flag.
@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 22, 2026
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @ayushcodes10. 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.11 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify review View in Graphify

Nothing blocking · 2 possible issues to check · Merge confidence 5/5

2 possible issues to check · High impact

Query scoring now applies the existing document-demotion weight to image nodes as well.

2 possible issues we couldn't confirm

They don't change the score.

Code graph · 872 functions depend on this change
  • 2 functions became more coupled. _query_terms() (31 callers), _score_query() (25 callers).
  • 28 of 613 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed 05236da · Full report in the Graphify check

safishamsi added a commit that referenced this pull request Nov 23, 2026
Maintainer tweaks on top of the #5299/#5394/#5315/#5374 batch:
- Move `import anyio` in serve.py to module top (was re-imported per call
  inside _warm_graph), a trivial cleanup on #5374.
- 0.9.117 changelog and version bump. No AST-cache schema change in this
  batch (query scoring, export filenames, serve reload, rcfile parsing).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.118 via an authorship-preserving cherry-pick. Image nodes are now demoted in seed scoring alongside documents and papers, so a caption-rich image no longer out-seeds real code for a query whose terms it happens to repeat. Thanks @ayushcodes10!

@safishamsi safishamsi closed this Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query seed-node selection matches image/doc captions, dominating BFS start for cross-cutting code queries

2 participants