Gourab RoyHome

SOFTWARE PROJECT

A document assistant that also handles scanned pages

I built this as a Streamlit app for asking questions about PDF, DOCX, and TXT files, including pages that are really just embedded images of text. Uploaded content is OCR'd where needed, indexed with FAISS, and answered by a Groq-hosted Llama 3.3 70B model using only the retrieved passages.

Formats
PDF, DOCX, TXT
OCR
Tesseract
Index
FAISS
Answering model
Llama 3.3 70B via Groq

THE QUESTION

Not every PDF is really text

A lot of the documents people actually want answers from, scanned contracts, printed forms, older reports, are images of text rather than text itself. A Q&A tool that only reads the text layer of a PDF silently fails on those files. I wanted one tool that handles both cases, with OCR available when it is needed and skipped when it is not.

METHOD

Ingest, index, retrieve, answer

  1. 01

    Parse and OCR

    Uploaded PDF, DOCX, and TXT files are parsed for text. Tesseract OCR can be toggled on to extract text from scanned images embedded in a document, and duplicate uploads are caught with an MD5 hash check.

  2. 02

    Chunk and embed

    Extracted text is split into overlapping chunks and embedded with a TF-IDF vectorizer.

  3. 03

    Index and retrieve

    Chunk vectors go into a FAISS index. Each question is embedded the same way and matched against the index for its closest chunks.

  4. 04

    Answer from context

    The retrieved chunks are passed as context to llama-3.3-70b-versatile on Groq, which answers grounded in that context inside a chat-style interface.

DEFAULT CONFIGURATION

Tunable constants

Chunk size1,000 characters
Overlap200 characters
RetrievedTop 5 chunks
Temperature0

A DELIBERATE CHOICE

TF-IDF instead of a neural embedding model

Lexical embeddings keep the tool lightweight

Chunk embedding uses TF-IDF rather than a neural sentence embedding model. That keeps the app dependency-light and fast to run without a GPU, at the cost of missing some of the semantic matching a neural embedder would catch. It is a deliberate trade-off for a tool meant to run comfortably on a small deployment.

REPRODUCE

Run it yourself

Run locallypip install -r requirements.txt export GROQ_API_KEY=your_key_here streamlit run app.py

Tesseract OCR must be installed on the host system separately; see packages.txt for the Debian and Ubuntu package list.