Metadata-Version: 2.4
Name: Rag-System
Version: 1.0.1
Summary: A production-quality Retrieval Augmented Generation (RAG) Python Framework.
Author-email: Mohd Musheer <musheerayan@gmail.com>
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: llama-index-core
Requires-Dist: pymupdf
Requires-Dist: python-docx
Requires-Dist: openpyxl
Requires-Dist: beautifulsoup4
Requires-Dist: tiktoken
Requires-Dist: python-dotenv
Provides-Extra: groq
Requires-Dist: llama-index-llms-groq; extra == "groq"
Provides-Extra: chroma
Requires-Dist: chromadb; extra == "chroma"
Requires-Dist: llama-index-vector-stores-chroma; extra == "chroma"
Provides-Extra: huggingface
Requires-Dist: llama-index-embeddings-huggingface; extra == "huggingface"
Requires-Dist: sentence-transformers; extra == "huggingface"
Provides-Extra: docs
Requires-Dist: sphinx; extra == "docs"
Requires-Dist: sphinx-rtd-theme; extra == "docs"
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: twine; extra == "dev"
Requires-Dist: build; extra == "dev"
Provides-Extra: all
Requires-Dist: llama-index-llms-groq; extra == "all"
Requires-Dist: chromadb; extra == "all"
Requires-Dist: llama-index-vector-stores-chroma; extra == "all"
Requires-Dist: llama-index-embeddings-huggingface; extra == "all"
Requires-Dist: sentence-transformers; extra == "all"
Dynamic: license-file

# Rag-System

A production-quality Retrieval Augmented Generation (RAG) Python Framework.

## Features

- **Multi-Format Ingestion**: Recursively ingest and parse `.pdf`, `.docx`, `.doc`, `.txt`, `.md`, `.csv`, `.xlsx`, `.xls`, `.json`, `.html`, `.htm`, and `.xml`.
- **Hybrid Search**: Combines ChromaDB vector similarity with native keyword filtering (`$contains`).
- **Flexible LLM Selection**: Out-of-the-box support for Groq, OpenAI, Anthropic, Gemini, Ollama, and OpenRouter.
- **Session Memory**: Persistent user facts serializer (`memory.json`) and token-budget-aware sliding conversation history window.
- **Advanced Document Filtering**: Expand wildcard glob paths and folders to target retrieval down to specific files and page ranges.
- **Unified Developer Namespace**: Exposes a clean, high-level user interface.

---

## Installation

Install using `pip`:

```bash
pip install Rag-System
```

---

## Quick Start

```python
from Rag_System import RAG

# Initialize
rag = RAG(
    model="llama3-8b-8192",
    provider="groq",
    data_dir="data",
    auto_ingest=True,
    verbose=True
)

# Ask a question
response = rag.ask("Which departments have the lowest CAP1 MCA cutoffs?")
print(response.answer)

# Print citations
for citation in response.citations:
    print(f"- {citation.filename} (Page {citation.page_number}) similarity={citation.similarity:.4f}")
```

---

## Configuration

Settings are parsed in the following priority order:
1. Constructor arguments
2. Environment variables from `.env`
3. Defaults (`Rag_System/constants.py`)

### Environment Settings (.env)

```env
GROQ_API_KEY=gsk_...
OPENAI_API_KEY=sk-proj-...
ANTHROPIC_API_KEY=sk-ant-...
GEMINI_API_KEY=AIzaSy...
OLLAMA_BASE_URL=http://localhost:11434
```

---

## API Reference

### class `RAG`

#### Arguments:
- `model`: Model name identifier.
- `embedding_model`: Text embedding model name. Defaults to `BAAI/bge-small-en-v1.5`.
- `provider`: Target LLM provider (`groq`, `openai`, `anthropic`, `google`, `ollama`, `openrouter`).
- `data_dir`: File directory path to scan.
- `auto_ingest`: If True, run index scans upon setup.
- `verbose`: Toggle framework log outputs.

#### Methods:
- `ask(question, ...)`: Solves intent routing, runs retrival, and returns `RAGResponse`.
- `chat(message)`: Run interactive conversation storing chat history.
- `ingest(force_rebuild=False)`: Incremental document file indexing.
- `retrieve(query, **kwargs)`: Return candidate nodes with similarity scores.
- `search(query, **kwargs)`: Alias for `retrieve`.
- `summarize(query=...)`: Summarize indexed documents.
- `compare(query=...)`: Compare documents.
- `statistics()`: Retrieve document counts and database counters.
- `list_documents()`: Return list of uniquely indexed filenames.
- `delete_document(filename)`: Wipe document contents matching name.
- `update_document(filename)`: Reindex file.
- `clear_memory()`: Reset conversation states.
- `add_memory(key, value)`: Remember user preference तथ्य.
- `reset_vectorstore()`: Clean all collections.

---

## CLI Usage

The package installs a `rag` subcommand group:

```bash
# Ingest documents
rag ingest --force-rebuild

# Query
rag ask "Which colleges offer MCA?" --files "data/pdfs/*.pdf"

# Stats
rag stats

# Documents list
rag documents
```
