Skip to content

Fix infra topology query-sensitive ranking#999

Merged
nndn merged 2 commits into
mainfrom
fix/infra-topology-semantic-similarity
Jul 13, 2026
Merged

Fix infra topology query-sensitive ranking#999
nndn merged 2 commits into
mainfrom
fix/infra-topology-semantic-similarity

Conversation

@yashkrishan

Copy link
Copy Markdown
Collaborator

Summary

  • Wire InfraTopologyReader into the existing semantic similarity scoring path so infra claims are ranked by query relevance instead of a flat default score.
  • Keep topology traversal query-free; stamp similarity after discovery so BFS/blast-radius behavior does not change.
  • Allow graph read --query on infra_topology.service_neighborhood and extract shared claim_semantic_similarity across readers.

Test plan

  • pytest tests/unit/test_p9_readers.py
  • pytest tests/conformance/test_graph_surface_lite_e2e.py
  • Contract suites: graph workbench ontology, surface-lite contract, CLI contract, views
  • FalkorDB roundtrip integration test

Made with Cursor

Wire InfraTopologyReader into the existing fact_query scoring path without
changing traversal discovery, allow graph read --query on the infra view, and
extract shared claim_semantic_similarity for all readers.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Query-aware ranking is now supported in infrastructure topology results, helping the most relevant items appear first.
    • Search/query input is now accepted across the relevant graph surface for better filtering and ranking.
  • Bug Fixes

    • Improved similarity scoring consistency across readers so rankings are more stable and predictable.
    • Boolean or malformed similarity values are now ignored instead of affecting results.
  • Tests

    • Added end-to-end and unit coverage for query-sensitive ranking behavior.

Walkthrough

Adds a shared claim_semantic_similarity helper for normalizing semantic similarity values from claim rows, adopts it across seven readers, extends InfraTopologyReader to stamp query-derived similarity scores during traversal, updates ontology view filters to accept query, and adds corresponding unit and e2e tests.

Changes

Semantic similarity propagation

Layer / File(s) Summary
Shared similarity helper
potpie/context-engine/application/readers/_common.py
Adds claim_semantic_similarity(row) returning a normalized float or None (boolean/non-numeric values yield None), and exports it via __all__.
Reader adoption of shared helper
application/readers/coding_preferences.py, decisions.py, docs.py, features.py, owners.py, prior_bugs.py, timeline_reader.py
Replaces manual row.properties["semantic_similarity"] extraction and float coercion with calls to claim_semantic_similarity(row) when building Candidate objects; timeline_reader.py also updates its internal sort_key.
Query-based similarity stamping in infra topology
application/readers/infra_topology.py
Populates Candidate.semantic_similarity via the shared helper, passes fact_query=req.query on the unanchored traversal path, and adds _stamp_query_similarity to re-query discovered rows by claim_key and stamp similarity scores without changing traversal discovery.
Ontology filter support for query
domain/graph_workbench_ontology.py
Adds "query" to optional_scope and supported_filters for the infra_topology.service_neighborhood view override.
Unit and e2e test coverage
tests/unit/test_p9_readers.py, tests/conformance/test_graph_surface_lite_e2e.py
Adds tests verifying claim_semantic_similarity ignores booleans, anchored/unanchored/no-query semantic ranking behavior in InfraTopologyReader, and an e2e test confirming query-sensitive ranking through resolve and read surfaces.

Sequence Diagram(s)

sequenceDiagram
  participant Reader as InfraTopologyReader
  participant Traversal as BFS traversal
  participant Store as Claim store

  Reader->>Traversal: traverse anchors (query-free)
  Traversal->>Store: find_claims (structural filters)
  Store-->>Traversal: discovered rows
  Reader->>Reader: _stamp_query_similarity(rows, req.query)
  Reader->>Store: find_claims(claim_key_in, fact_query=req.query)
  Store-->>Reader: similarity-stamped rows
  Reader->>Reader: build Candidate.semantic_similarity via claim_semantic_similarity
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: making infra topology ranking sensitive to the query.
Description check ✅ Passed The description is directly related to the changeset and matches the implemented infra ranking and query support work.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Co-authored-by: Cursor <cursoragent@cursor.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@potpie/context-engine/application/readers/infra_topology.py`:
- Around line 233-260: The stamping logic in _stamp_query_similarity currently
assumes limit=len(claim_keys) will return all requested rows, but
ClaimQuery.find_claims applies claim_key_in after vector ranking so some keys
can be dropped. Update _stamp_query_similarity to handle misses by doing a keyed
follow-up for any unstamped claim keys, or switch to a query shape that
prefilters by claim_key before similarity ranking. Make sure the fix preserves
the existing row set while still attaching semantic_similarity to every
discovered row.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 30262d1b-d85a-4160-94b5-8b52f30a0c6c

📥 Commits

Reviewing files that changed from the base of the PR and between a191a5e and 4aff175.

📒 Files selected for processing (12)
  • potpie/context-engine/application/readers/_common.py
  • potpie/context-engine/application/readers/coding_preferences.py
  • potpie/context-engine/application/readers/decisions.py
  • potpie/context-engine/application/readers/docs.py
  • potpie/context-engine/application/readers/features.py
  • potpie/context-engine/application/readers/infra_topology.py
  • potpie/context-engine/application/readers/owners.py
  • potpie/context-engine/application/readers/prior_bugs.py
  • potpie/context-engine/application/readers/timeline_reader.py
  • potpie/context-engine/domain/graph_workbench_ontology.py
  • potpie/context-engine/tests/conformance/test_graph_surface_lite_e2e.py
  • potpie/context-engine/tests/unit/test_p9_readers.py

Comment thread potpie/context-engine/application/readers/infra_topology.py
@linear-code

linear-code Bot commented Jul 7, 2026

Copy link
Copy Markdown

POT-1852

@nndn nndn merged commit 5631cd0 into main Jul 13, 2026
13 checks passed
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.

2 participants