Skip to content
rushmithanadipallyPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DocQA: Retrieval-Augmented Document Q&A

Ask questions about your own documents (.txt, .md, .pdf) from the command line. DocQA finds the most relevant passages, then answers using only those passages and cites where each answer came from.

How it works

  1. Load files from a folder (loader.py).
  2. Chunk each document into overlapping 120-word windows so answers that span a boundary are not lost (chunker.py).
  3. Retrieve the top-k chunks for a question using TF-IDF with unigrams and bigrams, ranked by cosine similarity (retriever.py).
  4. Answer (answerer.py):
    • With OPENAI_API_KEY set, an LLM answers strictly from the retrieved context and cites [file#chunk]. If the context lacks the answer, it says so.
    • Without a key, a built-in extractive fallback returns the best-matching sentences, so the project runs offline.

Setup

python -m venv .venv
source .venv/bin/activate        # Windows: .venv\Scripts\activate
pip install -r requirements.txt

Usage

python -m docqa.cli sample_docs "What is the lifespan of a home solar system?"
python -m docqa.cli sample_docs            # interactive mode
export OPENAI_API_KEY=sk-...               # optional: LLM-written answers

Example output:

A typical home system has a lifespan of 25 to 30 years. [solar.md#0]

Sources:
  [solar.md#0] score=0.23

Options: -k chunks to retrieve, --chunk-size, --overlap.

Tests

pytest

Design notes and next steps

  • TF-IDF keeps the project dependency-light and easy to reason about. Swapping Retriever for embeddings (for example text-embedding-3-small with a vector store like FAISS) is a contained change to one class.
  • Planned: embedding retrieval, a small web UI, and an evaluation script measuring retrieval hit rate on a labeled question set.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages