Chatbot Project (RAG over PDFs)
A simple Retrieval-Augmented Generation (RAG) chatbot that lets you ask questions about a PDF. It:
- Loads a PDF, splits it into chunks
- Creates embeddings with OpenAI
- Stores / retrieves chunks from a local ChromaDB vector store
- Uses an LLM (OpenAI chat model by default) to answer using retrieved context
- Exposes a FastAPI endpoint with per-session conversation history
Project structure
src/api/server.py— FastAPI server (GET /question-answering)src/document_loader/loader.py— PDF ingestion script (load → split → embed → persist to Chroma)src/question_answering/qa_system.py— retrieval + prompt building + LLM invocationsrc/vector_store/embeddings.py— helper for adding/searching/listing embeddings in ChromaDBsrc/retrieval/retriever.py— lower-level retrieval helper (debug/test)src/text_processing/splitter.py— text chunking helper
Requirements
- Python 3.10+ recommended
- An OpenAI API key
Install dependencies:
python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate pip install -r requirements.txt
Configuration
Create a .env file in the repo root:
OPENAI_API_KEY=your_key_here
# Optional
GPT_MODEL=gpt-41) Ingest a PDF (build the vector store)
By default, the ingestion script is hard-coded to use:
data/WhitepaperServiceMeshAndAPIManagement.pdf
Run ingestion (from the repo root):
python -m src.document_loader.loader
This will create / update the persisted vector store under vector_store_db/.
Note: The current
src/document_loader/loader.pyusesChroma.from_documents(...)which creates a Chroma collection. The rest of the code expects a collection nameddocument_embeddings. If you see retrieval issues, ensure the same collection name is being used consistently.
2) Run the API
Start the FastAPI server:
It runs on port 8000 by default.
Query the chatbot
Example request:
curl -G "http://localhost:8000/question-answering" \ --data-urlencode "query=What is a service mesh?" \ --data-urlencode "session_id=demo"
Response includes:
answer— the model's answerhistory— the session conversation history stored in-memory
Notes / limitations
- Conversation history is stored in memory only (lost on restart).
vector_store_db/is currently committed to the repo; you may want to add it to.gitignorefor most workflows.- A local LLM option via
LlamaCppexists insrc/question_answering/qa_system.pybut is commented out.
License
Add a license file if you plan to distribute this project.