Production-grade RAG for Python: ingest documents, hybrid search, streaming, multi-LLM, guardrails. CLI + Python API.
Project description
rag-python
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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rag_python-0.3.1.tar.gz.
File metadata
- Download URL: rag_python-0.3.1.tar.gz
- Upload date:
- Size: 35.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c16fa7553c551bc5a0affc4ad9d4f2a5e4f35d3d365b4a635d6af2481f67df7
|
|
| MD5 |
253bd57c95c4ff3fd983e170a18b470a
|
|
| BLAKE2b-256 |
0e35f2dbdd0d38f582c10d746fd8607422148ab196278823d8c325f893c0c847
|
File details
Details for the file rag_python-0.3.1-py3-none-any.whl.
File metadata
- Download URL: rag_python-0.3.1-py3-none-any.whl
- Upload date:
- Size: 41.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48c1d21a7692acc602d26338e86f276887fbb176051c53a1a84e70acf3aa4cc7
|
|
| MD5 |
4db955fef8a4492f229a83bd0f6144e7
|
|
| BLAKE2b-256 |
a903a8310b2c4a4676962d51b1ad1e26ac0abd688046a28a062d3e35f14a5d18
|