Skip to content

fix(query): prevent generic symbol query flooding via multiplicity penalty and seed deduplication#1832

Open
devcool20 wants to merge 1 commit into
Graphify-Labs:v8from
devcool20:fix-generic-symbol-flooding-1766
Open

fix(query): prevent generic symbol query flooding via multiplicity penalty and seed deduplication#1832
devcool20 wants to merge 1 commit into
Graphify-Labs:v8from
devcool20:fix-generic-symbol-flooding-1766

Conversation

@devcool20

Copy link
Copy Markdown

Description

This PR resolves Issue #1766, which causes query results to be flooded when codebases contain multiple generic/homonymous names (such as Next.js route handlers named GET or POST, or framework entrypoints like index or handler).

Previously, when a query matched a generic word (e.g., "get"), multiple distinct nodes sharing the same generic label (e.g., GET()) would receive the full _EXACT_MATCH_BONUS and get selected as query seeds. Running a BFS traversal from multiple generic nodes ended up pulling in massive portions of unrelated code, burying the actual specific target.


Proposed Changes

  1. Label Multiplicity Penalty (graphify/serve.py):

    • Computes and caches a map of normalized label counts (_label_counts_cache) on the graph G.
    • Divides the final matching score of any node by its label multiplicity (score /= multiplicity), ensuring generic framework convention names cannot easily overpower specific identifiers.
  2. Seed Label Deduplication (graphify/serve.py):

    • Adds a seen_labels tracking set in _pick_seeds to filter out duplicate labels, guaranteeing that only a single representative node gets seeded for any given homonymous label.

Validation & Testing

  • Scenario Mock Test: Verified using a Next.js route handler mock graph. Before the fix, querying "get users" seeded users_model, api_users_GET, and api_analytics_GET (flooding the BFS traversal). After the fix, the query correctly seeds only users_model and a single representative GET node (api_analytics_GET).
  • Regression Testing: Ran the full serve test suite (pytest tests/test_serve.py). All 80 unit tests passed successfully with 0 regressions.

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.

1 participant