How naveenkumarbs/rag_chatbot works
RAG Chatbot lets users upload PDF/text documents, index their contents, ask grounded questions, inspect cited chunks, and continue persisted conversations. The principal flow is upload → extract/chunk/embed → vector indexing; chat → history-aware query rewriting → retrieval/reranking → grounded prompt → local generation → persistence of messages and sources. Separate branches expose search, document management, health, and Prometheus metrics. The graph follows the sampled orchestration and SOURCE INDEX references; unsampled API and storage behavior is included only where the README or index documents it.
Main entry points: main.py FastAPI application · rag_service.py RAG service · retrieval_service.py Retrieval service · chat.py Chat API
Components 27
API and experience
- FastAPI application
app/main.py - Document API
app/api/documents.py - Chat API
app/api/chat.py - Search API
app/api/search.py - Conversation API
app/api/conversations.py
Document ingestion
- Ingestion service
app/rag/ingestion/ingestion_service.py - Document loader
app/rag/ingestion/document_loader.py - Text chunker
app/rag/chunking/text_chunker.py
Evidence retrieval
- Ollama embeddings
app/rag/embeddings/ollama_provider.py - Chroma vector store
app/rag/retrieval/chroma_store.py - Retrieval service
app/rag/retrieval/retrieval_service.py - Cross-encoder reranker
app/rag/reranking/cross_encoder_reranker.py - Retrieval cache
app/core/retrieval_cache.py
Answer generation
- RAG service
app/rag/generation/rag_service.py - Query rewriter
app/rag/query/query_writer.py - Context builder
app/rag/generation/context_builder.py - Prompt builder
app/rag/generation/prompt_builder.py - Ollama chat model
app/rag/providers/ollama_provider.py
Persistence and operations
- Redis
- Document repository
app/repositories/document_repository.py - Conversation repository
app/repositories/conversation_repository.py - Message repository
app/repositories/message_repository.py - Message source repository
app/repositories/message_source_repository.py - SQLite database
app/repositories/database.py - Health checks
app/services/health_service.py - Prometheus metrics
app/core/metrics.py
Other components
- User
Connections 35
- User → FastAPI application: uses
- FastAPI application → Document API: routes
app/main.py - FastAPI application → Chat API: routes
app/main.py - FastAPI application → Search API: routes
app/main.py - FastAPI application → Conversation API: routes
app/main.py - Document API → Ingestion service: ingests files
app/api/documents.py - Document API → Document repository: records documents
app/api/documents.py - Ingestion service → Document loader: extracts text
app/rag/ingestion/ingestion_service.py - Ingestion service → Text chunker: chunks text
app/rag/ingestion/ingestion_service.py - Ingestion service → Ollama embeddings: embeds chunks
app/rag/ingestion/ingestion_service.py - Ingestion service → Chroma vector store: indexes chunks
app/rag/ingestion/ingestion_service.py - Search API → Retrieval service: searches
app/api/search.py - Chat API → RAG service: asks questions
app/api/chat.py - RAG service → Query rewriter: rewrites query
app/rag/generation/rag_service.py - RAG service → Retrieval service: retrieves evidence
app/rag/generation/rag_service.py - Retrieval service → Retrieval cache: checks cache
app/rag/retrieval/retrieval_service.py - Retrieval cache → Redis: reads/writes
app/core/retrieval_cache.py - Retrieval service → Ollama embeddings: embeds query
app/rag/retrieval/retrieval_service.py - Retrieval service → Chroma vector store: searches vectors
app/rag/retrieval/retrieval_service.py - Retrieval service → Cross-encoder reranker: reranks results
app/rag/retrieval/retrieval_service.py - RAG service → Context builder: builds context
app/rag/generation/rag_service.py - RAG service → Prompt builder: builds prompt
app/rag/generation/rag_service.py - RAG service → Ollama chat model: generates answer
app/rag/generation/rag_service.py - Chat API → Conversation repository: loads conversations
app/api/chat.py - Chat API → Message repository: stores messages
app/api/chat.py - Chat API → Message source repository: stores sources
app/api/chat.py - Conversation API → Conversation repository: reads conversations
app/api/conversations.py - Conversation API → Message repository: reads messages
app/api/conversations.py - Conversation API → Message source repository: reads sources
app/api/conversations.py - Conversation repository → SQLite database: reads/writes
app/repositories/conversation_repository.py - Message repository → SQLite database: reads/writes
app/repositories/message_repository.py - Message source repository → SQLite database: reads/writes
app/repositories/message_source_repository.py - Document repository → SQLite database: reads/writes
app/repositories/document_repository.py - FastAPI application → Health checks: checks services
app/main.py - FastAPI application → Prometheus metrics: exposes metrics
app/main.py