# AI Call Quality Advisor - Production RAG System

FastAPI-based production-ready RAG stack for call quality analytics.

## Stack
- Vector DB: Qdrant
- Cache: Redis
- System DB: MySQL
- Analytics DB: ClickHouse
- Backend: FastAPI (Python)
- Embeddings: E5/BGE via SentenceTransformers
- Reranker: BGE reranker (CrossEncoder)
- LLM: OpenAI-compatible API

## Endpoints
- `POST /ingest_call`
- `POST /query`
- `POST /score_call`
- `GET /agent_report?tenant_id=...&agent_id=...`
- `GET /health`
- `GET /metrics`

## Run
```bash
cp .env.example .env
docker compose up --build
```

## Ingest Example
```bash
curl -X POST http://localhost:8080/ingest_call \
  -H 'Content-Type: application/json' \
  -d '{
    "tenant_id":"tenant-a",
    "call_id":"call-1001",
    "agent_id":"agent-22",
    "timestamp":"2026-02-17T10:00:00Z",
    "tags":["billing","escalation"],
    "transcript":[
      {"speaker":"agent","text":"Hello, how may I assist?"},
      {"speaker":"customer","text":"I was overcharged on my plan."}
    ]
  }'
```

## Query Example
```bash
curl -X POST http://localhost:8080/query \
  -H 'Content-Type: application/json' \
  -d '{
    "tenant_id":"tenant-a",
    "user_id":"mgr-1",
    "query":"Show similar calls with overcharging complaints",
    "tags":["billing"],
    "top_k":5,
    "use_keyword":true
  }'
```

## Scoring Example
```bash
curl -X POST http://localhost:8080/score_call \
  -H 'Content-Type: application/json' \
  -d '{"tenant_id":"tenant-a","call_id":"call-1001","agent_id":"agent-22"}'
```
