Skip to main content

rag-python

PyPI version PyPI downloads Python 3.10+ License: MIT Documentation

Production-grade Retrieval-Augmented Generation (RAG) for Python — ingest documents, ask questions, get grounded answers with multi-LLM support, hybrid search, streaming, and guardrails.

pip install rag-python
export OPENAI_API_KEY=sk-...
rag-python ingest ./docs --reindex
rag-python query "What is our leave policy?"

Author: Raghav Singla · Repo: github.com/RaghavOG/rag-python


Why rag-python?

Capability What you get
Ingest TXT, MD, PDF, DOCX, CSV, JSON, HTML → chunk → embed → ChromaDB
Retrieve Multi-query rewriting, hybrid BM25+vector, reranking, metadata filters
Generate Multi-LLM answers with guardrails, evaluation, and retry loop
Stream rag.query_stream() and --stream CLI for responsive UX
Offline Local embeddings via sentence-transformers
CLI rag-python ingest, query, docs — no code required

Install

pip install rag-python
Extra Install Enables
local pip install rag-python[local] Offline embeddings (sentence-transformers)
hybrid pip install rag-python[hybrid] BM25 + vector hybrid retrieval
rerank pip install rag-python[rerank] Cross-encoder reranking
anthropic pip install rag-python[anthropic] Claude LLM
gemini pip install rag-python[gemini] Gemini LLM
all pip install rag-python[all] All optional features

Quickstart (Python)

from rag_python import RAG

rag = RAG(llm_model="gpt-4o-mini")
rag.ingest(["./data"], reindex=True)

answer = rag.query("How many days of annual leave?")
print(answer.text)
print(answer.sources)

Streaming

stream = rag.query_stream("How many days of annual leave?")
for token in stream:
    print(token, end="", flush=True)
print(stream.result.evaluation)

Hybrid search + metadata filter

rag = RAG(
    retriever="hybrid",  # pip install rag-python[hybrid]
    metadata_filter={"filename": "leave-policy.pdf"},
)
rag.ingest(["./policies/"])
print(rag.query("annual leave policy").text)

Quickstart (CLI)

export OPENAI_API_KEY=sk-...

rag-python ingest ./data --reindex
rag-python query "How many days of annual leave?"
rag-python query "PTO policy" --stream -v
rag-python query "benefits" --retriever hybrid

# Built-in terminal docs
rag-python docs quickstart
rag-python docs --list
rag-python --help

Documentation

Guide Description
Docs index Start here
Usage Python API, streaming, retrieval
CLI reference All rag-python commands and flags
Configuration Env vars and RAGConfig
Providers OpenAI, Azure, Anthropic, Gemini, Ollama, local
Changelog Release notes

In the terminal: rag-python docs [topic] — topics: quickstart, install, cli, config, providers, features


Environment variables

Variable Description
OPENAI_API_KEY Default LLM + embeddings
ANTHROPIC_API_KEY Claude
GEMINI_API_KEY Gemini
AZURE_OPENAI_ENDPOINT / AZURE_OPENAI_API_KEY Azure OpenAI
OLLAMA_BASE_URL Local Ollama (default http://localhost:11434)
RAG_PYTHON_DATA_DIR Document dir (default ./data)
RAG_PYTHON_CHROMA_DIR Vector store (default ./chroma_db)

See Configuration and .env.example.


Project layout

src/rag_python/     # pip install rag-python → import rag_python
  client.py         # RAG, RAGAnswer, query_stream
  rag_pipeline.py   # ingest / query pipeline
  providers/        # OpenAI, Azure, Anthropic, Gemini, Ollama, local
docs/               # User documentation (linked from PyPI README)
tests/
examples/

License

MIT © Raghav Singla

Metadata

Release files for rag-python 0.3.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 rag-python 0.3.1
File Size Uploaded Provenance
rag_python-0.3.1.tar.gz 35.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for rag-python 0.3.1
File Interpreter ABI Platform
rag_python-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 76.8 kB

Release files / rag_python-0.3.1.tar.gz

Download URL rag_python-0.3.1.tar.gz
Size 35.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0c16fa7553c551bc5a0affc4ad9d4f2a5e4f35d3d365b4a635d6af2481f67df7
BLAKE2b-256 checksum
How to use checksums
0e35f2dbdd0d38f582c10d746fd8607422148ab196278823d8c325f893c0c847
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.0

Release files / rag_python-0.3.1-py3-none-any.whl

Download URL rag_python-0.3.1-py3-none-any.whl
Size 41.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
48c1d21a7692acc602d26338e86f276887fbb176051c53a1a84e70acf3aa4cc7
BLAKE2b-256 checksum
How to use checksums
a903a8310b2c4a4676962d51b1ad1e26ac0abd688046a28a062d3e35f14a5d18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.0

Security for rag-python 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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