mirror of
https://github.com/open-jarvis/OpenJarvis.git
synced 2026-07-28 14:07:55 +00:00
1.4 KiB
1.4 KiB
Document QA
Index a directory of documents into OpenJarvis memory and answer questions with context-augmented retrieval and citations.
Requirements
- OpenJarvis installed (
git clone https://github.com/open-jarvis/OpenJarvis.git && cd OpenJarvis && uv syncoruv sync --extra dev) - An inference engine running (Ollama, cloud API, vLLM, etc.)
- A memory backend available (SQLite is the built-in default)
Usage
python examples/doc_qa/doc_qa.py --help
python examples/doc_qa/doc_qa.py --docs-path ./docs --query "How does authentication work?"
python examples/doc_qa/doc_qa.py --docs-path ./papers --query "What are the main findings?" \
--model gpt-4o --engine cloud --chunk-size 256 --top-k 10
How It Works
The script performs two steps:
-
Index -- Uses
Jarvis.memory.index()to chunk the documents at--docs-pathand store them in the memory backend. Each chunk is stored with its source path so answers can cite specific files. -
Ask -- Uses
j.ask(query, context=True)which automatically retrieves the most relevant chunks from memory and injects them as context before sending the query to the model. The model produces an answer grounded in the retrieved documents.
This is the retrieval-augmented generation (RAG) pattern built into the
OpenJarvis SDK. Adjust --chunk-size and --top-k to tune the
retrieval quality for your documents.