使用LangChain的Neo4jGraph时APOC插件报错的解决方法咨询
问题:使用LangChain的Neo4jGraph时出现APOC插件缺失报错
我在Python项目中尝试使用langchain_community.graphs模块的Neo4jGraph类与Neo4j数据库交互,代码如下:
from langchain.chains import GraphCypherQAChain from langchain_community.graphs import Neo4jGraph from langchain_openai import ChatOpenAI enhanced_graph = Neo4jGraph( url="bolt://localhost:7687", username="neo4j", password="password", enhanced_schema=True, ) print(enhanced_graph.schema) chain = GraphCypherQAChain.from_llm( ChatOpenAI(temperature=0), graph=enhanced_graph, verbose=True ) chain.invoke({"query": "Who is Bob?"})
运行代码后出现以下报错:
ValueError: Could not use APOC procedures. Please ensure the APOC plugin is installed in Neo4j and that 'apoc.meta.data()' is allowed in Neo4j configuration 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.}
解决方案
1. 安装APOC插件
- Neo4j桌面版:找到目标数据库实例,点击「Plugins」标签,找到APOC插件后点击「Install」,安装完成后重启数据库。
- 服务器部署版:下载与Neo4j版本匹配的APOC插件包,将其放入Neo4j安装目录的
plugins文件夹,重启Neo4j服务。
2. 配置Neo4j允许APOC过程
打开Neo4j配置文件neo4j.conf,添加或修改以下配置项:
dbms.security.procedures.unrestricted=apoc.* dbms.security.procedures.allowlist=apoc.meta.data
保存配置后重启Neo4j服务。
3. 临时规避方案(无需安装APOC)
如果暂时不需要增强schema功能,可以初始化Neo4jGraph时将enhanced_schema设为False,LangChain会使用基础schema获取逻辑,不依赖APOC:
enhanced_graph = Neo4jGraph( url="bolt://localhost:7687", username="neo4j", password="password", enhanced_schema=False, )
内容的提问来源于stack exchange,提问作者Dmitri Galkin
相关产品推荐
相关产品推荐

