Educational QA with RAG
Four chunking strategies, one set of questions, one honest comparison
- Role
- Solo build
- Where
- AISD, Algonquin College
- When
- Jan to Apr 2025
- Status
- Coursework, not hosted
Context
Retrieval-augmented generation is usually presented with one chunking strategy already chosen, as if the choice were obvious. It is not, and it moves answer quality more than the model does.
The problem
To compare chunking strategies fairly you have to hold everything else still: same source documents, same embedding model, same retrieval depth, same prompt, same judge. Anything less and you are comparing pipelines, not chunkers.
Approach
One corpus, four ways of cutting it
Open-source grade 6 and 7 Geography and History textbooks are extracted with PyMuPDF, then chunked four ways from identical cleaned text: sentence windows of three with two-sentence overlap, 200-token windows with a 50-token stride using the BERT WordPiece tokenizer, paragraph splits, and a hybrid. The paragraph chunker falls back to six-sentence windows when a PDF has no real paragraph breaks, which most textbook exports do not.
The strategies produce very different corpora
From the same books: 11,923 sentence chunks, 2,982 paragraph chunks, 1,708 token chunks, and 622 hybrid chunks. An order of magnitude between the extremes, which is exactly why the comparison is worth running.
Four indexes, identical construction
Each chunk set is embedded with all-MiniLM-L6-v2 and written to its own FAISS IndexFlatL2, with chunk metadata pickled alongside so a retrieved vector traces back to its source PDF. Same model, same index type, same batch size across all four.
Same prompt, same k, same judge
Retrieval takes the top 3 chunks and builds an identical history-tutor prompt for LLaMA 3.2 running locally through Ollama. The Streamlit interface switches strategy on the same question and scores the answer by hand, logging every run to CSV.
How it fits together
Extract
- PyMuPDF
- grade 6 to 7 textbooks
Chunk, four ways
- sentence · 11,923
- paragraph · 2,982
- token · 1,708
- hybrid · 622
Embed
- all-MiniLM-L6-v2
- one FAISS IndexFlatL2 per strategy
Retrieve
- top 3 chunks
- identical prompt across all four
Answer & score
- LLaMA 3.2 via Ollama
- Streamlit, manual score to CSV
Tech stack
- Ingestion
- PyMuPDF
- NLTK
- HuggingFace tokenizers
- Retrieval
- SentenceTransformers (all-MiniLM-L6-v2)
- FAISS IndexFlatL2
- Generation
- LLaMA 3.2
- Ollama
- Interface
- Streamlit
- pandas
- Compute
- CUDA when available, CPU fallback
Outcome
- A working comparison rig where the chunking strategy is the only variable that moves.
- Average manual score of 10.5 out of 12 across the evaluated question set.
- Streamlit interface for real-time querying and manual scoring, with every run logged for later analysis.
The repository is private. Happy to walk through the code directly.
More case studies
- Resume-Aware RAG Chatbot: Grounding resume generation in real resumes
- FedEthics Platform: Inheriting one hand-written HTML file and leaving a platform that deploys itself
- Express Entry Draws Intelligence: Turning an IRCC JSON feed into an answer people can act on