Skip to content

feat: surface entity linking results in add_fact/add_preference responses - #94

Open
AhmedHamadto wants to merge 2 commits into
neo4j-labs:mainfrom
AhmedHamadto:feat/linking-feedback
Open

feat: surface entity linking results in add_fact/add_preference responses#94
AhmedHamadto wants to merge 2 commits into
neo4j-labs:mainfrom
AhmedHamadto:feat/linking-feedback

Conversation

@AhmedHamadto

Copy link
Copy Markdown
Contributor

Summary

add_fact() and add_preference() now report whether entities were linked via ABOUT relationships, directly in the tool response. Previously, the only way to know if linking succeeded was to query the graph manually.

Changes:

  • _link_to_entity_by_name() returns {"name": ..., "linked": true/false} instead of None
  • add_fact() stores subject/object linking results in fact.metadata["linked_entities"]
  • add_preference() stores linking result in pref.metadata["linked_entity"]
  • Integration layer surfaces these in the MCP tool response

Example Responses

Fact with one entity match:

{
  "stored": true,
  "type": "fact",
  "triple": "Rust -> USED_FOR -> edge binary",
  "linked_entities": {
    "subject": {"name": "Rust", "linked": true},
    "object": {"name": "edge binary", "linked": false}
  }
}

Preference with entity match:

{
  "stored": true,
  "type": "preference",
  "category": "Python",
  "linked_entity": {"name": "Python", "linked": true}
}

Why This Matters

Without linking feedback, users can't tell if their knowledge graph is actually connected. Orphaned facts and preferences accumulate silently (#77). This makes linking results visible without requiring direct Cypher queries.

Test Plan

3 integration tests in tests/integration/test_linking_feedback.py:

  • test_add_fact_returns_linked_entities — subject linked, object not → both reported correctly
  • test_add_preference_returns_linked_entity — matching entity → linked: true
  • test_add_fact_no_match_reports_unlinked — no matches → both linked: false

Verified end-to-end against a live Neo4j instance.

Fixes #90
Depends on #93

EC2 Default User added 2 commits April 9, 2026 03:05
When add_fact() or add_preference() is called, the new
_link_to_entity_by_name() method looks up matching entities by name
(case-insensitive) and creates ABOUT relationships in the graph.

Changes:
- Add _link_to_entity_by_name() to LongTermMemory with calls from
  add_fact() (subject + object) and add_preference() (category)
- Add LINK_FACT_TO_ENTITY query constant and enhance GET_ENTITY_BY_NAME
  with case-insensitive matching
- Add fallback name-based entity lookup and linked facts/preferences
  retrieval in MCP memory_get_entity tool
- Fix missing 'import logging' in long_term.py that caused NameError
  in the except handler, silently breaking all entity linking via MCP
- Add 5 integration tests verifying ABOUT relationship creation

Fixes neo4j-labs#77
Fixes neo4j-labs#87
…nses

_link_to_entity_by_name() now returns {name, linked} instead of None.
add_fact() stores subject/object linking results in fact.metadata, and
add_preference() stores linking result in pref.metadata. The integration
layer surfaces these in the tool response so callers can see what was
linked without querying the graph.

Example response:
  {"stored": true, "type": "fact", ...,
   "linked_entities": {"subject": {"name": "Rust", "linked": true},
                       "object": {"name": "edge binary", "linked": false}}}

Fixes neo4j-labs#90
@vercel

vercel Bot commented Apr 9, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the lyonwj's projects Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Apr 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agent-memory Ready Ready Preview, Comment Apr 23, 2026 0:53am

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.

Enhancement: add_fact/add_preference should report entity linking results

1 participant