Metadata-Version: 2.2
Name: rag-python
Version: 0.2.0
Summary: Production-grade RAG for Python: multi-LLM, query rewriting, reranking, guardrails, and evaluation.
Author-email: Raghav Singla <04raghavsingla28@gmail.com>
License: MIT
Project-URL: Homepage, https://github.com/RaghavOG/rag-python
Project-URL: Repository, https://github.com/RaghavOG/rag-python
Project-URL: Documentation, https://github.com/RaghavOG/rag-python#readme
Project-URL: Issues, https://github.com/RaghavOG/rag-python/issues
Keywords: rag,llm,embeddings,chromadb,openai,rag-python,retrieval-augmented-generation
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: openai>=1.12.0
Requires-Dist: tiktoken>=0.5.0
Requires-Dist: chromadb>=0.4.22
Requires-Dist: pypdf>=3.17.0
Requires-Dist: python-docx>=1.1.0
Requires-Dist: langdetect>=1.0.9
Requires-Dist: regex>=2023.0.0
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: requests>=2.31.0
Provides-Extra: rerank
Requires-Dist: sentence-transformers>=2.2.0; extra == "rerank"
Requires-Dist: torch>=2.0.0; extra == "rerank"
Provides-Extra: local
Requires-Dist: sentence-transformers>=2.2.0; extra == "local"
Provides-Extra: anthropic
Requires-Dist: anthropic>=0.20.0; extra == "anthropic"
Provides-Extra: gemini
Requires-Dist: google-genai>=0.3.0; extra == "gemini"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Provides-Extra: all
Requires-Dist: rag-python[anthropic,gemini,local,rerank]; extra == "all"

# rag-python

[![PyPI version](https://img.shields.io/pypi/v/rag-python.svg)](https://pypi.org/project/rag-python/)
[![PyPI downloads](https://img.shields.io/pypi/dm/rag-python.svg)](https://pypi.org/project/rag-python/)
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![GitHub](https://img.shields.io/badge/GitHub-RaghavOG%2Frag--python-blue)](https://github.com/RaghavOG/rag-python)

**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](https://github.com/RaghavOG)  
**Repository:** [github.com/RaghavOG/rag-python](https://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

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

---

## Quickstart

```python
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

```bash
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`](.env.example) for all tuning options.

---

## Project structure

```text
.
├── 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

- [Usage](docs/USAGE.md)
- [Providers](docs/PROVIDERS.md)
- [Changelog](CHANGELOG.md)

---

## License

MIT © [Raghav Singla](https://github.com/RaghavOG)
