-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
how can i query from non-empty graph which is created manully? #2040
Comments
Hi there! I understand you're having trouble querying a manually created graph in Mem0 with Neo4j, and your searches are returning empty results. Let me help you troubleshoot this. Based on the documentation and the error context, here are some specific recommendations:
The key is ensuring you've: Would you mind sharing your exact code for adding memories and searching? That would help me diagnose the specific issue more precisely. |
Above all is all my code. I need to search something from the neo4j graph which is created manully before Memory is initialized , which means that graph is not build by m.add(). In other words, Can i directly search from a graph not build by mem0? |
Hi there! I understand you want to search a manually created Neo4j graph that wasn't built using Mem0's standard m.add() method. Based on the documentation and your specific requirement, here are a few approaches you can consider:
from mem0 import Memory
from neo4j import GraphDatabase
config = {
"graph_store": {
"provider": "neo4j",
"config": {
"url": "bolt://localhost:7687",
"username": "neo4j",
"password": "neo4j123"
}
},
"version": "v1.1"
}
m = Memory.from_config(config_dict=config)
# Direct Neo4j Driver Access
neo4j_driver = GraphDatabase.driver(
"bolt://localhost:7687",
auth=("neo4j", "neo4j123")
)
def custom_graph_search(query):
with neo4j_driver.session() as session:
result = session.run(query)
return [record for record in result]
# Example Cypher query
results = custom_graph_search("MATCH (n) RETURN n LIMIT 10")
config = {
"graph_store": {
"provider": "neo4j",
"config": {
"url": "bolt://localhost:7687",
"username": "neo4j",
"password": "neo4j123",
"custom_prompt": "Extract entities specifically from my pre-existing graph structure"
}
},
"version": "v1.1"
} Key Recommendations: Potential Risks:
Would you be willing to share more details about:
This will help me provide a more tailored solution! 🕵️♂️🔍 |
Hi there! Thanks for providing those additional details about your graph structure. I can help you query your manually created graph for both the long_press operations and city searches. For your specific queries, here's how you can approach this using direct Neo4j queries since you're working with a custom graph structure:
from mem0 import Memory
from neo4j import GraphDatabase
config = {
"graph_store": {
"provider": "neo4j",
"config": {
"url": "bolt://localhost:7687",
"username": "neo4j",
"password": "neo4j123"
}
},
"version": "v1.1"
}
# Initialize Neo4j driver
driver = GraphDatabase.driver(
"bolt://localhost:7687",
auth=("neo4j", "neo4j123")
)
def find_long_pressable_elements():
with driver.session() as session:
# Query elements where operation_long_press property exists and is not null/empty
query = """
MATCH (n:element_node)
WHERE n.operation_long_press IS NOT NULL
AND n.operation_long_press <> ''
RETURN n.name, n.operation_long_press, n.page_name
"""
result = session.run(query)
return [dict(record["n"]) for record in result]
# For city search, assuming cities might be in text or name properties:
def search_city(city_name):
with driver.session() as session:
query = """
MATCH (n:element_node)
WHERE n.text CONTAINS $city_name
OR n.name CONTAINS $city_name
RETURN n
"""
result = session.run(query, city_name=city_name)
return [dict(record["n"]) for record in result] To use these functions: # Find long-pressable elements
long_press_elements = find_long_pressable_elements()
print("Elements that can be long-pressed:", long_press_elements)
# Search for a specific city
city_results = search_city("New York")
print("City search results:", city_results) Important notes:
Potential risks to be aware of:
Would you like me to:
Let me know if you need any clarification or have questions about implementing these queries! |
🐛 Describe the bug
I creat a graph mannully. Then I want to use mem0 to search from this non-empty graph. But result in empty.
"graph_store": {
"provider": "neo4j",
"config": {
"url": "bolt://localhost:7687",
"username": "neo4j",
"password": "neo4j123"
}
},
"version": "v1.1"
The text was updated successfully, but these errors were encountered: