Ask questions about your documents with mini-RAG. Built in about 20 lines of shell on top of this open source stack: Stack: Docling (parsing) → TF-IDF (retrieval) → Ollama (local LLM)
docs/ ──docling──▶ tmp/md/*.md ──TF-IDF top-k──▶ tmp/ctx ──Ollama──▶ answer
- macOS or Linux with Homebrew
- Python 3
jq:brew install jq
1. Start the LLM server (terminal 1). Skip this if the Ollama app is already running.
sh server.sh2. Ask a question (terminal 2)
sh rag.sh ./docs "What are geospatial foundation models?"sh rag.sh <docs_path> "<question>" [top_k] [model] [ollama_url]Arguments are positional (there are no --flags), so they must be given in this order:
| Position | Argument | Description | Default |
|---|---|---|---|
| 1 | docs_path |
File or folder of documents | required |
| 2 | question |
Your question, in quotes | required |
| 3 | top_k |
Number of chunks sent to the LLM | 4 |
| 4 | model |
Ollama model name | $MODEL or qwen2.5:7b |
| 5 | ollama_url |
Ollama server address | $OLLAMA_URL or http://localhost:11434 |
Example with 8 chunks:
sh rag.sh ./docs "What are geospatial foundation models?" 8Environment variables (optional):
MODEL=llama3.1:8b sh rag.sh ./docs "Question?" # use another model
OLLAMA_URL=http://gpu-box:11434 sh rag.sh ... # remote Ollama serverIntermediate files are saved in ./tmp/:
| File | Content |
|---|---|
tmp/md/ |
Markdown produced by Docling, one file per document |
tmp/ctx |
The retrieved chunks sent to the LLM (last run only) |
If an answer looks wrong, run cat tmp/ctx to check whether the right chunks were retrieved. To force a clean re-parse, run rm -rf tmp/md.
⚠️ The first launch is slow. Dependencies are installed, Docling downloads its models, and Ollama pulls the LLM (~4.7 GB forqwen2.5:7b).