Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[graph_improvement]: Unique Id removed from update prompt #2020

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions mem0/memory/graph_memory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging

from mem0.memory.utils import format_entities

try:
from langchain_community.graphs import Neo4jGraph
except ImportError:
Expand Down Expand Up @@ -94,8 +96,8 @@ def add(self, data, filters):
extracted_entities = []

logger.debug(f"Extracted entities: {extracted_entities}")

update_memory_prompt = get_update_memory_messages(search_output, extracted_entities)
search_output_string = format_entities(search_output)
update_memory_prompt = get_update_memory_messages(search_output_string, extracted_entities)

_tools = [UPDATE_MEMORY_TOOL_GRAPH, ADD_MEMORY_TOOL_GRAPH, NOOP_TOOL]
if self.llm_provider in ["azure_openai_structured", "openai_structured"]:
Expand Down
17 changes: 17 additions & 0 deletions mem0/memory/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from mem0.configs.prompts import FACT_RETRIEVAL_PROMPT


Expand All @@ -15,3 +17,18 @@ def parse_messages(messages):
if msg["role"] == "assistant":
response += f"assistant: {msg['content']}\n"
return response

def format_entities(entities):
if not entities:
return ""

formatted_lines = []
for entity in entities:
simplified = {
"source": entity["source"],
"relation": entity["relation"],
"destination": entity["destination"]
}
formatted_lines.append(json.dumps(simplified))

return "\n".join(formatted_lines)
Loading