From 7f20b215726d73350a4cf62d3e7e5a9b4898b117 Mon Sep 17 00:00:00 2001 From: Preston Rasmussen <109292228+prasmussen15@users.noreply.github.com> Date: Tue, 4 Mar 2025 16:34:19 -0500 Subject: [PATCH] Entity attributes in prompts (#284) * add node attributes to prompts * tested * attribute update --- graphiti_core/prompts/dedupe_nodes.py | 2 +- graphiti_core/search/search_filters.py | 2 +- graphiti_core/utils/maintenance/node_operations.py | 12 +++++++++++- pyproject.toml | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/graphiti_core/prompts/dedupe_nodes.py b/graphiti_core/prompts/dedupe_nodes.py index 696b64a2..99d478a4 100644 --- a/graphiti_core/prompts/dedupe_nodes.py +++ b/graphiti_core/prompts/dedupe_nodes.py @@ -64,7 +64,7 @@ def node(context: dict[str, Any]) -> list[Message]: {json.dumps(context['existing_nodes'], indent=2)} - Given the above EXISTING NODES, MESSAGE, and PREVIOUS MESSAGES. Determine if the NEW NODE extracted from the conversation + Given the above EXISTING NODES and their attributes, MESSAGE, and PREVIOUS MESSAGES. Determine if the NEW NODE extracted from the conversation is a duplicate entity of one of the EXISTING NODES. diff --git a/graphiti_core/search/search_filters.py b/graphiti_core/search/search_filters.py index 2d77e641..be574c07 100644 --- a/graphiti_core/search/search_filters.py +++ b/graphiti_core/search/search_filters.py @@ -55,7 +55,7 @@ def node_search_filter_query_constructor( filter_params: dict[str, Any] = {} if filters.node_labels is not None: - node_labels = ':'.join(filters.node_labels) + node_labels = '|'.join(filters.node_labels) node_label_filter = ' AND n:' + node_labels filter_query += node_label_filter diff --git a/graphiti_core/utils/maintenance/node_operations.py b/graphiti_core/utils/maintenance/node_operations.py index e0610433..85a28a9a 100644 --- a/graphiti_core/utils/maintenance/node_operations.py +++ b/graphiti_core/utils/maintenance/node_operations.py @@ -289,7 +289,10 @@ async def resolve_extracted_node( start = time() # Prepare context for LLM - existing_nodes_context = [{'uuid': node.uuid, 'name': node.name} for node in existing_nodes] + existing_nodes_context = [ + {'uuid': node.uuid, 'name': node.name, 'attributes': node.attributes} + for node in existing_nodes + ] extracted_node_context = { 'uuid': extracted_node.uuid, @@ -366,6 +369,13 @@ async def resolve_extracted_node( node = existing_node node.name = name node.summary = summary_response.get('summary', '') + + new_attributes = existing_node.attributes + existing_attributes = existing_node.attributes + for attribute_name, attribute_value in existing_attributes.items(): + if new_attributes.get(attribute_name) is None: + new_attributes[attribute_name] = attribute_value + uuid_map[extracted_node.uuid] = existing_node.uuid end = time() diff --git a/pyproject.toml b/pyproject.toml index 7b7f77b9..3c4c3540 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "graphiti-core" -version = "0.7.6" +version = "0.7.7" description = "A temporal graph building library" authors = [ "Paul Paliychuk ",