I am a beginner in learning about Neo4J and Cypher queries, and following this GitHub for building a Hybrid RAG using knowledge graphs. I have added a graph to my Neo4j workspace using Cypher query. The example of commands is shown below:
MERGE (nizhny_novgorod:birthPlace {id: "Nizhny Novgorod"})
MERGE (large_language_models_like_chatgpt:characteristics {id: "large language models like ChatGPT"})
MERGE (richard_zemel:person {id: "Richard Zemel"})
MERGE (mixtures_of_experts:invention {id: "mixtures of experts"})
MERGE (december_6_1947:date {id: "December 6, 1947"})
MERGE (nobel_prize_in_physics:award {id: "Nobel Prize in Physics"})
MERGE (geoffrey_hinton)-[:bornIn]->(london)
MERGE (geoffrey_hinton)-[:bornAt]->(december_6_1947)
MERGE (geoffrey_hinton)-[:worksAt]->(university_of_toronto)
MERGE (geoffrey_hinton)-[:hasNationality]->(britishcanadian)
MERGE (geoffrey_hinton)-[:hasRole]->(cognitive_psychologist_and_computer_scientist)
MERGE (geoffrey_hinton)-[:coAuthored]->(david_rumelhart)
MERGE (geoffrey_hinton)-[:coAuthored]->(ronald_j_williams)
And the problem is that the __Entity__
is empty, and it does not return any node, when I run the MATCH (n:__Entity__) RETURN n LIMIT 25;
command.
I faced with this problem when trying to find neighbor nodes while retrieving the knowledge graph using the below function.
# Fulltext index query
def structured_retriever(question: str) -> str:
"""
Or Graph Retriever
Collects the neighborhood of entities mentioned in the question
"""
result = ""
entities = entity_chain.invoke({"question": question})
print(f"Extracted entities: {entities.names}")
for entity in entities.names:
query = generate_full_text_query(entity)
print(f"Generated query: {query}")
response = graph.query(
"""CALL db.index.fulltext.queryNodes('entity', $query, {limit:2})
YIELD node, score
CALL {
WITH node
MATCH (node)-[r]->(neighbor)
RETURN node.id + ' - ' + type(r) + ' -> ' + neighbor.id AS output
UNION ALL
WITH node
MATCH (node)<-[r]-(neighbor)
RETURN neighbor.id + ' - ' + type(r) + ' -> ' + node.id AS output
}
RETURN output LIMIT 50
""",
{"query": query},
)
print(f"Query response: {response}")
if response:
result += "\n".join([el['output'] for el in response])
else:
print(f"No results found for entity: {entity}")
return result
The above query does not return anything. For example, for the below question:
print(structured_retriever("Where was Geoffrey Hinton born"))
Output:
Extracted entities: ['Geoffrey Hinton']
Generated query: Geoffrey~2 AND Hinton~2
Query response: []
No results found for entity: Geoffrey Hinton