Open pihang opened 3 weeks ago
Here's a proposed solution to integrate graph database entities into the memory recall process:
def enhanced_memory_recall(relevant_memories):
# Combine vector storage memories
memories_text = "\n".join(memory["memory"] for memory in relevant_memories["results"])
# Add graph entity information to provide additional context
if "relations" in relevant_memories and relevant_memories["relations"]:
# Format graph entities into a readable string
graph_context = "\n".join([
f"Relation: {entity.get('relationship', 'Unknown')} "
f"From: {entity.get('source', 'Unknown')} "
f"To: {entity.get('target', 'Unknown')}"
for entity in relevant_memories.get("relations", [])
])
# Combine memories with graph entity context
full_context = f"{memories_text}\n\n--- Related Entities ---\n{graph_context}"
else:
full_context = memories_text
return full_context
Key improvements:
Recommended modifications in memo/proxy/main.py
:
# Replace existing memory text generation
memories_text = enhanced_memory_recall(relevant_memories)
Rationale and References:
Additional Recommendations:
Potential Enhancement: For more advanced use cases, you might want to develop a more sophisticated entity integration strategy that can:
🐛 Describe the bug
memo/proxy/main.py
It seems that when answering questions in memo/proxy/main.py, the recall mechanism doesn't utilize the dictionary information from the graph database.Current code:
memories_text = "\n".join(memory["memory"] for memory in relevant_memories["results"])
In
memo/memory/main.py
, the memory search actually includes parallel searches in both vector storage and graph storage. The code returns:return {"results": original_memories, "relations": graph_entities}
However, here only original_memories from vector storage recall is handled, and the graph database entities (graph_entities) are not used in constructing the memory recall.
How should we handle the recall of entities from the graph database?
For instance, data structured as follows is not being utilized:
search_results.append({"source": item[0], "relationship": item[1], "target": item[2]})
Example: