Skip to content

Repository files navigation

ragcite

CI Python License: MIT

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.

Why

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.

Install

pip install ragcite        # once released
pip install -e ".[dev]"    # from a checkout, with the test/lint tools

Requires Python 3.10+.

Quickstart

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))

Pipeline stages

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.

Command line

ragcite index --corpus corpus.jsonl
ragcite query --corpus corpus.jsonl --question "Where is the Eiffel Tower?"
ragcite eval  --corpus corpus.jsonl --dataset qa.jsonl

Documentation

License

MIT — see LICENSE.

About

Offline-first pure-Python RAG pipeline with grounded, citation-aware generation and an evaluation harness

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages