Metadata-Version: 2.4
Name: adaptive-rag-engine
Version: 1.0.0
Summary: Adaptive Retrieval-Augmented Generation Engine with Hybrid Retrieval, LangChain, Cross-Encoder Reranking and FastAPI.
Author-email: Gokul Raj P <mailsforgokulraj@gmail.com>
License: Copyright <2026> <gokul028h>
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Keywords: rag,llm,langchain,fastapi,retrieval,bm25,faiss,sentence-transformers,gemini,cross-encoder
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# Adaptive RAG Engine

<div align="center">

Production-ready Adaptive Retrieval-Augmented Generation (Adaptive RAG) Engine built using FastAPI, LangChain, FAISS, SentenceTransformers, BM25, Cross-Encoder Reranking and Google Gemini.

![Python](https://img.shields.io/badge/Python-3.10-blue)
![FastAPI](https://img.shields.io/badge/FastAPI-0.116-green)
![LangChain](https://img.shields.io/badge/LangChain-Framework-green)
![FAISS](https://img.shields.io/badge/FAISS-Vector_Search-orange)
![License](https://img.shields.io/badge/License-MIT-yellow)

</div>

---

# Overview

Adaptive RAG Engine is a modular Retrieval-Augmented Generation framework designed to improve retrieval quality through adaptive query routing, hybrid retrieval, reciprocal rank fusion (RRF), cross-encoder reranking, confidence estimation, and optimized context construction before passing relevant information to a Large Language Model (LLM).

Unlike conventional RAG systems that rely on a single retrieval strategy, Adaptive RAG dynamically selects Dense, Sparse, or Hybrid Retrieval based on query analysis to improve retrieval precision while maintaining low latency.

---

# Key Features

- Adaptive Query Analysis
- Intelligent Query Routing
- Dense Retrieval (SentenceTransformers)
- Sparse Retrieval (BM25)
- Hybrid Retrieval
- Reciprocal Rank Fusion (RRF)
- Cross-Encoder Re-ranking
- Confidence Estimation
- Context Optimization
- LangChain Retriever
- FastAPI REST API
- FAISS Vector Database
- Google Gemini Integration
- Modular Production Architecture
- Docker Ready
- PyPI Ready

---

# System Architecture

```mermaid
flowchart TD

A[User Query]

A --> B[FastAPI REST API]

B --> C[Adaptive RAG Pipeline]

C --> D[Query Analyzer]

D --> E[Adaptive Query Router]

E -->|Semantic Query| F[Dense Retriever]

E -->|Keyword Query| G[BM25 Retriever]

E -->|Mixed Query| H[Hybrid Retrieval]

F --> I[SentenceTransformer Embeddings]

I --> J[FAISS Vector Store]

G --> K[BM25 Index]

J --> H

K --> H

H --> L[Reciprocal Rank Fusion]

L --> M[Cross Encoder Reranker]

M --> N[Confidence Estimator]

N --> O[Context Optimizer]

O --> P[LangChain Retriever Adapter]

P --> Q[Prompt Builder]

Q --> R[Gemini LLM]

R --> S[Generated Answer]

S --> T[FastAPI Response]
```

# Retrieval Pipeline

User Query

↓

FastAPI REST API

↓

Query Analyzer

↓

Adaptive Query Router

↓

Dense Retriever (MiniLM)

BM25 Retriever

↓

Hybrid Retriever

↓

RRF Fusion

↓

Cross Encoder Reranker

↓

Confidence Estimator

↓

Context Optimizer

↓

LangChain Retriever

↓

Prompt Builder

↓

Gemini

↓

Generated Response

---

# Technology Stack

| Category | Technologies |
|-----------|-------------|
| Backend | FastAPI |
| LLM | Google Gemini |
| Framework | LangChain |
| Vector Search | FAISS |
| Embeddings | SentenceTransformers |
| Sparse Retrieval | BM25 |
| Reranking | Cross Encoder |
| Programming Language | Python |
| Packaging | Docker, PyPI |

---

# Project Structure

```text
app/
src/
tests/
docs/
data/
logs/
```

---

# Installation

```bash
git clone ...
cd adaptive-rag-engine

pip install -r requirements.txt
```

---

# Environment Variables

```text
GEMINI_API_KEY=

GEMINI_MODEL=

HF_TOKEN=
```

---

# Running

```bash
uvicorn app.main:app --reload
```

---

# API

POST /rag/ask

Example

```json
{
  "question":"Explain Retrieval Augmented Generation."
}
```

---

# Docker

```bash
docker build -t adaptive-rag-engine .

docker run -p 8000:8000 adaptive-rag-engine
```

---

# PyPI

```bash
pip install adaptive-rag-engine
```

---

# Future Scope

- Redis Cache
- Streaming Responses
- Multi-modal Retrieval
- Kubernetes Deployment
- Multi-Agent RAG
- GraphRAG
- Knowledge Graph Integration

---

# License

MIT License
