neo4j-labs / llm-graph-builder

Neo4j graph construction from unstructured data using LLMs
https://neo4j.com/labs/genai-ecosystem/llm-graph-builder/
Apache License 2.0
2.07k stars 309 forks source link

The graph database does not store any nodes and relationships #598

Open Kain-90 opened 1 month ago

Kain-90 commented 1 month ago

I am using the custom Tongyi llm from langchain_community.chat_models.tongyi import ChatTongyi

I found that there are nodes and relationships in the model response in langchain smith but there is no related data in the neo4j, do I need to define the schema manually every time, if so, how to set up automatic extraction and then store it?

image
{
"nodes": [
{
"id": "山竹白鸽汤",
"type": "Recipe"
},
{
"id": "山药",
"type": "Ingredient",
"description": "用于改善皮肤"
},
{
"id": "玉竹",
"type": "Ingredient",
"description": "用于解毒和改善皮肤"
},
{
"id": "净白鸽",
"type": "Ingredient",
"description": "主料,一只"
},
{
"id": "精盐",
"type": "Ingredient",
"description": "调料"
},
{
"id": "味精",
"type": "Ingredient",
"description": "调料"
},
{
"id": "葱段",
"type": "Ingredient",
"description": "调料"
},
{
"id": "姜片",
"type": "Ingredient",
"description": "调料"
},
{
"id": "香油",
"type": "Ingredient",
"description": "调料"
}
],
"relationships": [
{
"source_node_id": "山竹白鸽汤",
"source_node_type": "Recipe",
"target_node_id": "山药",
"target_node_type": "Ingredient",
"type": "USES"
},
{
"source_node_id": "山竹白鸽汤",
"source_node_type": "Recipe",
"target_node_id": "玉竹",
"target_node_type": "Ingredient",
"type": "USES"
},
{
"source_node_id": "山竹白鸽汤",
"source_node_type": "Recipe",
"target_node_id": "净白鸽",
"target_node_type": "Ingredient",
"type": "MADE_OF"
},
{
"source_node_id": "山竹白鸽汤",
"source_node_type": "Recipe",
"target_node_id": "精盐",
"target_node_type": "Ingredient",
"type": "USES"
},
{
"source_node_id": "山竹白鸽汤",
"source_node_type": "Recipe",
"target_node_id": "味精",
"target_node_type": "Ingredient",
"type": "USES"
},
{
"source_node_id": "山竹白鸽汤",
"source_node_type": "Recipe",
"target_node_id": "葱段",
"target_node_type": "Ingredient",
"type": "USES"
},
{
"source_node_id": "山竹白鸽汤",
"source_node_type": "Recipe",
"target_node_id": "姜片",
"target_node_type": "Ingredient",
"type": "USES"
},
{
"source_node_id": "山竹白鸽汤",
"source_node_type": "Recipe",
"target_node_id": "香油",
"target_node_type": "Ingredient",
"type": "USES"
}
]
}
2024-07-22 13:41:00,912 - Exception in post_processing tasks: {code: Neo.ClientError.Procedure.ProcedureCallFailed} {message: Failed to invoke procedure `db.index.vector.queryNodes`: Caused by: java.lang.IllegalArgumentException: Index query vector has 1024 dimensions, but indexed vectors have 384.}
Traceback (most recent call last):
  File "/Users/kain/cct_project/llm-graph-builder/backend/score.py", line 257, in post_processing
    await asyncio.to_thread(update_graph, graph)
  File "/Users/kain/.pyenv/versions/3.10.13/lib/python3.10/asyncio/threads.py", line 25, in to_thread
    return await loop.run_in_executor(None, func_call)
  File "/Users/kain/.pyenv/versions/3.10.13/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/kain/cct_project/llm-graph-builder/backend/src/main.py", line 428, in update_graph
    graph_DB_dataAccess.update_KNN_graph()
  File "/Users/kain/cct_project/llm-graph-builder/backend/src/graphDB_dataAccess.py", line 134, in update_KNN_graph
    self.graph.query("""MATCH (c:Chunk)
  File "/Users/kain/cct_project/llm-graph-builder/backend/venv/lib/python3.10/site-packages/langchain_community/graphs/neo4j_graph.py", line 419, in query
    data = session.run(Query(text=query, timeout=self.timeout), params)
  File "/Users/kain/cct_project/llm-graph-builder/backend/venv/lib/python3.10/site-packages/neo4j/_sync/work/session.py", line 314, in run
    self._auto_result._run(
  File "/Users/kain/cct_project/llm-graph-builder/backend/venv/lib/python3.10/site-packages/neo4j/_sync/work/result.py", line 221, in _run
    self._attach()
  File "/Users/kain/cct_project/llm-graph-builder/backend/venv/lib/python3.10/site-packages/neo4j/_sync/work/result.py", line 409, in _attach
    self._connection.fetch_message()
  File "/Users/kain/cct_project/llm-graph-builder/backend/venv/lib/python3.10/site-packages/neo4j/_sync/io/_common.py", line 178, in inner
    func(*args, **kwargs)
  File "/Users/kain/cct_project/llm-graph-builder/backend/venv/lib/python3.10/site-packages/neo4j/_sync/io/_bolt.py", line 855, in fetch_message
    res = self._process_message(tag, fields)
  File "/Users/kain/cct_project/llm-graph-builder/backend/venv/lib/python3.10/site-packages/neo4j/_sync/io/_bolt5.py", line 370, in _process_message
    response.on_failure(summary_metadata or {})
  File "/Users/kain/cct_project/llm-graph-builder/backend/venv/lib/python3.10/site-packages/neo4j/_sync/io/_common.py", line 245, in on_failure
    raise Neo4jError.hydrate(**metadata)
neo4j.exceptions.ClientError: {code: Neo.ClientError.Procedure.ProcedureCallFailed} {message: Failed to invoke procedure `db.index.vector.queryNodes`: Caused by: java.lang.IllegalArgumentException: Index query vector has 1024 dimensions, but indexed vectors have 384.}
2024-07-22 13:41:01,137 - closing connection for post_processing api
karanchellani commented 1 month ago

@Kain-90 we are workig on fixing this, you should see this in DEV soon