local-rag
README.md
# local-rag
A **private, local document search** for Claude or any MCP client. Ask a plain question and get back the passages that answer it, each with its file, date, page and a relevance score. If nothing fits, it says "not in these documents" instead of guessing.
**Indexing, embeddings, and search run on your Mac.** Ollama creates embeddings locally, LanceDB stores the index on disk, and one read-only MCP tool returns matching passages. If you use a hosted model to draft answers, your MCP client may send the question and retrieved excerpts to the model provider.
## Why local?
The search tool builds and queries the index on your own machine without uploading the source files. The client handles answer generation separately. Use the included sample documents to try it, and check your client's data handling before connecting sensitive documents.
- **Read-only.** The search tool can't write, delete, or read anything outside the index.
- **Cites everything.** Every passage comes back with its file, date, page and score.
- **Says when it doesn't know.** A relevance floor turns weak matches into "not in these documents."
- **Keeps things out on purpose.** An exclude guard refuses `.env` files, keys, credentials, spreadsheets and any folder you rule out. It tests itself before every build, and if the test fails, nothing is built.
- **Hides old and internal docs.** Files labeled `superseded` or `internal` stay out of results unless you ask for them.
## How it works
```
your documents (read-only, never changed)
| pick allowed files, pull out text, drop sensitive sentences
v
passages (~400 tokens, 60 overlap) + labels (file, date, page, status, audience)
| Ollama turns each passage into a vector
v
LanceDB folder (one table per collection, plus a keyword index)
|
question --> hybrid search (meaning + exact words) --> relevance floor
| nothing passes? "not in these documents"
v
passages with file, date, page, score --> MCP client --> model drafts a cited answer
(a hosted model may receive these excerpts)
```
## Stack
| Part | Used | Job |
| --- | --- | --- |
| Embeddings | Ollama + `qwen3-embedding:0.6b` | Turns text into vectors on your machine |
| Vector database | LanceDB | A folder on disk. No server. Backup is a copy. |
| Python | uv + Python 3.12 | A sealed-off environment for this project |
| File readers | PyMuPDF, python-docx, BeautifulSoup | PDF (page by page), Word, HTML. Markdown and text read as-is. |
| Search tool | Python `mcp` package | One read-only tool for Claude |
## Requirements
- macOS. Built and tested on an Apple Silicon Mac mini. It should run anywhere Ollama and Python 3.12 do, but only macOS is tested.
- Homebrew
- About 1 GB free for the embedding model, plus room for your index
- An MCP client, like Claude Code or Claude Desktop
## Install
```bash
git clone https://github.com/armyrunner9916/local-rag.git
cd local-rag
brew install ollama uv
ollama serve # leave running in its own terminal
ollama pull qwen3-embedding:0.6b
uv venv --python 3.12
uv pip install -r requirements.txt
cp config.example.json config.json
```
## Try it on the sample documents
`examples/sample-docs/` holds a few made-up company documents, and `examples/sample-questions.json` holds test questions for them.
```bash
.venv/bin/python -I ingest.py --collection sample
.venv/bin/python -I eval.py --collection sample
```
You'll see which file came back first for each question, plus hit@1, hit@3 and MRR scores. Off-topic questions should come back "not in these documents."
## Use your own documents
1. **Decide what's in and what's out first.** Write it down. It matters more than any setting.
2. Edit `config.json`: add a collection, point it at your folders, and list what to exclude.
3. Build it: `.venv/bin/python -I ingest.py --collection <name>`
4. Write 15 to 20 real questions with known answers, plus a few off-topic ones, and run `eval.py`.
5. Fix what the tests catch. Label old files `superseded`, private ones `internal`, and tune the relevance floor if you need to.
`config.json` is gitignored, so your paths and lists never get committed.
## Connect it to Claude
Claude Code:
```bash
claude mcp add --scope user local-rag -- \
"$(pwd)/.venv/bin/python" -I "$(pwd)/mcp/server.py"
```
Claude Desktop: add the same command and arguments to `claude_desktop_config.json` under `mcpServers`.
The tool:
```
search_docs(query, collection="sample", top_k=5,
include_internal=false, include_superseded=false)
```
It returns passages with file, date, page and score, and a match of `strong` or `weak`. If Ollama isn't running, the server starts it.
## Keep it fresh
`refresh.py` rebuilds every collection, reruns the tests and compares the scores with a saved baseline. If a build fails, the last good table stays in place. Run it by hand, or schedule it with launchd or cron.
## What it doesn't do yet
- No OCR, so scanned PDFs come in empty.
- Spreadsheets are refused on purpose.
- Every build is a full rebuild. Fine for a few thousand passages, slow for tens of thousands.
- One user, one machine.
## More from Armyrunner Studios
Built by [Armyrunner Studios](https://armyrunner-studios.com). I set this up for businesses that want their own private document search. Stop by if you want one.
## License
MIT. See [LICENSE](LICENSE).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues