chatbot-app
View on GitHub ↗
Configuration

RAG Pipeline

--rag retrieves relevant passages from local files in docs/ and adds them to the model prompt, citing every grounded claim. It's opt-in and additive — plain python src/main.py is unaffected.

Pipeline stages

01

Load — rag/loader.py

Loads .pdf / .txt / .md files from docs/. Unsupported extensions and unreadable files are skipped with a logged warning, not fatal.
02

Chunk — rag/chunker.py

Splits documents into overlapping chunks (RecursiveCharacterTextSplitter, 1000 chars / 200 overlap), tagging each with source and chunk_index metadata.
03

Embed — rag/embeddings.py

get_embeddings_provider() reads EMBEDDINGS_PROVIDER (default ollama, model nomic-embed-text). openai uses text-embedding-3-small and requires OPENAI_API_KEY.
04

Store — rag/store.py

build_or_load() wraps langchain_chroma.Chroma, persisted to chroma_db/ (gitignored). Idempotent — an existing collection is loaded instead of re-embedded.
05

Retrieve — rag/retriever.py

retrieve(store, query, k=3) returns the top-3 most relevant chunks for each request.

Citations

constants.RAG_SYSTEM_PROMPT_SUFFIX is appended to (never replaces) SYSTEM_PROMPT in RAG mode. It instructs the model to cite retrieved chunks as [source: <filename>] and to say it doesn't know rather than inventing a citation when nothing relevant was retrieved.

Fallback behavior

If docs/ has no usable content, the CLI's --rag prints a warning and falls back to normal mode rather than crashing. The REST API is different: it builds the RAG store at startup regardless of a flag, and /chat/rag returns 503 if that vector store never initialized.

Preparing embeddings

Pull the local embedding model and start in RAG mode
# Default local embedding model
ollama pull nomic-embed-text
python src/main.py --rag

Delete chroma_db/ and restart the app when you need to rebuild the persisted index after changing the corpus. Add real .pdf/.md/.txt files to docs/ — it currently ships with a placeholder docs/sample-faq.md.

Next steps