Skip to main content

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

Project description

rag-python

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,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.1.0.tar.gz (23.6 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.1.0-py3-none-any.whl (29.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rag_python-0.1.0.tar.gz
  • Upload date:
  • Size: 23.6 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.1.0.tar.gz
Algorithm Hash digest
SHA256 c9305b77412fde5e8264b826d8af9f6c751b287b1d3f0e51a4d3078fe48dd099
MD5 5cd2eae7c2d5e648a8516edce3f813d5
BLAKE2b-256 3a0a9d5117f60b0b8e6416788d5ba1ed9d6a91087f123a60b24d918b92e72ba8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rag_python-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 29.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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0dbf16ba74d1410921e378ff30c4340894ee0d85b4066e7cf7ed771bd7dda1e3
MD5 380106af97a120b86f26c1b355028982
BLAKE2b-256 bd43e3fcbb73ab4d6faf6dbaf7cce3b83ea0f54735f0d9ff9ed4c845240cec6e

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