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 Database Entities Not Utilized in Recall within #1991

Open
pihang opened this issue Oct 29, 2024 · 1 comment
Open

Graph Database Entities Not Utilized in Recall within #1991

pihang opened this issue Oct 29, 2024 · 1 comment
Assignees

Comments

@pihang
Copy link

pihang commented Oct 29, 2024

🐛 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:

{
  "memories": [...],
  "entities": [
    {"source": "peter", "relation": "identity", "destination": "spiderman"}
  ]
}
@Cirr0e
Copy link

Cirr0e commented Nov 20, 2024

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:

  1. Preserves existing vector memory retrieval
  2. Adds graph entity information if available
  3. Creates a comprehensive context string
  4. Provides optional fallback if no graph entities exist

Recommended modifications in memo/proxy/main.py:

# Replace existing memory text generation
memories_text = enhanced_memory_recall(relevant_memories)

Rationale and References:

  • Based on the Mem0.ai documentation on Graph Memory integration [Citation: Mem0.ai Documentation]
  • Solves the issue of unused graph database entities
  • Provides a flexible approach to incorporating relational context

Additional Recommendations:

  1. Ensure your Neo4j configuration is up to date (version v1.1+)
  2. Validate graph entity extraction in your memory creation process
  3. Consider adding logging to track graph entity utilization

Potential Enhancement:
For more advanced use cases, you might want to develop a more sophisticated entity integration strategy that can:

  • Weight graph entity importance
  • Handle more complex relationship types
  • Provide more nuanced context generation

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

No branches or pull requests

3 participants