A small retrieval-augmented generation pipeline, in pure Python.
ragcite retrieves passages, reranks them, generates an answer, and — the part
it actually cares about — ties every sentence of that answer back to the
passages that support it with inline [1] citations. It ships with an offline,
extractive generator so the whole thing runs with no model, no network and no
third-party dependencies, plus an evaluation harness for retrieval, answer
quality and citation grounding.
It is meant as a readable reference: the code prioritises being followable over being fast, and every stage is a small, swappable object.
Most RAG stacks are a thick wrapper over a vector database and a hosted LLM. That
makes them hard to reason about and impossible to run in a unit test. ragcite
takes the opposite bet: a dependency-free core you can read end to end in an
afternoon, where grounding and evaluation are first-class rather than bolted on.
pip install ragcite # once released
pip install -e ".[dev]" # from a checkout, with the test/lint toolsRequires Python 3.10+.
from ragcite import BM25Retriever, ExtractiveGenerator, LexicalReranker, Pipeline
from ragcite.types import Document
docs = [
Document(id="d1", text="The Eiffel Tower is a landmark in Paris, France."),
Document(id="d2", text="Mount Everest is the tallest mountain on Earth."),
]
pipe = Pipeline(
retriever=BM25Retriever(),
reranker=LexicalReranker(),
generator=ExtractiveGenerator(max_sentences=1),
).index(docs)
answer = pipe.run("Where is the Eiffel Tower?")
print(answer.text)
# The Eiffel Tower is a landmark in Paris, France. [1]
for c in answer.citations:
print(c.marker, c.doc_id, round(c.support, 2))| Stage | Interface | Built-ins |
|---|---|---|
| Retrieve | Retriever |
BM25Retriever, DenseRetriever, HybridRetriever |
| Rerank | Reranker |
LexicalReranker, MMRReranker (+ ReciprocalRankFusion) |
| Generate | Generator |
ExtractiveGenerator, LLMGenerator |
| Ground | — | citation attribution + faithfulness checking |
Bring your own LLM by wrapping any str -> str callable in LLMGenerator; the
library still builds the prompt and attributes the response to your sources.
ragcite index --corpus corpus.jsonl
ragcite query --corpus corpus.jsonl --question "Where is the Eiffel Tower?"
ragcite eval --corpus corpus.jsonl --dataset qa.jsonlMIT — see LICENSE.