Skip to content

Repository files navigation

GenAI Document Assistant

A Streamlit application for local document summarisation, grounded question answering, and comprehension-question generation. Users can upload a PDF or TXT file and interact with it through an Ollama-hosted language model.

Key features

  • Uploads PDF and UTF-8 TXT documents.
  • Extracts document text and basic metadata.
  • Produces a concise summary.
  • Answers questions using selected passages from the uploaded document.
  • Generates logic/comprehension challenges with answers and evidence.
  • Uses lazy model initialisation, clear error messages, environment-based configuration, and automated tests for the deterministic utilities.

Architecture

PDF/TXT upload
      │
      ▼
Document loader
  - validates extension and size
  - extracts text and metadata
      │
      ▼
Context selector
  - chunks document text
  - ranks chunks by query-term overlap
      │
      ▼
Ollama LLM
  ├── summary prompt
  ├── grounded Q&A prompt
  └── JSON challenge prompt
      │
      ▼
Streamlit interface

Project structure

.
├── app.py
├── src/document_assistant/
│   ├── document_loader.py
│   ├── llm.py
│   ├── service.py
│   └── text_utils.py
├── tests/
├── .env.example
├── requirements.txt
└── .streamlit/config.toml

Prerequisites

  • Python 3.10 or newer
  • Ollama installed and running
  • A locally available model, defaulting to gemma:2b

Setup

python -m venv .venv

Windows:

.venv\Scripts\activate

macOS/Linux:

source .venv/bin/activate

Install dependencies:

pip install -r requirements.txt

Prepare the local model:

ollama pull gemma:2b

Copy .env.example to .env and change the model or Ollama URL when needed.

Run the application:

streamlit run app.py

Grounding approach

The application splits the document into overlapping chunks and ranks them using query-term overlap. Only the highest-ranked passages are sent to the model for Q&A. The prompt instructs the model to state when the answer is not supported by the supplied context.

This is a lightweight retrieval approach rather than a production retrieval-augmented generation system. It does not use embeddings, a vector database, citations with page coordinates, or formal answer-quality evaluation.

Testing

pip install -r requirements-dev.txt
pytest

The tests cover text chunking, context selection, JSON extraction, and challenge validation without requiring Ollama.

Security and privacy notes

  • Do not commit uploaded documents, .env, or Streamlit secrets.
  • Local inference can keep prompts on the machine running Ollama, but actual privacy depends on how Ollama and the host environment are configured.
  • Do not use this prototype for confidential, regulated, medical, or legal documents without an appropriate security review.

Future improvements

  • Add embeddings and a vector store for semantic retrieval.
  • Preserve page-level references during extraction.
  • Add OCR for scanned PDFs.
  • Add evaluation datasets for faithfulness and answer relevance.
  • Add model and response caching.

Author

Govardhan Reddy — MSc Big Data Analytics candidate

Licence

MIT

About

Local GenAI document assistant for PDF summarisation, grounded Q&A and question generation.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages