Phase 2: Graph RAG knowledge base with Neo4j#1
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a Phase 2 planning document describing a Graph RAG architecture using Neo4j (persistent cross-session knowledge graph + graph-based retrieval) intended to complement the existing vector + BM25 retrieval stack.
Changes:
- Adds
plans/phase-2-graph-rag.mdoutlining the proposed Graph RAG/Neo4j design, integration points, and verification steps.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ## Integration Points | ||
|
|
||
| - `backend/app/services/document_service.py` — Queue graph extraction as background task after embedding | ||
| - `backend/app/main.py` — Init Neo4j in lifespan → `app.state.graph_store` | ||
| - New: `backend/app/retrieval/graph_search.py` — Extract entities from query via LLM → query Neo4j → return as virtual chunks | ||
| - `backend/app/retrieval/hybrid.py` — Add `include_graph: bool` param | ||
| - `backend/app/agents/researcher.py` — Add `query_knowledge_graph` as second tool |
There was a problem hiding this comment.
The “Integration Points” list mentions new/updated modules (backend/app/retrieval/graph_search.py, include_graph param in backend/app/retrieval/hybrid.py, and agent/tooling changes), but those changes aren’t present in the current branch. If this PR is intended to implement Graph RAG, please include the referenced code changes (or revise the plan/PR description to reflect the actual scope).
| ## Infrastructure Changes | ||
|
|
||
| - `docker-compose.yml` — Add `neo4j:5-community` service (ports 7474, 7687, APOC plugin) | ||
| - `backend/app/config.py` — Add `neo4j_uri`, `neo4j_user`, `neo4j_password` (all optional — vector-only fallback if unset) | ||
| - New deps: `neo4j>=5.0.0`, `langchain-neo4j>=0.3.0` |
There was a problem hiding this comment.
This plan describes concrete repo changes (Neo4j service in docker-compose.yml, new Python deps, and Alembic migrations 003_*/004_*), but none of those artifacts exist in this branch (no neo4j service in docker-compose.yml, no neo4j/langchain-neo4j deps in backend/pyproject.toml, and no 003/004 migration files under backend/alembic/versions). Either include the corresponding code/config changes in this PR or update the PR description/plan so it matches what’s actually being delivered here.
| ## Tests | ||
|
|
||
| - `backend/tests/test_graph_extractor.py` — Mock LLM extraction | ||
| - `backend/tests/test_graph_store.py` — Neo4j operations with test container |
There was a problem hiding this comment.
This section lists new tests (backend/tests/test_graph_extractor.py, backend/tests/test_graph_store.py), but those files aren’t present in the current branch. Either add the tests as part of this PR or adjust the plan/PR scope so it doesn’t claim tests that aren’t being introduced.
| ## New Package: `backend/app/graph/` | ||
|
|
||
| | File | Purpose | | ||
| |------|---------| | ||
| | `extractor.py` | `LLMGraphTransformer` extracts entities + relationships from chunks. Incremental — only processes chunks not yet extracted. | | ||
| | `store.py` | Neo4j wrapper: `add_entities_and_relationships()`, `query_subgraph(entities, depth)`, `search_entities(query)`, `get_entity_context(entity)` | | ||
| | `models.py` | Pydantic models: `Entity`, `Relationship`, `Subgraph` | |
There was a problem hiding this comment.
This plan calls out a new backend/app/graph/ package (extractor.py, store.py, models.py), but that directory/files aren’t present in the current branch. If this PR is meant to deliver Phase 2 functionality, please include the package (or update the PR/plan scope accordingly).
55f48de to
ac3518a
Compare
Summary
graph_search.py) as a third retrieval source alongside dense + BM25query_knowledge_graphtool; writer persists session answers back to the graphKey files
backend/app/graph/— new package:extractor.py,store.py,models.pybackend/app/retrieval/graph_search.py— entity-aware query → Neo4j subgraph → virtual chunksbackend/app/services/document_service.py— background graph extraction after embedding003_research_sessions.py,004_graph_metadata.pydocker-compose.yml— Neo4j 5 community service addedTest plan