feat: surface entity linking results in add_fact/add_preference responses - #94
Open
AhmedHamadto wants to merge 2 commits into
Open
feat: surface entity linking results in add_fact/add_preference responses#94AhmedHamadto wants to merge 2 commits into
AhmedHamadto wants to merge 2 commits into
Conversation
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
|
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. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
add_fact()andadd_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 ofNoneadd_fact()stores subject/object linking results infact.metadata["linked_entities"]add_preference()stores linking result inpref.metadata["linked_entity"]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 correctlytest_add_preference_returns_linked_entity— matching entity →linked: truetest_add_fact_no_match_reports_unlinked— no matches → bothlinked: falseVerified end-to-end against a live Neo4j instance.
Fixes #90
Depends on #93