A small Python project for asking questions from PDF or text documents using a simple RAG pipeline.
The project loads a document, splits it into chunks, retrieves the most relevant chunks, and then uses an LLM to answer the user's question. If no API key is available, it still returns the best matching context so the retrieval part can be tested locally.
I wanted to practice the main parts of an LLM application:
- document loading
- text chunking
- retrieval
- prompt building
- FastAPI endpoints
- clean Python project structure
This project is intentionally kept simple so the core idea is easy to understand.
- Python
- FastAPI
- scikit-learn
- pypdf
- OpenAI API optional
rag-pdf-assistant/
app.py
requirements.txt
.env.example
data/
sample_notes.txt
src/
chunking.py
document_loader.py
llm_client.py
rag_pipeline.py
vector_store.py
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txtCreate a .env file if you want LLM answers:
OPENAI_API_KEY=your_api_key_hereThe app still works without an API key, but it will return retrieved context instead of a generated answer.
uvicorn app:app --reloadThen open:
http://127.0.0.1:8000/docs
Use /ask with:
{
"file_path": "data/sample_notes.txt",
"question": "What is retrieval augmented generation?"
}This is a learning-focused RAG project. For a production system, I would add:
- persistent vector database
- file upload support
- user authentication
- better evaluation
- background processing for large PDFs