Skip to content

fix(query): downweight rationale prefix seeds - #2975

Open
hopstreax wants to merge 1 commit into
Graphify-Labs:v8from
hopstreax:fix/2962-docstring-query-seeds
Open

hopstreax wants to merge 1 commit into
Graphify-Labs:v8from
hopstreax:fix/2962-docstring-query-seeds

Conversation

@hopstreax

Copy link
Copy Markdown
Contributor

Summary

closes #2962

Natural-language docstrings/rationale nodes could dominate query seed selection when a query term matched the beginning of the docstring.

For example:

graphify query "what computes ROAS"

could rank:

"Computes Return On Ad Spend (ROAS)..."

above the production code responsible for ROAS because prefix matches receive a 100× bonus over substring matches.

This change makes that prefix signal type-aware without changing code-symbol scoring.

Root Cause

_score_query() applies the same prefix-match bonus to all node types.

Rationale nodes are natural-language descriptions and commonly begin with verbs such as:

  • Computes ...
  • Returns ...
  • Creates ...
  • Stored ...

These sentence-initial words can therefore receive the same identifier-oriented prefix bonus as a code symbol.

The problem was amplified by the separate multi-word joined-prefix tier and the best_by_term singleton scoring used by the per-term seed guarantee.

file_type was already available on query-time nodes but was not used by the scorer.

Solution

Introduce a rationale-specific prefix factor:

_RATIONALE_PREFIX_FACTOR = 0.01

For file_type == "rationale" nodes, the factor is applied consistently to:

  • multi-word joined-prefix scoring
  • per-term prefix scoring
  • singleton/per-term seed scoring

Code nodes retain the existing prefix scoring.

Exact matches, substring matches, source matches, coverage, seed-gap selection, and the per-term guarantee remain unchanged.

Other node types are also left unchanged.

Why 0.01?

The existing prefix bonus is:

100 × IDF

Reducing rationale prefixes by 0.01 makes their effective prefix contribution equivalent to the existing substring scale while preserving the prefix signal for code identifiers.

In the reproduced multi-word case, higher factors such as 0.05 and 0.10 still allowed the rationale node to dominate. 0.01 was sufficient to allow the relevant production code node to become the primary seed.

Tests

Added focused regression coverage for:

Validation

uv run pytest tests/test_serve.py
151 passed

Full suite:

4837 passed
41 skipped
20 pre-existing Windows platform limitations

Static checks:

uv run ruff check .
All checks passed!

Pyright also reports no errors in the changed scoring code.

Real Behavior Proof

Command:

graphify query "what computes ROAS"

Before:

Top seed: rationale/docstring node
Rationale score: 110.9009
roas_report: 17.3287

After:

Top seed: roas_report
Rationale score: 2.1383
roas_report: 17.3287
calculate_roas: 1.0397

The production code node is now the primary seed while the rationale node remains available as a secondary seed.

Scope

This change is intentionally limited to rationale-node prefix scoring. It does not alter the global prefix bonus or unrelated query-ranking behavior.

@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 reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Formal verification. No changes could be formally verified in this run.


Graphify review — findings

Downweights prefix-match bonuses for file_type == "rationale" nodes in _score_query via a new _RATIONALE_PREFIX_FACTOR (0.01), so docstring action verbs like "Computes…" no longer out-seed production code symbols (#2962). Applies the factor to the joined-prefix, per-term prefix, and singleton-prefix tiers only; exact, substring, and code-node scoring are untouched. Adds six tests covering the scaled prefix behavior plus unchanged code-prefix, exact-rationale, and substring paths.

No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 557 functions depend on the 335 functions this change touches.

Health — this change adds coupling hotspots:

  • new: dispatch_command() — 2 callers, 119 callees
  • new: _query_graph_text() — 20 callers, 9 callees
  • new: _score_query() — 20 callers, 5 callees
  • new: _query_terms() — 25 callers, 3 callees
  • new: run_benchmark() — 16 callers, 3 callees
  • new: _build_server() — 2 callers, 16 callees
  • new: _load_graph() — 9 callers, 3 callees
  • new: _query_subgraph_tokens() — 7 callers, 3 callees
  • …and 9 more — each is listed as a finding

Verification — 557 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: 399 function(s) in the blast radius were not formally verified this run

Formal verification

Could not verify: Could not verify \_score\_query.

The verifier did not have enough to check \_score\_query, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: not verifiable: all 45 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)

· 17 more finding(s) on lines outside this diff (see the check run).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant