From 043db73ee6c06a9338112b58056d1c2bb3c370f0 Mon Sep 17 00:00:00 2001 From: jp170na Date: Sun, 11 Oct 2026 00:21:47 +0200 Subject: [PATCH] Refactor GraphRAG into standalone tool --- Dockerfile | 1 + tools/__init__.py | 0 tools/graphrag/__init__.py | 0 {scripts => tools/graphrag}/build_graphrag.py | 6 +++--- .../graphrag/evaluation}/graphrag_questions.json | 0 {scripts => tools/graphrag}/graph_db.py | 0 {scripts => tools/graphrag}/graph_search.py | 2 +- {scripts => tools/graphrag}/graphrag.py | 0 {scripts => tools/graphrag}/neo4j_smoke.py | 2 +- tools/graphrag/tests/__init__.py | 0 {test => tools/graphrag/tests}/test_graph_search.py | 2 +- {test => tools/graphrag/tests}/test_graphrag.py | 2 +- 12 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 tools/__init__.py create mode 100644 tools/graphrag/__init__.py rename {scripts => tools/graphrag}/build_graphrag.py (99%) rename {evaluation/json_files => tools/graphrag/evaluation}/graphrag_questions.json (100%) rename {scripts => tools/graphrag}/graph_db.py (100%) rename {scripts => tools/graphrag}/graph_search.py (99%) rename {scripts => tools/graphrag}/graphrag.py (100%) rename {scripts => tools/graphrag}/neo4j_smoke.py (82%) create mode 100644 tools/graphrag/tests/__init__.py rename {test => tools/graphrag/tests}/test_graph_search.py (99%) rename {test => tools/graphrag/tests}/test_graphrag.py (99%) diff --git a/Dockerfile b/Dockerfile index e026b59..b214c1d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,6 +26,7 @@ RUN python -m pip install --no-cache-dir \ COPY app ./app COPY scripts ./scripts +COPY tools ./tools RUN mkdir -p data diff --git a/tools/__init__.py b/tools/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tools/graphrag/__init__.py b/tools/graphrag/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scripts/build_graphrag.py b/tools/graphrag/build_graphrag.py similarity index 99% rename from scripts/build_graphrag.py rename to tools/graphrag/build_graphrag.py index af12487..29896f3 100644 --- a/scripts/build_graphrag.py +++ b/tools/graphrag/build_graphrag.py @@ -5,11 +5,11 @@ import json from pathlib import Path from typing import Any -from scripts.graph_db import ( +from .graph_db import ( create_neo4j_driver, get_neo4j_settings, ) -from scripts.graphrag import ( +from .graphrag import ( GRAPH_SCOPE, build_graph_payload, ) @@ -17,7 +17,7 @@ from scripts.graphrag import ( PROJECT_ROOT = Path( __file__ -).resolve().parents[1] +).resolve().parents[2] DOCUMENTS_FILE = ( PROJECT_ROOT diff --git a/evaluation/json_files/graphrag_questions.json b/tools/graphrag/evaluation/graphrag_questions.json similarity index 100% rename from evaluation/json_files/graphrag_questions.json rename to tools/graphrag/evaluation/graphrag_questions.json diff --git a/scripts/graph_db.py b/tools/graphrag/graph_db.py similarity index 100% rename from scripts/graph_db.py rename to tools/graphrag/graph_db.py diff --git a/scripts/graph_search.py b/tools/graphrag/graph_search.py similarity index 99% rename from scripts/graph_search.py rename to tools/graphrag/graph_search.py index a6bd3a1..72da71e 100644 --- a/scripts/graph_search.py +++ b/tools/graphrag/graph_search.py @@ -1283,7 +1283,7 @@ def search_graph( limit: int = DEFAULT_LIMIT, max_entities: int = DEFAULT_MAX_ENTITIES, ) -> dict[str, Any]: - from scripts.graph_db import ( + from .graph_db import ( create_neo4j_driver, get_neo4j_settings, ) diff --git a/scripts/graphrag.py b/tools/graphrag/graphrag.py similarity index 100% rename from scripts/graphrag.py rename to tools/graphrag/graphrag.py diff --git a/scripts/neo4j_smoke.py b/tools/graphrag/neo4j_smoke.py similarity index 82% rename from scripts/neo4j_smoke.py rename to tools/graphrag/neo4j_smoke.py index 41ae918..aad2b7b 100644 --- a/scripts/neo4j_smoke.py +++ b/tools/graphrag/neo4j_smoke.py @@ -1,4 +1,4 @@ -from scripts.graph_db import verify_neo4j_connection +from .graph_db import verify_neo4j_connection def main() -> None: diff --git a/tools/graphrag/tests/__init__.py b/tools/graphrag/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_graph_search.py b/tools/graphrag/tests/test_graph_search.py similarity index 99% rename from test/test_graph_search.py rename to tools/graphrag/tests/test_graph_search.py index fe241c6..44c7bc7 100644 --- a/test/test_graph_search.py +++ b/tools/graphrag/tests/test_graph_search.py @@ -4,7 +4,7 @@ from typing import Any import pytest -import scripts.graph_search as graph_search +import tools.graphrag.graph_search as graph_search class FakeSession: diff --git a/test/test_graphrag.py b/tools/graphrag/tests/test_graphrag.py similarity index 99% rename from test/test_graphrag.py rename to tools/graphrag/tests/test_graphrag.py index d03a23d..0d1c3d3 100644 --- a/test/test_graphrag.py +++ b/tools/graphrag/tests/test_graphrag.py @@ -1,6 +1,6 @@ from __future__ import annotations -from scripts.graphrag import ( +from tools.graphrag.graphrag import ( build_graph_payload, extract_explicit_proposal_title, extract_works,