# LlamaIndex Q&A

A document question-answering application built with FastAPI and LlamaIndex. Drop PDFs into the `pdfs/` folder, start the server, and ask questions about their contents via a web UI or REST API.

## Stack

- **FastAPI** — REST API and static file serving
- **LlamaIndex** — PDF ingestion, vector indexing, and RAG query engine
- **Claude** (`claude-sonnet-4-6`) — LLM for answer generation
- **BAAI/bge-small-en-v1.5** — local HuggingFace embedding model (no OpenAI key needed)

## Setup

```bash
python3 -m venv .venv
source .venv/bin/activate      # Windows: .venv\Scripts\activate
pip install -r requirements.txt
```

## Usage

1. Add one or more PDF files to the `pdfs/` folder.
2. Set your Anthropic API key:
   ```bash
   export ANTHROPIC_API_KEY=sk-ant-...
   ```
3. Start the server:
   ```bash
   uvicorn main:app --reload
   ```
4. Open [http://localhost:8000](http://localhost:8000) in your browser.

The index is built once at startup. Restart the server whenever you add or remove PDFs.

## API

| Method | Path | Description |
|--------|------|-------------|
| `GET` | `/` | Web UI |
| `GET` | `/health` | Index status |
| `POST` | `/ask` | Ask a question |

### POST /ask

**Request**
```json
{ "question": "What is this document about?" }
```

**Response**
```json
{ "answer": "..." }
```

## Project layout

```
.
├── main.py          # FastAPI app with LlamaIndex integration
├── index.html       # Q&A web UI
├── requirements.txt
└── pdfs/            # Place your PDF documents here
```
