Skip to content

graph: entity extractor creates self-loop edges (source == target) #2215

@bug-ops

Description

@bug-ops

Description

During CI-204 testing of A-MEM link weight evolution, a self-referential edge was found in graph_edges:

id=2 | Anthropic Claude API → includes → Anthropic Claude API
retrieval_count=7, confidence=0.8

The entity extractor generates an edge where source_entity_id == target_entity_id. This happens when the LLM produces a relation like "Anthropic Claude API includes [capabilities]" and resolves both sides to the same entity.

Impact

  • Semantically invalid: a node relating to itself has no information value
  • Spreading activation: self-loops cause the node to accumulate activation from itself on each hop; with decay_lambda=0.85 and max_hops=3, this is bounded but adds noise
  • Graph traversal / BFS: typically safe (visited-set deduplication) but adds an extraneous edge

Reproduction

Config: testing.toml with [memory.graph] enabled=true. Run several sessions with graph extraction active. Query:

SELECT e.id, s.name, t.name, e.relation 
FROM graph_edges e 
JOIN graph_entities s ON e.source_entity_id=s.id 
JOIN graph_entities t ON e.target_entity_id=t.id 
WHERE e.source_entity_id=e.target_entity_id;

Expected

Self-loop edges (source == target) should be rejected at the insertion boundary in GraphExtractor or the DB schema should enforce CHECK (source_entity_id != target_entity_id).

Severity

LOW — does not break functionality, but pollutes the knowledge graph and adds minor noise to spreading activation.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions