A RAG toolkit in plain Python
Dependency-free retrieval-augmented generation toolkit: chunking, BM25, vector and hybrid retrieval, answers with cited sources.
ragkit is a small retrieval-augmented generation toolkit written with only the Python standard library. It keeps the shape of a production pipeline (chunk, index, retrieve, generate) while staying runnable anywhere Python runs, with no API keys or model downloads needed to test or demo it.
Fixed-size windows with overlap, or sentence-aware chunks that never split a sentence.
Okapi BM25 with document-length normalisation and metadata filters.
In-memory cosine similarity over pluggable embedders. Ships with a hashing embedder and a corpus-fit TF-IDF embedder (no neural embeddings by default).
Reciprocal rank fusion over the lexical and vector rankings.
Every answer carries its source chunks and scores so it can be cited.
One-method protocol for embedders and LLMs; an offline echo LLM is included for tests and demos.
Split documents into overlapping windows or whole-sentence chunks.
Rank chunks with BM25, vector similarity, or both fused with RRF.
Build the prompt from the top chunks and return the answer with its cited sources.