Skip to content

enhance (cost + performance) adding weights to graphs derived from confidence score to use weighted bfs#399

Open
akhiljns wants to merge 1 commit intosafishamsi:v4from
akhiljns:weightedGraphs
Open

enhance (cost + performance) adding weights to graphs derived from confidence score to use weighted bfs#399
akhiljns wants to merge 1 commit intosafishamsi:v4from
akhiljns:weightedGraphs

Conversation

@akhiljns
Copy link
Copy Markdown

Weighted Graph Traversal and Pathfinding

Changes

build.py

Every edge now gets a cost attribute derived from confidence_score:

cost = 1.0 / confidence_score

Examples:

  • EXTRACTED = 1.0
  • INFERRED@0.8 = 1.25
  • AMBIGUOUS@0.2 = 5.0

serve.py

Two new algorithms were added:

_weighted_bfs()

A priority-queue-based BFS using heapq that explores high-confidence edges first within the depth limit.

_weighted_shortest_path()

Uses nx.dijkstra_path() with the cost attribute.

MCP tools

  • query_graph now accepts mode: "weighted" alongside "bfs" and "dfs".
  • shortest_path now accepts weighted: true for Dijkstra-based traversal.

cluster.py

cluster() and _partition() now accept weighted=True.

When enabled:

  • confidence_score is copied into the weight edge attribute for Leiden/Louvain clustering.
  • EXTRACTED edges (1.0) bind communities tighter than INFERRED edges (0.6–0.9) or AMBIGUOUS edges (0.1–0.3).

main.py

New CLI flags:

  • graphify query "..." --weighted — priority-queue BFS.
  • graphify path "A" "B" --weighted — Dijkstra shortest path.

Help text has also been updated for both commands.

How It Works

graphify query "authentication" --weighted

Explores high-confidence edges first.

graphify path "UserService" "Database" --weighted

Finds the most trustworthy path, not necessarily the shortest.

The weighted path avoids low-confidence shortcuts. For example, an AMBIGUOUS 1-hop edge with cost 5.0 is skipped in favor of a 3-hop EXTRACTED path with total cost 3.0.

@akhiljns akhiljns changed the title adding weights to graphs derived from confidence score and added weighted bfs to traverse using cost attribute enhance (cost + performance) adding weights to graphs derived from confidence score to use weighted bfs Apr 16, 2026
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