Skip to content

Facts not linked to entities, making cross-session retrieval fail #77

@danstarns

Description

@danstarns

Problem

When a user saves a fact like "Daniel likes tea" in one chat session, then opens a new chat and asks "what does Daniel like?", the system fails to find any relevant information because no Daniel entity exists to connect the fact to.

Reproduction

Session 1 — User says "Daniel likes tea". The AI calls memory_store (stored as preference):

// Request
{
  "tool": "memory_store",
  "arguments": {
    "memory_type": "preference",
    "content": "Daniel likes tea.",
    "category": "beverage",
    "subject": "Daniel",
    "predicate": "likes",
    "object_value": "tea"
  }
}

// Response — stored successfully, no entity created
{
  "stored": true,
  "type": "preference",
  "id": "f3e0f0c8-e69b-48c7-b8d6-aed29e17656c",
  "category": "beverage"
}

Session 2 (new chat) — User asks "What facts do you know about Daniel?" The AI calls entity_lookup:

// Request
{
  "tool": "entity_lookup",
  "arguments": {
    "name": "Daniel"
  }
}

// Response — entity not found
{
  "found": false,
  "name": "Daniel"
}

The agent responds: "I don't have any specific facts about Daniel. If you want to share something about him, feel free to let me know!" — even though a preference was just stored in the previous session.

Neo4j verification — After Session 1, a MATCH (a) RETURN a query in the Neo4j browser returns only a single node in the entire database:

(:Preference {
  id: "f3e0f0c8-e69b-48c7-b8d6-aed29e17656c",
  preference: "Daniel likes tea.",
  category: "beverage",
  confidence: 1.0,
  created_at: "2026-03-14T03:56:47.344Z",
  embedding: [-0.016, 0.018, ...]  // 1536-dim vector
})

No Entity node for "Daniel" exists. No Fact node exists (the AI chose preference type). The Preference node is completely isolated — no relationships to any other node. This confirms the root cause: memory_store creates the Preference node but never creates or links an Entity node for the subject "Daniel".

Note: The AI chose memory_type: "preference" rather than "fact", but the core bug applies to both — neither add_fact() nor add_preference() create or link Entity nodes. Additionally, the AI in Session 2 only tried entity_lookup and did not attempt memory_search (which might have found the preference via text similarity), highlighting a secondary issue with tool selection.

Expected Behavior

When a fact is stored with a subject (e.g., "Daniel"), the system should:

  1. Create or resolve an Entity node for "Daniel" (type: PERSON)
  2. Link the Fact to the Entity via a relationship (e.g., ABOUT or RELATES_TO)
  3. When a new session queries about "Daniel", the entity lookup finds "Daniel" and traverses to linked facts

Root Cause

  1. No entity creation on store: Both add_fact() and add_preference() in LongTermMemory store nodes without extracting or linking entities from the subject/object fields. Facts, preferences, and entities exist as disconnected islands in the graph.

  2. entity_lookup has no path to facts/preferences: The MCP entity_lookup tool only searches Entity nodes — it has no traversal path to discover Fact or Preference nodes even when the subject matches.

  3. Tool selection gap: The MCP client AI doesn't fall back to memory_search when entity_lookup returns nothing, missing data that could be found via text similarity search.

Proposed Solution

When storing a fact:

  • Extract entity references from subject and object fields in both add_fact() and add_preference()
  • Resolve against existing entities (or create new ones)
  • Create relationships linking the Fact/Preference node to the resolved Entity nodes (e.g., (Entity)-[:SUBJECT_OF]->(Fact), (Fact)-[:OBJECT_OF]->(Entity))
  • Ensure entity_lookup and get_context() traverse Fact and Preference relationships when building context
  • Consider improving the entity_lookup MCP tool description to hint the AI should fall back to memory_search when no entity is found

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions