A retrieval-augmented generation (RAG) system for searching the internal documentation of the University of Belgrade School of Electrical Engineering (ETF). It retrieves relevant passages from faculty documents and uses a local large language model to answer questions with source references.
- PDF and Word document ingestion with OCR fallback
- Flat and hierarchical text chunking
- Multilingual sentence-transformer embeddings and FAISS retrieval
- Local answer generation through Ollama
- Source-aware answers through a web interface and JSON API
- Reproducible retrieval and generation benchmarks
Documents -> extraction -> chunking -> embeddings -> FAISS index
|
User question -> retrieval -> context -> local LLM -> answer + sources
See Architecture and Data pipeline for implementation details.
- Python 3.10 or newer
- Git
- Ollama for local answer generation
- Enough disk space for the Python dependencies, embedding model, and LLM
Clone the repository and create a virtual environment:
git clone https://github.com/Bojke3/etf-rag-system.git
cd etf-rag-system
python -m venv .venvActivate the environment:
# Windows PowerShell
.\.venv\Scripts\Activate.ps1# Linux or macOS
source .venv/bin/activateInstall the dependencies and create the local configuration:
python -m pip install --upgrade pip
pip install -r requirements.txt# Windows PowerShell
Copy-Item .env.example .env# Linux or macOS
cp .env.example .envStart Ollama, then download the default model from another terminal:
ollama pull mistralThe repository includes a ready-to-use FAISS index. The default settings in .env.example select its matching embedding model. Start the application with:
python web/app.pyOpen http://localhost:8000/chat in a browser. The health endpoint is available at http://localhost:8000/, and questions can be submitted to POST /query.
To test another Ollama model, install it with ollama pull MODEL_NAME, then select it in the web interface or set OLLAMA_MODEL=MODEL_NAME in .env and restart the application.
For a repeatable local comparison, run the model against the final benchmark questions:
python scripts/collect_benchmark_answers.py --execution local --model MODEL_NAME --benchmark benchmarking/finalna_pitanja.json --run-id MODEL_RUN_IDUse a unique run ID for every model or configuration. Results are saved under benchmarking/runs/MODEL_RUN_ID/. Keep the vector index, retrieval settings, prompt strategy, and context budget fixed when comparing generation models. To test a different embedding model, build a new index with scripts/index_documents.py --model EMBEDDING_MODEL and set the same EMBEDDING_MODEL and new VECTOR_STORE_PATH in .env; an index must not be queried with a different encoder from the one that created it.
To rebuild the knowledge base from documents in DataAkti/, use the three-stage pipeline:
python scripts/extract_documents.py --input DataAkti --output data/extracted
python scripts/chunk_documents.py --input data/extracted --output data/chunks --chunk-size 1024 --overlap 150
python scripts/index_documents.py --input data/chunks --output models/vectorstore_newOutput directories must be new or empty. After indexing, set VECTOR_STORE_PATH=./models/vectorstore_new in .env. Keep EMBEDDING_MODEL identical to the model used to build the index.
pytest tests/ -v
pytest tests/ --cov=src| Path | Purpose |
|---|---|
src/data/ |
Document loading, OCR, preprocessing, and chunking |
src/embedding/ |
Embedding models, FAISS storage, and index validation |
src/retrieval/ |
Similarity search and parent-aware retrieval |
src/llm/ |
Local and hosted LLM clients |
src/rag/ |
Context construction, prompting, and answer generation |
src/evaluation/ |
Retrieval and generation evaluation |
scripts/ |
Data processing and benchmarking commands |
web/ |
Flask web interface and API |
benchmarking/ |
Question sets, run records, and benchmark results |
- Setup guide
- API reference
- Benchmarking guide
- Final benchmark questions
- Retrieval evaluation
- Research notes
- Vector index registry
Andrija Trnavcevic and Vuk Bojovic
This project is distributed under the MIT License.