A small RAG (retrieval-augmented generation) project. It finds the parts of your PDFs that match a question, then asks an LLM to answer using only those parts. If the documents don't contain the answer, it says Answer not found.
It is tested on six NIST publications about AI and security, listed in docs/corpus.md.
- Read: extract the text of each PDF, page by page.
- Split: cut each page into small chunks of about 1,200 characters.
- Embed: turn each chunk into a vector with a local model (
bge-small-en-v1.5). - Search: when a question comes in, find the 5 chunks most similar to it.
- Answer: send those chunks to an LLM through OpenRouter, with the rule "answer only from these sources and cite them like [1]".
If no chunk is similar enough, the app answers Answer not found. without calling the LLM.
You need Python 3.12, uv and OpenRouter API Key.
git clone https://github.com/ahdgalal/document-qa.git
cd document-qa
uv sync
cp .env.example .env- Open
.envand replaceYour_OpenRouter_API_Keywith your OpenRouter key. - Put your PDFs in a folder called
data/. - Build the index, then start the API:
uv run python -m document_qa.indexer
uv run uvicorn document_qa.app:create_app --factoryOpen http://127.0.0.1:8000/docs and try POST /ask with:
{"question": "What four functions make up the AI RMF Core?"}The answer comes back with citations, each listing a document and a page number.
uv run pytestThe tests use fake models, so they don't need internet access or an API key.
- Only works with PDFs that contain text (scanned PDFs are not supported).
- English only.
- Tables in PDFs are read as plain text, so answers from tables may be missed.
MIT