Skip to content

Phase 2: Graph RAG knowledge base with Neo4j#1

Closed
RahulModugula wants to merge 0 commit into
mainfrom
phase/2-graph-rag
Closed

Phase 2: Graph RAG knowledge base with Neo4j#1
RahulModugula wants to merge 0 commit into
mainfrom
phase/2-graph-rag

Conversation

@RahulModugula

Copy link
Copy Markdown
Owner

Summary

  • Adds a persistent Neo4j knowledge graph that grows across research sessions
  • Extracts entities and relationships from ingested chunks via LLM (incremental, background task)
  • Adds graph-based retrieval (graph_search.py) as a third retrieval source alongside dense + BM25
  • Researcher agent gains a query_knowledge_graph tool; writer persists session answers back to the graph

Key files

  • backend/app/graph/ — new package: extractor.py, store.py, models.py
  • backend/app/retrieval/graph_search.py — entity-aware query → Neo4j subgraph → virtual chunks
  • backend/app/services/document_service.py — background graph extraction after embedding
  • Migrations: 003_research_sessions.py, 004_graph_metadata.py
  • docker-compose.yml — Neo4j 5 community service added

Test plan

  • Ingest a document → verify entities in Neo4j browser (port 7474)
  • Run a research query → verify graph context in retrieved chunks
  • Run a related query in a new session → verify prior session knowledge is retrieved
  • Neo4j unset → system falls back to vector-only gracefully
  • All existing tests still pass

Copilot AI review requested due to automatic review settings March 24, 2026 04:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.md outlining 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.

Comment thread plans/phase-2-graph-rag.md Outdated
Comment on lines +19 to +25
## 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

Copilot AI Mar 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment thread plans/phase-2-graph-rag.md Outdated
Comment on lines +13 to +17
## 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`

Copilot AI Mar 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread plans/phase-2-graph-rag.md Outdated
Comment on lines +33 to +36
## Tests

- `backend/tests/test_graph_extractor.py` — Mock LLM extraction
- `backend/tests/test_graph_store.py` — Neo4j operations with test container

Copilot AI Mar 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread plans/phase-2-graph-rag.md Outdated
Comment on lines +5 to +11
## 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` |

Copilot AI Mar 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants