A functional Retrieval-Augmented Generation chatbot built with FastAPI and LangChain on the backend, and a React + Vite frontend. The app loads bootcamp documentation, creates three distinct chunking strategies, performs two retrieval methods, and returns all six answers together with labeled token usage metrics.
- Loads bootcamp docs from
backend/data/aiseason-doc.txt - Uses three chunking strategies:
recursivesemantichierarchical
- Uses two retrieval methods:
similarity(similarity score threshold)mmr(maximum marginal relevance)
- Executes all 6 combinations and returns every answer in one response
- Labels each answer by chunking strategy and retrieval method
- Compares each result by
prompt_tokens,completion_tokens, andtotal_tokens
- Embedding model:
sentence-transformers/all-MiniLM-L6-v2 - Embeddings created with
HuggingFaceEmbeddings - Vector database: Chroma DB
- Each chunking strategy is stored in its own Chroma collection:
recursivesemantichierarchical
- No metadata filtering is required for retrieval; each collection contains only the chunks for its specific strategy. This makes retrieval cleaner, easier to debug, and avoids accidental cross-strategy issues.
The backend is built with FastAPI and LangChain.
backend/app/main.py- Defines the FastAPI app
- Adds CORS middleware using
FRONTEND_URL - Exposes
/api/chatto execute all 6 RAG combinations
backend/app/api/chat.py- Runs retrieval and generation for each chunking/retrieval combination
- Builds the prompt from retrieved context
- Calls the LLM and records usage metadata
- Returns results with chunking label, retrieval method, answer, and token counts
backend/app/api/models.py- Defines
ChatRequest,Result, andChatResponse
- Defines
Chunking lives in backend/app/rag/chunking.py.
recursive_chunking- Splits text using
RecursiveCharacterTextSplitter - Creates overlapping chunks for recursive splitting
- Splits text using
semantic_chunking- Uses
SemanticChunkerwith embeddings - Produces semantically coherent chunks
- Uses
hierarchical_chunking- Builds a multi-level chunking structure with parent and child splits
Retrieval methods are implemented in backend/app/rag/retrieval_methods.py.
similarity_score_retriever- Uses Chroma similarity score threshold search
- Falls back to standard top-k similarity search if needed
mmr_retrieval- Uses Maximum Marginal Relevance search
Both retrieval methods select the correct Chroma collection by chunking strategy.
backend/app/rag/vectorstore.py- Creates a Chroma vector store for each collection
- Uses
collection_nameto isolate each chunking strategy
backend/db/chroma_db/- Persists embeddings and collections locally
backend/app/rag/ingestion_pipeline.py- Loads documents from
backend/data/ - Converts and cleans text
- Generates chunks for all three strategies
- Saves each set of chunks into separate Chroma collections
- Loads documents from
The frontend lives in frontend/.
- Built with React and Vite
- Designed for a modern single-page UI that queries
/api/chat - Uses Axios to send the user question to the FastAPI backend
- Displays all six answers together, clearly labeled by:
- chunking strategy
- retrieval method
- Shows token metrics for each answer result
backend/.env— environment configurationrequirements.txt— Python dependenciesapp/main.py— FastAPI app entrypointapi/chat.py— RAG execution logicmodels.py— request/response schemas
rag/chunking.py— three chunking strategiesretrieval_methods.py— similarity and MMR retrieversvectorstore.py— Chroma collection helperingestion_pipeline.py— ingestion and collection creationfile_conversion.py— document cleaning utilities
data/— bootcamp documentation source filesdb/chroma_db/— persisted Chroma collections
frontend/package.json— frontend dependencies and scriptssrc/— React application source filespublic/— public static assetsvite.config.js— Vite configuration
- Backend
cd backend
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --reload- Frontend
cd frontend
npm install
npm run dev- Environment variables
Create backend/.env with at least:
FRONTEND_URL=http://localhost:5173
GROQ_API_KEY=your_groq_api_key_hereEach chat response returns all six combinations with labels and usage metrics:
chunking:recursive/semantic/hierarchicalretrieval:similarity/mmranswer: generated response textprompt_tokens,completion_tokens,total_tokens
This makes it easy to compare the performance and behavior of every chunking and retrieval combination side by side.
- The project uses the embedding model
sentence-transformers/all-MiniLM-L6-v2. - Three separate Chroma collections isolate strategy-specific chunks and avoid cross-strategy contamination.
- The UI is built to show all six answers together so users can immediately compare outputs.