Skip to content

fix(algorithms): use declared primary key instead of hardcoded node.id#1

Open
timothyEastridge wants to merge 1 commit into
mainfrom
fix/algorithms-declared-pk
Open

fix(algorithms): use declared primary key instead of hardcoded node.id#1
timothyEastridge wants to merge 1 commit into
mainfrom
fix/algorithms-declared-pk

Conversation

@timothyEastridge

Copy link
Copy Markdown
Member

Problem

GraphAlgorithms hardcoded RETURN node.id AS node_id (and {id: $x} MATCH filters), which raises "Cannot find property id for node" on any table whose primary key isn't literally id — i.e. essentially all real schemas (Store(store_key), Identity(identity_id), CustomerRecord(record_id), RetailOrder(order_id), …). This broke run_algorithm for the Bridgr agent on the seeded demo and any customer data.

Fix

  • Add _pk(node_label) — resolves the declared PK via table_info (the Python binding reports the flag as "primary key", with a space); falls back to the first column, then id.
  • Use node.<pk> in weakly_connected_components, pagerank, louvain, strongly_connected_components, k_core; use {<pk>: $x} in degree_centrality and shortest_path.
  • k_core also returned the wrong column — corek_degree AS core_number (verified against K_CORE_DECOMPOSITION output).

Verification

In-container against the seeded retail graph: Louvain over CustomerRecord/SPLINK_DB now returns non-null node_id (real record_id values); the agent's segmentation paints and traversal works.

Note

_build_adjacency (custom cross-label algos) still assumes id across heterogeneous PKs — left for a separate change; it isn't on the agent's run_algorithm path. bridgr-platform/bridgr-mono pins this commit; merging here keeps fresh clones + CI green.

🤖 Generated with Claude Code

GraphAlgorithms hardcoded `RETURN node.id AS node_id` (and `{id: $x}` matches),
raising "Cannot find property id for node" on any table whose PK isn't literally
`id` (Store(store_key), Identity(identity_id), CustomerRecord(record_id), ...).
This broke run_algorithm for the agent on real schemas.

- Add _pk(node_label): resolve the declared PK via table_info (the Python binding
  reports the flag as "primary key" with a space); fall back to first column, "id".
- Use node.<pk> in wcc/pagerank/louvain/scc/k_core and {<pk>: $x} matches in
  degree_centrality + shortest_path.
- k_core returned the wrong column too: `core` -> `k_degree AS core_number`
  (verified against the engine's K_CORE_DECOMPOSITION output).

Verified in-container on the seeded retail graph: louvain over
CustomerRecord/SPLINK_DB now returns non-null node_id (record_id values).
(_build_adjacency spans all tables with heterogeneous PKs — left for a separate change.)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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