How prongs394/harry-potter-langgraph-rag works
This is a Harry Potter question-answering RAG service. A client sends a question to the FastAPI /chat endpoint, which invokes a LangGraph workflow: retrieve and rank passages, generate an answer with Ollama, and—if the answer is “I don't know”—rewrite the question once and retry. Offline, the notebook processes book PDFs, chunks the text, and prepares the persistent ChromaDB collection used at runtime. The source excerpts show the runtime calls; indexing details and some workflow stages are documented in the README rather than sampled code.
Main entry points: retrieval.py Dense retrieval · agent.py LangGraph workflow · server.py Chat endpoint · index_books.ipynb Text chunking
Components 17
API
- Chat endpoint
server.py
Answer workflow
- LangGraph workflow
agent.py - Retrieval step
agent.py - Dense retrieval
retrieval.py - Query embedding
retrieval.py - ChromaDB collection
retrieval.py - Context expansion
retrieval.py - Cross-encoder reranking
retrieval.py - Answer generation
agent.py - Answer check
agent.py - Question rewriting
agent.py
Book indexing
- PDF processing
index_books.ipynb - Text chunking
index_books.ipynb - Chunk embeddings
index_books.ipynb - Vector index
index_books.ipynb
Other components
- API client
- Local Ollama model
Connections 18
- API client → Chat endpoint: submits question
README.md - Chat endpoint → LangGraph workflow: invokes
server.py - LangGraph workflow → Retrieval step: starts at
agent.py - Retrieval step → Dense retrieval: calls
agent.py - Dense retrieval → Query embedding: encodes query
retrieval.py - Dense retrieval → ChromaDB collection: queries and reads
retrieval.py - Dense retrieval → Context expansion: assembles neighbors
retrieval.py - Dense retrieval → Cross-encoder reranking: scores candidates
retrieval.py - LangGraph workflow → Answer generation: then generates
agent.py - Answer generation → Local Ollama model: requests answer
agent.py - Answer generation → Answer check: checks answer
agent.py - Answer check → Question rewriting: may route to
agent.py - Question rewriting → Local Ollama model: requests rewrite
agent.py - Question rewriting → Retrieval step: retries retrieval
agent.py - PDF processing → Text chunking: extracts and chunks
README.md - Text chunking → Chunk embeddings: creates embeddings
README.md - Chunk embeddings → Vector index: prepares collection
README.md - Vector index → ChromaDB collection: provides runtime collection
README.md