Skip to main content

Caching based RAG primitives

Project description

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, then answers a query from the nearest chunk:

chunker = SemanticChunker()
embedder = SentenceTransformerDenseEmbedder()
index = MemoryDenseIndex()
chunks = MemoryStore()
generator = TransformersGenerator()

for document in documents:
    for chunk in chunker.chunk(document):
       embedding = await embedder.embed(chunk)
       key = await index.add(embedding)
       chunks.set(key, chunk)

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

tests/application/ has full dense and hybrid recipes.

API

Every stage is a Protocol with concrete implementations. 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, id(file) returns the content Hash.
  • UnstructuredFileParser — parses any file supported by unstructured.
  • PdfFileParser, MarkdownFileParser, CsvFileParser — aliases of UnstructuredFileParser for readable call sites.

Chunkers — split units into chunks

  • Chunker — protocol: chunk(unit) -> list[str].
  • 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.
  • 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[E, K] — protocol: async add(embedding) -> key, async remove(key), async similar(embedding, results=100) -> list[key]. Ranks by inner product (equals cosine for L2-normalized vectors). Keys are derived from embedding content, so adding the same vector twice yields one entry.
  • MemoryDenseIndex — flat FAISS index; MemoryDenseIndex(dimensions=None) infers width from the first vector unless fixed.
  • MemorySparseIndex — in-memory inner-product search over sparse weight maps.
  • FileSparseIndex — like MemorySparseIndex, but seals embeddings on disk under .jar/, keeping only keys in memory.

Fusers — merge ranked lists

  • Fuser[V] — protocol: fuse(*rankings) -> list[V].
  • 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.
  • CrossEncoderScorer — cross-encoder reranker (default cross-encoder/ms-marco-MiniLM-L6-v2).

Generators — produce an answer

  • Generator — protocol: async prompt(query) -> str.
  • TransformersGenerator — local Transformers text-generation model (default HuggingFaceTB/SmolLM2-135M-Instruct, max_new_tokens=512).

Stores — map index keys back to data

  • Store[K, V] — protocol: set(key, value), get(key) -> value | None, remove(key), keys().
  • MemoryStore[K, V] — in-memory map from key to value (chunk text, embeddings, metadata, ...).
  • FileStore[K, V] — like MemoryStore, but seals buffer values on disk under .jar/, keeping only keys and digests in memory.

Types

  • Hash — a blake3 hasher; the content ID returned by parsers.
  • DenseEmbeddinglist[float].
  • SparseEmbeddingdict[int, float] mapping token id to weight.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rager-0.1.14.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rager-0.1.14-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file rager-0.1.14.tar.gz.

File metadata

  • Download URL: rager-0.1.14.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}

File hashes

Hashes for rager-0.1.14.tar.gz
Algorithm Hash digest
SHA256 ee2463318b76501a352c07988b68128c9bda6ffc2c0d0d35e14e0d35dadda6b2
MD5 b137669de6d6cca30d412e58b0c9482b
BLAKE2b-256 fe08f6a4e202abb99e9c8a7ab1a5f7ebb9aa61c28f537cd9804750f1fdfc519f

See more details on using hashes here.

File details

Details for the file rager-0.1.14-py3-none-any.whl.

File metadata

  • Download URL: rager-0.1.14-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}

File hashes

Hashes for rager-0.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 3753e4e12d2e0a4884ad67bd24b628fa7eb1e0e730529d830721fc785f882727
MD5 b0e32c92a1a40505f442e38b8e499b6f
BLAKE2b-256 450f03cbf5094ec6246560668bfef882e86687e983b7311f43965d789521359c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page