3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PythonでNeo4Jに接続しようとしたら怒られた

Posted at

事象

GraphRAGなどというものに挑戦してみようと思い、pythonからneo4jに接続を試みた

url = "bolt://172.18.0.1:7687"
username ="hoge"
password = "fuga"
graph = Neo4jGraph(
    url=url,
    username=username,
    password=password
)

結果、以下のようなエラーが発生

Traceback (most recent call last):
  File "/root/.pyenv/versions/3.11.0/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 584, in _run_script
    exec(code, module.__dict__)
  File "/home/volume/knowledge-graph_rag/langchain-examples/all-in-one/pages/7_Graph_RAG.py", line 19, in <module>
    graph = Neo4jGraph(
            ^^^^^^^^^^^
  File "/root/.pyenv/versions/3.11.0/lib/python3.11/site-packages/langchain_community/graphs/neo4j_graph.py", line 367, in __init__
    raise ValueError(
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のDockerCompose

services:
    neo4j:
      image: neo4j:latest
      tty: true
      ports:
        - 7474:7474
        - 7687:7687
      volumes:
        - ./neo4j/data:/data
        - ./neo4j/logs:/logs
        - ./neo4j/conf:/conf
      environment:
        - NEO4J_AUTH=none

対応策

apocプラグインを有効化する
具体的には以下を行うことで無事解決した

プラグインのインストール

以下からallinのjarを取得してpluginディレクトリに格納

設定ファイル修正

neo4j.confに以下を追記

dbms.security.procedures.unrestricted=gds.*,apoc.*

docker-compose.yml修正

修正後

services:
    neo4j:
      image: neo4j:latest
      tty: true
      ports:
        - 7474:7474
        - 7687:7687
      volumes:
        - ./neo4j/data:/data
        - ./neo4j/logs:/logs
        - ./neo4j/conf:/conf
        - ./neo4j/plugin:/plugin # この行追加
      environment:
        - NEO4J_AUTH=none
        - NEO4JLABS_PLUGINS=["apoc"] # この行追加

ドキュメントを見ると、環境変数として追記したものがあればプラグインの物理的格納はいらないのでは?という気もするが確かめてはいない

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?