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.
- Load files from a folder (
loader.py). - Chunk each document into overlapping 120-word windows so answers that span a boundary are not lost (
chunker.py). - Retrieve the top-k chunks for a question using TF-IDF with unigrams and bigrams, ranked by cosine similarity (
retriever.py). - Answer (
answerer.py):- With
OPENAI_API_KEYset, 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.
- With
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txtpython -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 answersExample 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.
pytest- TF-IDF keeps the project dependency-light and easy to reason about. Swapping
Retrieverfor embeddings (for exampletext-embedding-3-smallwith 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.