Skip to main content

Production-grade RAG for Python: multi-LLM, query rewriting, reranking, guardrails, and evaluation.

Project description

rag-python

PyPI version PyPI downloads Python 3.10+ License: MIT GitHub

rag-python is a production-oriented Python library for Retrieval-Augmented Generation (RAG).

Ingest your documents, ask questions, get grounded answers — with query rewriting, multi-query retrieval, reranking, guardrails, and multi-LLM support.

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


Features

  • Document pipeline: loaders → cleaning → chunking → embeddings → ChromaDB
  • Query pipeline: rewriting → multi-query retrieval → reranking
  • Generation with guardrails (prompt injection + hallucination checks)
  • Evaluation scores + self-correction retry loop
  • LLM providers: OpenAI, Azure OpenAI, Anthropic, Gemini, Ollama

Install

pip install rag-python
# or from source
pip install -e .
# with reranking + extra providers
pip install -e ".[rerank,local,anthropic,gemini,all]"

Quickstart

from rag_python import RAG

rag = RAG(
    llm_provider="openai",
    llm_model="gpt-4o-mini",
    embedding_provider="openai",
    embedding_model="text-embedding-3-small",
)

rag.ingest(["./data"], reindex=True)
answer = rag.query("How many days of annual leave?")
print(answer.text)

CLI

export OPENAI_API_KEY=sk-...
rag-python ingest ./data --reindex
rag-python query "How many days of annual leave?" -v

Environment variables

Variable Required Description
OPENAI_API_KEY For OpenAI Default LLM + embeddings
ANTHROPIC_API_KEY For Claude LLM only
GEMINI_API_KEY For Gemini LLM only
AZURE_OPENAI_ENDPOINT For Azure Azure OpenAI
AZURE_OPENAI_API_KEY For Azure Azure OpenAI
OPENAI_API_VERSION Azure Default 2023-09-01-preview
OLLAMA_BASE_URL Ollama Default http://localhost:11434
RAG_PYTHON_DATA_DIR Optional Default ./data
RAG_PYTHON_CHROMA_DIR Optional Default ./chroma_db

See .env.example for all tuning options.


Project structure

.
├── src/rag_python/      # Installable package (PyPI: rag-python)
│   ├── client.py        # High-level RAG API
│   ├── rag_pipeline.py  # Full pipeline
│   └── providers/       # OpenAI, Azure, Anthropic, Gemini, Ollama
├── tests/
├── examples/
├── docs/
├── data/                # Sample documents
├── pyproject.toml
└── main.py              # Local dev CLI wrapper

Docs


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

rag_python-0.2.0.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

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

rag_python-0.2.0-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

File details

Details for the file rag_python-0.2.0.tar.gz.

File metadata

  • Download URL: rag_python-0.2.0.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for rag_python-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3c7b7da5236e1de510cccfa64c2665360dccc956280827ccc10c5f6dc06cabd9
MD5 412892bc988910f587c2ee775cb337cd
BLAKE2b-256 5aaaacc6cd198711c72f748c16f024ada631d11444723a1aab4e9887b39fb8e7

See more details on using hashes here.

File details

Details for the file rag_python-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: rag_python-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 30.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for rag_python-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fd904476f4cad68b46be4ce35c82567d5961a8bde41696261a2116eca6c4e90c
MD5 930aa10e05d6098b5328595825cbfb61
BLAKE2b-256 2ce5486a7aa3b6d3be2256f443b14f81accf32a662263fb3690af87a947bf895

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