How fedeflowers/rag_bgg works
1. High-level shape
This repo is a single Python application with a Streamlit-style UI in bot/ that implements a RAG workflow for board-game rulebooks. The app is split across three main boundaries: interactive UI, ingestion/retrieval logic, and persistence/search backends.
2. User-facing application layer
bot/app.py is the entry point that likely wires together the pages and session state. The UI is broken into utils/login_page.py for authentication and utils/main_page.py for the main experience after login. bot/css.py, icons/, and readme_images/ support presentation only.
3. Authentication and session continuity
utils/cookie_manager.py indicates browser-side session persistence, so users stay logged in across reruns. init-mongo.js suggests MongoDB is initialized with app-specific collections/users. Authentication is a distinct subsystem from document retrieval, which is important for the architecture diagram.
4. PDF ingestion pipeline
Uploaded rulebooks flow through utils/ingestion_manager.py and utils/ingestion_module.py. These modules are the bridge from raw PDF files into indexable knowledge. The README and filenames imply the pipeline extracts content from PDFs, chunks it, and prepares it for vector search.
5. LLM-assisted extraction
utils/openai_extractor.py shows that OpenAI is not just used for chat answers but also for document processing/extraction. The repo requires an OpenAI API key, so the LLM is an external dependency central to both ingestion and question answering.
6. Retrieval layer
bot/evaluation/vector_db.py and the README’s Qdrant requirement point to Qdrant as the vector store. This is the core retrieval boundary: embeddings or text chunks are indexed there, then queried when the user asks a rule question. Qdrant is separate from the app process and from MongoDB.
7. Chat/Q&A flow
The main interaction is: user asks a question in the UI, the app retrieves relevant chunks from Qdrant, then sends context plus the user prompt to OpenAI for the final answer. README.md mentions “adjust your bot and temperature,” so model selection and generation settings are user-configurable inputs into this flow.
8. Saved chats and reference management
The app supports viewing, retrieving, and deleting prior chats tied to ingested files. That implies a persistent chat/history store, most likely in MongoDB, with file-name or library-level grouping. This is separate from the vector index, which stores searchable content rather than chat history.
9. Empty-state handling
The “No Libraries” feature means the app explicitly handles the case where nothing has been ingested yet. That is an important control-flow branch in the UI: the app must distinguish between authenticated-but-empty and authenticated-with-available-rulebooks.
10. Evaluation/benchmarking subsystem
bot/evaluation/ is an isolated analysis harness, not part of the runtime UI. It contains templates, test notebooks, results.csv, and saved query/answer artifacts for measuring retrieval/answer quality against the vector DB. This should be treated as an offline validation subsystem.
11. Deployment and infrastructure
dockerfile and docker-compose.yml package the app with MongoDB and Qdrant. The README says the app is exposed on port 8501 and uses an external Docker network, so the architecture is containerized and service-oriented rather than monolithic. Running locally without Docker requires separate MongoDB and Qdrant setup and OpenAI credentials.
12. What to draw in a diagram
A clear diagram should show: browser/user -> Streamlit app -> authentication/session store in MongoDB; upload path -> ingestion/extraction -> Qdrant; question path -> Qdrant retrieval -> OpenAI answer generation -> UI response; and a parallel persistence path for saved chats/history in MongoDB. The evaluation folder should be shown as an offline, non-production sidecar.
Main entry points: main_page.py Main page · utils_funcs.py Q&A flow · vector_db.py Vector DB · app.py App entry
Components 18
UI
Interactive Streamlit app and presentation layer
- App entry · Main application entry point that wires UI and session flow
bot/app.py - Login page · Login and access control screen
bot/utils/login_page.py - Main page · Primary authenticated experience for libraries and Q&A
bot/utils/main_page.py - Avatars · Presentation helper for chat display
bot/utils/avatar_manager.py - Styles · UI styling and visual theming
bot/css.py
Ingestion
PDF processing and indexing pipeline
- Ingestion mgr · Coordinates upload handling and indexing workflow
bot/utils/ingestion_manager.py - Ingestion module · Processes rulebook content into indexable chunks
bot/utils/ingestion_module.py - Extractor · Uses OpenAI during document processing and extraction
bot/utils/openai_extractor.py
Retrieval
Vector search and answer generation path
State
Authentication and persistence backends
- Cookies · Browser-side login continuity across reruns
bot/utils/cookie_manager.py - Mongo init · Database bootstrap and collection/user initialization
bot/init-mongo.js - Chat store · Stores prior chats and library-associated history
bot/utils/utils_funcs.py
Evaluation
Offline benchmarking and analysis
- Eval runner · Runs retrieval and answer evaluation experiments
bot/evaluation/evaluation.py - Templates · Prompt and query templates for benchmarking
bot/evaluation/templates.py - Results · Saved evaluation outputs and metrics
bot/evaluation/results.csv
Deployment
Containerization and runtime wiring
- Compose · Container orchestration for app and backing services
docker-compose.yml - Dockerfile · Image definition for the application runtime
dockerfile
Connections 22
- App entry → Login page: renders · App selects authentication screen for unauthenticated users
- App entry → Main page: routes · App routes authenticated users into the main experience
- App entry → Cookies: restores session · App uses cookie-backed session continuity
- Login page → Mongo init: auth data · Login flow depends on MongoDB-backed state and initialization
- Main page → Ingestion mgr: uploads · Main UI sends uploaded rulebooks into the ingestion pipeline
- Ingestion mgr → Ingestion module: coordinates · Manager delegates parsing and chunking work
- Ingestion module → Extractor: extracts · Pipeline uses OpenAI-assisted extraction during processing
- Ingestion module → Vector DB: indexes · Processed chunks are stored for retrieval
- Main page → Q&A flow: asks · User questions enter the RAG answer path
- Q&A flow → Vector DB: retrieves · Answer flow fetches relevant chunks from the vector store
- Q&A flow → Extractor: generates · LLM is used to synthesize the final response
- Q&A flow → Chat store: stores chat · Conversation history is persisted separately from search index
- Main page → Chat store: loads history · Main UI reads prior chats and file-grouped libraries
- Mongo init → Chat store: provisions · Mongo initialization prepares persistence storage
- Main page → Avatars: decorates · Chat display uses avatar/presentation helpers
- Main page → Styles: styles · UI styling supports the main experience
- Eval runner → Vector DB: benchmarks · Offline evaluation queries the retrieval layer
- Eval runner → Templates: uses · Benchmark runner consumes canned prompts and queries
- Eval runner → Results: writes · Evaluation outputs are saved as artifacts
- Compose → Dockerfile: builds · Compose uses the application image definition
- Compose → Mongo init: starts · Deployment includes database bootstrap
- Compose → Vector DB: starts · Deployment includes the vector search service