AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Property Graph Relation Keys Collide When Entity IDs Or Labels Contain Underscores

SimplePropertyGraphStore silently overwrites Relation objects because LabelledPropertyGraph uses underscore-joined string keys for relation lookup. Distinct triplets such as A_B-C-D and A-B-C_D collide on key A_B_C_D, causing retrieved relations to belong to another triplet. The graph retains the correct number of triplets but returns inconsistent relation data, including after persistence.

highConfidence 95%Llama_indexVectorStoreIndexIndexingRetrievalAffected V0.14.25

Origin Analysis

LabelledPropertyGraph._get_relation_key builds a key by concatenating source_id, label, and target_id with underscores without escaping or boundary disambiguation. Since underscores are valid characters in IDs/labels, different trips can map to the same key. add_triplet checks the tuple (subject,relation,object) but stores the Relation in a dictionary keyed by that ambiguous string, overwriting any earlier entry with the same derived key.
1. Install llama-index-core at commit 6dd2f3cdd9ce7ff927ea8d46ccee08875bb00f95. 2. Run the provided reproduce.py script that inserts two Relation objects: - Relation(source_id='A_B', label='C', target_id='D', properties={'fact': 1}) - Relation(source_id='A', label='B', target_id='C_D', properties={'fact': 2}) 3. Inspect store.graph.triplets and store.graph.relations; observe triplet count is 2 but relation count is 1. 4. Call get_triplets(ids=['A_B']) and see the returned Relation has label 'B', properties {'fact': 2}, and endpoints A and C_D, which is inconsistent. 5. Persist and reload; the overwritten relation persists.

Fixing Code Block

Edge Case Audit

If a persisted file already contains an overwritten relation (data lost at write time), rebuilding cannot recover the lost Relation; the overwritten relation remains gone. Rolling back to an older version after persisting with the new JSON keys will break lookups because old code expects underscore keys. Concurrent writes to the graph may race when _rebuild_relation_keys is called; synchronize access or rebuild before making the graph visible. Users with existing persisted graphs should migrate them using _rebuild_relation_keys on load and avoid downgrading unless they also rewrite keys back to the old format.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state