问题
运行代码:
import os
from dotenv import load_dotenv
from langchain_neo4j import Neo4jGraph
from langchain_core.documents import Document
from langchain_experimental.graph_transformers import LLMGraphTransformer
from langchain_openai import ChatOpenAI
from pydantic import SecretStr
os.environ['NEO4J_URI'] = "bolt://127.0.0.1:7687"
os.environ['NEO4J_USERNAME'] = "neo4j"
os.environ['NEO4J_PASSWORD'] = "meiyanzhi"
# 加载环境变量
load_dotenv()
api_key = os.getenv("QWEN2.5_APT_KEY")
graph = Neo4jGraph(refresh_schema=False)
llm = ChatOpenAI(
base_url="https://api.ppinfra.com/v3/openai",
model="qwen/qwen2.5-32b-instruct",
api_key=SecretStr(api_key)
)
llm_transformer = LLMGraphTransformer(llm=llm)
text = """
Marie Curie, born in 1867, was a Polish and naturalised-French physicist and chemist who conducted pioneering research on radioactivity.
She was the first woman to win a Nobel Prize, the first person to win a Nobel Prize twice, and the only person to win a Nobel Prize in two scientific fields.
Her husband, Pierre Curie, was a co-winner of her first Nobel Prize, making them the first-ever married couple to win the Nobel Prize and launching the Curie family legacy of five Nobel Prizes.
She was, in 1906, the first woman to become a professor at the University of Paris.
"""
documents = [Document(page_content=text)]
graph_documents = llm_transformer.convert_to_graph_documents(documents)
print(f"Nodes:{graph_documents[0].nodes}")
print(f"Relationships:{graph_documents[0].relationships}")
# 将生成的图数据写入 Neo4j
graph.add_graph_documents(graph_documents, baseEntityLabel=True)
报错信息
pycharm运行结果:
Nodes:[Node(id='Marie_Curie', type='Person', properties={}), Node(id='1867', type='Year', properties={}), Node(id='Polish', type='Nationality', properties={}), Node(id='French', type='Nationality', properties={}), Node(id='Physicist', type='Occupation', properties={}), Node(id='Chemist', type='Occupation', properties={}), Node(id='Radioactivity', type='Research_field', properties={}), Node(id='Nobel_Prize', type='Award', properties={}), Node(id='University_Of_Paris', type='Institution', properties={}), Node(id='Professor', type='Occupation', properties={}), Node(id='Pierre_Curie', type='Person', properties={})]
Relationships:[Relationship(source=Node(id='Marie_Curie', type='Person', properties={}), target=Node(id='1867', type='Year', properties={}), type='BORN_IN_YEAR', properties={}), Relationship(source=Node(id='Marie_Curie', type='Person', properties={}), target=Node(id='Polish', type='Nationality', properties={}), type='HAS_NATIONALITY', properties={}), Relationship(source=Node(id='Marie_Curie', type='Person', properties={}), target=Node(id='French', type='Nationality', properties={}), type='HAS_NATIONALITY', properties={}), Relationship(source=Node(id='Marie_Curie', type='Person', properties={}), target=Node(id='Physicist', type='Occupation', properties={}), type='HAS_OCCUPATION', properties={}), Relationship(source=Node(id='Marie_Curie', type='Person', properties={}), target=Node(id='Chemist', type='Occupation', properties={}), type='HAS_OCCUPATION', properties={}), Relationship(source=Node(id='Marie_Curie', type='Person', properties={}), target=Node(id='Radioactivity', type='Research_field', properties={}), type='CONDUCTED_RESEARCH_ON', properties={}), Relationship(source=Node(id='Marie_Curie', type='Person', properties={}), target=Node(id='Nobel_Prize', type='Award', properties={}), type='WON_AWARD', properties={}), Relationship(source=Node(id='Marie_Curie', type='Person', properties={}), target=Node(id='Nobel_Prize', type='Award', properties={}), type='WON_AWARD_TWICE', properties={}), Relationship(source=Node(id='Marie_Curie', type='Person', properties={}), target=Node(id='Nobel_Prize', type='Award', properties={}), type='WON_AWARD_IN_TWO_FIELDS', properties={}), Relationship(source=Node(id='Marie_Curie', type='Person', properties={}), target=Node(id='University_Of_Paris', type='Institution', properties={}), type='WORKED_AT', properties={}), Relationship(source=Node(id='Marie_Curie', type='Person', properties={}), target=Node(id='Professor', type='Occupation', properties={}), type='HAS_OCCUPATION', properties={}), Relationship(source=Node(id='Pierre_Curie', type='Person', properties={}), target=Node(id='Marie_Curie', type='Person', properties={}), type='SPOUSE_OF', properties={}), Relationship(source=Node(id='Pierre_Curie', type='Person', properties={}), target=Node(id='Nobel_Prize', type='Award', properties={}), type='WON_AWARD', properties={})]
Traceback (most recent call last):
File "/Users/xmly/PycharmProjects/ai_demo/app/graph/neo4j_graph.py", line 40, in <module>
graph.add_graph_documents(graph_documents, baseEntityLabel=True)
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/langchain_neo4j/graphs/neo4j_graph.py", line 335, in add_graph_documents
self.refresh_schema() # Refresh constraint information
^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/langchain_neo4j/graphs/neo4j_graph.py", line 278, in refresh_schema
self.structured_schema = get_structured_schema(
^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/neo4j_graphrag/schema.py", line 289, in get_structured_schema
for data in query_database(
^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/neo4j_graphrag/schema.py", line 164, in query_database
data = driver.execute_query(
^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/neo4j/_sync/driver.py", line 970, in execute_query
return session._run_transaction(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/neo4j/_sync/work/session.py", line 583, in _run_transaction
result = transaction_function(tx, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/neo4j/_work/query.py", line 144, in wrapped
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/neo4j/_sync/driver.py", line 1306, in _work
res = tx.run(query, parameters)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/neo4j/_sync/work/transaction.py", line 206, in run
result._tx_ready_run(query, parameters)
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/neo4j/_sync/work/result.py", line 177, in _tx_ready_run
self._run(query, parameters, None, None, None, None, None, None)
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/neo4j/_sync/work/result.py", line 236, in _run
self._attach()
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/neo4j/_sync/work/result.py", line 430, in _attach
self._connection.fetch_message()
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/neo4j/_sync/io/_common.py", line 184, in inner
func(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/neo4j/_sync/io/_bolt.py", line 864, in fetch_message
res = self._process_message(tag, fields)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/neo4j/_sync/io/_bolt5.py", line 500, in _process_message
response.on_failure(summary_metadata or {})
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/neo4j/_sync/io/_common.py", line 254, in on_failure
raise self._hydrate_error(metadata)
neo4j.exceptions.ClientError: {code: Neo.ClientError.Procedure.ProcedureNotFound} {message: There is no procedure with the name `apoc.meta.data` registered for this database instance. Please ensure you've spelled the procedure name correctly and that the procedure is properly deployed.}
环境
neo4j 4.4.42
apoc文件:官网下载的apoc-4.4.0.1-all.jar文件
java 11
终端执行:
neo4j console --verbose
结果:
Starting Neo4j.
Executing command line: /Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home/bin/java -cp /Users/xmly/Documents/neo4j/neo4j-community-4.4.42/plugins/*:/Users/xmly/Documents/neo4j/neo4j-community-4.4.42/conf/*:/Users/xmly/Documents/neo4j/neo4j-community-4.4.42/lib/* -XX:+UseG1GC -XX:-OmitStackTraceInFastThrow -XX:+AlwaysPreTouch -XX:+UnlockExperimentalVMOptions -XX:+TrustFinalNonStaticFields -XX:+DisableExplicitGC -XX:MaxInlineLevel=15 -XX:-UseBiasedLocking -Djdk.nio.maxCachedBufferSize=262144 -Dio.netty.tryReflectionSetAccessible=true -Djdk.tls.ephemeralDHKeySize=2048 -Djdk.tls.rejectClientInitiatedRenegotiation=true -XX:FlightRecorderOptions=stackdepth=256 -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -Dlog4j2.disable.jmx=true -Dfile.encoding=UTF-8 org.neo4j.server.CommunityEntryPoint --home-dir=/Users/xmly/Documents/neo4j/neo4j-community-4.4.42 --config-dir=/Users/xmly/Documents/neo4j/neo4j-community-4.4.42/conf
2025-05-08 09:05:35.017+0000 INFO Starting...
2025-05-08 09:05:35.973+0000 INFO This instance is ServerId{2265cb2f} (2265cb2f-d42b-4405-bb5f-f7973d1ebdf4)
2025-05-08 09:05:38.041+0000 INFO ======== Neo4j 4.4.42 ========
2025-05-08 09:05:49.303+0000 ERROR Failed to start Neo4j on localhost:7474.
java.lang.RuntimeException: Error starting Neo4j database server at /Users/xmly/Documents/neo4j/neo4j-community-4.4.42/data/databases
at org.neo4j.graphdb.facade.DatabaseManagementServiceFactory.startDatabaseServer(DatabaseManagementServiceFactory.java:227) ~[neo4j-4.4.42.jar:4.4.42]
at org.neo4j.graphdb.facade.DatabaseManagementServiceFactory.build(DatabaseManagementServiceFactory.java:180) ~[neo4j-4.4.42.jar:4.4.42]
at org.neo4j.server.CommunityBootstrapper.createNeo(CommunityBootstrapper.java:36) ~[neo4j-4.4.42.jar:4.4.42]
at org.neo4j.server.NeoBootstrapper.start(NeoBootstrapper.java:142) [neo4j-4.4.42.jar:4.4.42]
at org.neo4j.server.NeoBootstrapper.start(NeoBootstrapper.java:95) [neo4j-4.4.42.jar:4.4.42]
at org.neo4j.server.CommunityEntryPoint.main(CommunityEntryPoint.java:34) [neo4j-4.4.42.jar:4.4.42]
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.procedure.impl.GlobalProceduresRegistry@491f8831' was successfully initialized, but failed to start. Please see the attached cause exception "Some jar procedure files (apoc-4.4.0.1-all.jar) are invalid, see log for details.".
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:463) ~[neo4j-common-4.4.42.jar:4.4.42]
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:110) ~[neo4j-common-4.4.42.jar:4.4.42]
at org.neo4j.graphdb.facade.DatabaseManagementServiceFactory.startDatabaseServer(DatabaseManagementServiceFactory.java:218) ~[neo4j-4.4.42.jar:4.4.42]
... 5 more
Caused by: java.util.zip.ZipException: Some jar procedure files (apoc-4.4.0.1-all.jar) are invalid, see log for details.
at org.neo4j.procedure.impl.ProcedureJarLoader.loadProceduresFromDir(ProcedureJarLoader.java:83) ~[neo4j-procedure-4.4.42.jar:4.4.42]
at org.neo4j.procedure.impl.GlobalProceduresRegistry.start(GlobalProceduresRegistry.java:371) ~[neo4j-procedure-4.4.42.jar:4.4.42]
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:442) ~[neo4j-common-4.4.42.jar:4.4.42]
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:110) ~[neo4j-common-4.4.42.jar:4.4.42]
at org.neo4j.graphdb.facade.DatabaseManagementServiceFactory.startDatabaseServer(DatabaseManagementServiceFactory.java:218) ~[neo4j-4.4.42.jar:4.4.42]
... 5 more
2025-05-08 09:05:49.304+0000 INFO Neo4j Server shutdown initiated by request
2025-05-08 09:05:49.307+0000 INFO Stopped.
org.neo4j.server.startup.BootProcessFailureException: Unexpected process failure. See log for info.
at org.neo4j.server.startup.ProcessManager.run(ProcessManager.java:194)
at org.neo4j.server.startup.BootloaderOsAbstraction.console(BootloaderOsAbstraction.java:74)
at org.neo4j.server.startup.Bootloader.console(Bootloader.java:151)
at org.neo4j.server.startup.Neo4jCommand$Console.call(Neo4jCommand.java:56)
at org.neo4j.server.startup.Neo4jCommand$Console.call(Neo4jCommand.java:47)
at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
at picocli.CommandLine.access$1300(CommandLine.java:145)
at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2352)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2346)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2311)
at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
at picocli.CommandLine.execute(CommandLine.java:2078)
at org.neo4j.server.startup.Neo4jCommand.main(Neo4jCommand.java:166)
at org.neo4j.server.startup.Neo4jBoot.main(Neo4jBoot.java:31)