How aman554-eq/physics-rag-chatbot works
This is a physics education chatbot: a user starts an isolated chat, submits a question, and receives a streamed, physics-grounded answer. The README documents the retrieval, reranking, prompt selection, memory, and local-model capabilities; sampled backend code confirms session registration, retrieval/reranking helpers, answer streaming, and history updates. Several stages are documented but their connecting implementation was not fully sampled, so those links follow the documented architecture rather than uninspected source.
Main entry points: rag-5.5.py Stream endpoint · [id]/page.tsx Chat page · (root)/page.tsx Landing page · index.faiss FAISS index
Components 19
Chat interface
- Landing page
client/app/(root)/page.tsx - Chat page
client/app/(root)/[id]/page.tsx - Session controls
client/app/components/Header.tsx
API and sessions
- Question endpoint
server/rag-5.5.py - Stream endpoint
server/rag-5.5.py - Session history
server/rag-5.5.py
Answer generation
- Hybrid retrieval
server/rag-5.5.py - FAISS search
server/rag-5.5.py - Dense search
server/rag-5.5.py - Cross-encoder reranking
server/rag-5.5.py - Prompt routing
server/rag-5.5.py - History-aware retrieval
server/rag-5.5.py - Answer generation
server/rag-5.5.py
Knowledge base
- Physics text
server/data_extraction/book.txt - Document splitting
server/rag-5.5.py - FAISS index
server/vector/index.faiss
Other components
- Physics learner
- Ollama Gemma2
- Embedding models
Connections 23
- Physics learner → Landing page: opens app
- Landing page → Chat page: starts session
- Physics learner → Chat page: asks question
- Chat page → Question endpoint: registers question
- Question endpoint → Session history: initializes session
- Chat page → Stream endpoint: opens SSE stream
- Stream endpoint → Session history: reads history
- Stream endpoint → Hybrid retrieval: retrieves context
- Hybrid retrieval → FAISS search: searches index
- Hybrid retrieval → Dense search: searches embeddings
- FAISS search → FAISS index: searches
- Hybrid retrieval → Cross-encoder reranking: ranks candidates
- Stream endpoint → Prompt routing: selects prompt
- Stream endpoint → History-aware retrieval: reformulates with history
- Stream endpoint → Answer generation: streams answer
- Answer generation → Ollama Gemma2: requests completion
- Stream endpoint → Session history: stores conversation
- Stream endpoint → Chat page: sends SSE tokens
- Chat page → Physics learner: renders answer
- Session controls → Session history: deletes session
- Physics text → Document splitting: splits into chunks
- Document splitting → FAISS index: builds index
- Embedding models → Dense search: encodes documents