Skip to main content

rager

Composable RAG primitives with caching baked in.

Install

uv add rager

Getting started

uv run pytest
uv run prek install

For GPU (CUDA/ROCm) torch, add the matching PyTorch index to your own project and install torch from it — those builds aren't on PyPI.

Example

Wire the primitives together yourself — there is no hidden pipeline. This chunks documents, embeds and indexes each chunk under its own key, then answers a query from the nearest chunk:

chunker = SemanticChunker()
embedder = SentenceTransformerDenseEmbedder()
index = FaissIndex(384, MemoryStore())
chunks = MemoryStore()
generator = TransformersGenerator()

key = 0
for document in documents:
    for chunk in chunker.chunks(document):
        await index.set(key, await embedder.embed(chunk))
        chunks[key] = chunk
        key += 1

query = "Why do cats purr?"
(key,) = await index.similar(await embedder.embed(query), embedding_results=1)
answer = await generator.prompt(f"Answer using only the context.\n{chunks[key]}\n{query}")

tests/application/ has full dense and hybrid recipes.

API

Every stage is a Protocol with concrete implementations. Each module also ships an abstract Base* helper that derives the protocol from a few core operations, so you can drop in your own implementation. async methods batch concurrent calls; model-backed methods cache results under .jar/.

Parsers — extract text units from files

  • Parser — protocol: units(file) returns text units.
  • BaseParser — derives a cached units() from _jar, _batched, and _units; the jar is keyed by the file's blake3 content hash.
  • UnstructuredFileParser — parses any file supported by unstructured, returning its elements.
  • UnstructuredPageParser — composes a file parser and returns one string per page, grouping elements by page number.
  • PdfFileParser, MarkdownFileParser, CsvFileParser — aliases of UnstructuredFileParser; PdfPageParser, MarkdownPageParser, CsvPageParser — aliases of UnstructuredPageParser, for readable call sites.

Chunkers — split units into chunks

  • Chunker — protocol: chunks(unit) -> list[str].
  • BaseChunker — derives a cached chunks() from _jar and _split.
  • SemanticChunker — splits on semantic boundaries with a token budget: SemanticChunker(model_name="gpt-3.5-turbo", chunk_size=1000, overlap=0).

Embedders — turn chunks into vectors

  • Embedder[E] — protocol: async embed(chunk) -> E.
  • BaseEmbedder — derives a cached embed() from _jar and _encode.
  • SentenceTransformerDenseEmbedder — dense, L2-normalized DenseEmbedding via SentenceTransformers (default all-MiniLM-L6-v2).
  • SpladeSparseEmbedder — sparse SparseEmbedding via a SPLADE encoder (default prithivida/Splade_PP_en_v1).

Indexes — store vectors and search by similarity

  • Index[K, E] — protocol: a Store[K, E] of embeddings plus async similar(embedding, embedding_results=100) -> list[key]. Ranks by inner product (equals cosine for L2-normalized vectors).
  • FaissIndex(dimensions, key_map) — flat FAISS index; seals embeddings on disk under .jar/ and records each key's FAISS id in the injected key_map store.
  • SparseIndex(embedding_map, token_map) — inner-product search over sparse weight maps through an inverted token index; the injected stores decide whether embeddings live in memory or on disk, and search only loads the posting lists of the query's tokens.

Fusers — merge ranked lists

  • Fuser[V] — protocol: fuse(*rankings) -> list[V].
  • BaseFuser — derives fuse() from _weight(rank, size).
  • ReciprocalRankFuser — reciprocal rank fusion with smoothing constant k (default 60).
  • BordaCountFuser — Borda count fusion.

Scorers — rerank chunks against a query

  • Scorer — protocol: async score(query, chunk) -> float.
  • BaseScorer — derives a cached score() from _jar and _predict.
  • CrossEncoderScorer — cross-encoder reranker (default cross-encoder/ms-marco-MiniLM-L6-v2).

Generators — produce an answer

  • Generator — protocol: async prompt(query) -> str.
  • BaseGenerator — derives a cached prompt() from _jar and _generate.
  • TransformersGenerator — local Transformers text-generation model (default HuggingFaceTB/SmolLM2-135M-Instruct, max_new_tokens=512).

Stores — map keys to data

  • Store[K, V] — protocol: mapping-style access (store[key], del store[key], in, len(), iteration) plus set(key, value), get(key) -> value | None, remove(key), clear(), and keys().
  • BaseStore — derives the full protocol from keys, __setitem__, __getitem__, and __delitem__.
  • MemoryStore[K, V] — in-memory map from key to value (chunk text, embeddings, metadata, ...).
  • FileStore[K, V] — like MemoryStore, but seals values on disk under .jar/, keeping only keys and digests in memory.

Types

  • Hash — a blake3 hasher.
  • DenseEmbeddinglist[float].
  • SparseEmbeddingdict[int, float] mapping token id to weight.

Release files for rager 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rager 0.4.1
File Size Uploaded
rager-0.4.1.tar.gz 16.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rager 0.4.1
File Interpreter ABI Platform
rager-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 38.1 kB

Release files / rager-0.4.1.tar.gz

Download URL rager-0.4.1.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6e32acc3b5998c106639ea7a803a714f5c6d42a4d0f46447a77a0f51745f36a7
BLAKE2b-256 checksum
How to use checksums
5605d1c98d793de832f413682a1b27747e0c948b89760aea70f537c4516d7c4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / rager-0.4.1-py3-none-any.whl

Download URL rager-0.4.1-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2968a69016ac51c4791f762dd9d52a10242d6b3f926e1168e3d8025a37a17b4a
BLAKE2b-256 checksum
How to use checksums
3dc90c7ad9bcdb439ffb21e8fce951fb0bcec5fbde32cea33f087a139915389b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.18

2 release files

0.1.17

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page