Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

58 Commits

Folders and files

Repository files navigation

Financial Document RAG Assistant

Overview

Financial Document RAG Assistant is a local, multi-document RAG application for uploading and persistently indexing financial PDF reports. It uses BGE-M3 for multilingual semantic retrieval, ChromaDB for persistent vector storage, and Ollama for local LLM answer generation. The project includes a FastAPI backend, a Streamlit interface, and CLI tools. Every answer is returned with system-managed source file, page, and chunk metadata.

Demo

PDF Upload and Indexing

Streamlit PDF upload and indexing

Source-Grounded Question Answering

Streamlit source-grounded question answering

Key Features

  • PDF upload and persistent indexing
  • Multi-document registry
  • Document-specific Chroma retrieval
  • BGE-M3 multilingual embeddings
  • Local Ollama LLM support
  • Focused answer context
  • System-managed sources
  • FastAPI document API
  • Streamlit UI
  • CLI tools
  • Retrieval evaluation
  • Cross-document leakage checks

Architecture

Streamlit UI / CLI
        ↓
FastAPI
        ↓
Document Registry
        ↓
PDF Processing and Chunking
        ↓
BGE-M3 Embeddings
        ↓
Persistent ChromaDB
        ↓
document_id Filtered Retrieval
        ↓
Focused Context
        ↓
Ollama LLM
        ↓
Answer + System Sources

Project Structure

app/               Core backend application and orchestration
  api/             FastAPI routes and request/response schemas
  documents/       JSON-backed document registry
  loaders/         PDF text extraction with page metadata
  processing/      Text cleaning, chunking, and ingestion
  rag/             Retrieval, context, prompts, and answer generation
  services/        Document indexing and RAG service orchestration
  vectorstore/     BGE-M3 embeddings, ChromaDB, and local vector utilities
ui/                Streamlit frontend and FastAPI HTTP client
scripts/           CLI, indexing, evaluation, and manual smoke tools
eval/              Retrieval evaluation questions
tests/             Unit, API, isolation, and UI smoke tests
learning_notes/    Development notes and engineering decisions

Installation

python -m venv venv

Windows:

.\venv\Scripts\activate
pip install -r requirements.txt

Ollama Setup

Pull the default local model:

ollama pull gemma3:4b

The Ollama application must be running before using the Ollama provider.

Run the Backend

uvicorn app.main:app --reload

Swagger:

http://127.0.0.1:8000/docs

Run the Streamlit UI

In a separate terminal:

streamlit run ui/app.py

Open:

http://localhost:8501

Product Workflow

  1. Upload a PDF.
  2. Index the document in ChromaDB.
  3. Select an indexed document.
  4. Ask a question.
  5. Review the answer and its source metadata.

API Endpoints

  • GET /health
  • POST /ask
  • POST /documents/upload
  • GET /documents
  • POST /documents/{document_id}/ask

CLI Usage

Index a document:

python -m scripts.index_document --pdf-path data/raw/KPC_2026.05.pdf

List indexed documents:

python -m scripts.index_document --list-documents

Ask a question:

python -m scripts.ask_pdf --question "Fonun yönetim ücreti nedir?" --llm-provider ollama --llm-model gemma3:4b

Evaluation

PDF files are local runtime data and are not committed. Place the evaluation PDF under data/raw/ before running the command.

Single-document evaluation:

python -m scripts.evaluate_rag --pdf-path data/raw/KPC_2026.05.pdf --eval-path eval/rag_eval_questions.json --start-page 1 --end-page 3 --top-k 3 --use-cache

Verified result:

Pass rate: 100.00%
Average Precision@3: 0.7500
Average Recall@3: 1.0000
Average MRR@3: 1.0000
Average NDCG@3: 0.9599

Cross-document isolation is covered by automated document_id metadata-filter tests. A dedicated multi-document evaluation script and dataset are planned but are not included yet. The intended future command is:

python -m scripts.evaluate_multi_document_rag --eval-path eval/multi_document_eval.json --top-k 3 --relevance-mode strict

No multi-document leakage rate is reported because this evaluation has not been implemented and verified yet.

Example Output

Question:
Fonun yönetim ücreti nedir?

Answer:
Fonun yönetim ücreti 7.125.856,54 TL'dir.

Sources:
- KPC_2026.05.pdf, page 3

Main Engineering Decisions

  • BGE-M3 embeddings are supplied directly instead of using Chroma's default embedding model.
  • Document isolation is enforced with document_id metadata filters.
  • Only the most relevant chunks are included in the answer context.
  • Source metadata is generated by the system rather than the LLM.
  • Retrieval quality is evaluated independently from answer generation.
  • Streamlit is implemented as a thin HTTP client over FastAPI.

Limitations

  • Table-heavy PDF extraction can still be noisy.
  • The evaluation dataset is currently small.
  • Local LLM answer quality depends on model capacity.
  • Authentication and multi-user support are not included.
  • The application is not financial advice.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages