Skip to main content
Glama
Akashbakshi99

RAG Query MCP Server

README.md
# RAG Pipeline

Hybrid-retrieval RAG (dense + BM25 sparse fused in Pinecone, Jina reranking, Gemini generation) over a single document.

## Setup

```bash
pip install -r requirements.txt
```

Create a `.env` in the project root:

```env
GOOGLE_API_KEY=your_key
PINECONE_API_KEY=your_key
PINECONE_INDEX_NAME=rag-hybrid
JINA_API_KEY=your_key
API_KEY=your_choice          # protects the FastAPI endpoint
```

## Ingest (run once before querying)

Chunks and embeds `data/*.pdf` into Pinecone, and fits the BM25 index.

```bash
python ingest.py
```

## Run the endpoints

All three answer questions through the same pipeline.

### 1. CLI (`ask.py`)

```bash
python ask.py "What is the standard meal expense cap during business travel at Texazdi X?"   # one-shot
python ask.py                                             # interactive prompt
```

### 2. HTTP API (`app.py`, FastAPI)

```bash
python -m uvicorn app:app --host 127.0.0.1 --port 8000
```

Then query it (send the `API_KEY` from your `.env` as the `x-api-key` header):

```bash
curl -X POST http://127.0.0.1:8000/query \
  -H "Content-Type: application/json" \
  -H "x-api-key: your_choice" \
  -d '{"question": " How many days of paid annual leave can be carried over to the next year, and what is the total annual leave allotment?"}'
```

Health check: `GET http://127.0.0.1:8000/health`

### 3. MCP server (`mcp_server.py`)

Exposes a `query_documents` tool over MCP (stdio):

```bash
python mcp_server.py
```

## Evaluation (optional)

```bash
python -m evals.evaluate
```