Skip to main content

Local RAG Q&A Assistant

CI

🇹🇷 Türkçe README

A small, fully local retrieval-augmented Q&A tool: no internet connection needed at query time, no data leaves your machine. Point it at a folder of documents, ask questions in natural language, and it answers only from what's in your documents — if the answer isn't there, it says so instead of making something up.

How it works

  1. Ingest — files in docs/ are split into paragraphs, each paragraph is embedded and written to a local SQLite database.
  2. Retrieve — your question is embedded the same way; the 3 closest chunks are found by cosine similarity.
  3. Generate — those chunks are passed as context to a locally-running LLM (phi-3.5-mini via Microsoft Foundry Local) with a strict "answer only from this context" system prompt.
  4. CLI — local-rag-qa ask runs the ask-loop in your terminal until you type quit.

Why local

Foundry Local runs phi-3.5-mini behind an OpenAI-compatible REST endpoint, GPU-accelerated via Metal on Apple Silicon. Nothing about a question or a document ever leaves the machine — a good fit for private notes, internal docs, or just not wanting your queries logged by someone else's API.

Quickstart

# 1) Foundry Local (Homebrew)
brew tap microsoft/foundrylocal
brew install foundrylocal
foundry service start
foundry model download phi-3.5-mini

# 2) Install the CLI (editable, until the PyPI release lands — see roadmap)
python3 -m venv .venv && source .venv/bin/activate
pip install -e .

# 3) Put your documents in docs/, then index and ask
local-rag-qa ingest    # embeds everything in docs/ into knowledge.db
local-rag-qa ask        # starts the Q&A loop

foundry-local-sdk uses the X | None type syntax, which needs Python ≥3.10 (or the eval_type_backport package, already a conditional dependency in pyproject.toml on older versions).

Project layout

.
├── docs/                       # your knowledge base (.md / .txt files go here)
├── src/local_rag_qa/
│   ├── cli.py                  # `local-rag-qa` entry point (ingest / ask)
│   ├── common.py                # chunking, embedding, cosine-similarity helpers
│   ├── ingest.py                 # docs/ -> chunks -> embeddings -> SQLite
│   ├── retrieve.py               # question -> embedding -> nearest chunks
│   ├── generate.py               # chunks + question -> Foundry Local -> answer
│   └── main.py                    # interactive ask-loop
├── pyproject.toml
└── README.md

A note on scope (kept honest on purpose)

The original plan called for embedding via Foundry Local's qwen3-embedding-0.6b. At setup time, Foundry Local's model catalog had no embedding model available (foundry model list --filter task=embedding returned empty), so embedding runs on the fully local, open-source sentence-transformers (all-MiniLM-L6-v2, ~90 MB) instead. This doesn't break the "runs offline" goal — only the first model download needs internet.

Limitations / roadmap

  • Chunking is a plain blank-line paragraph split; token-aware, overlapping chunking would help.
  • Embedding uses sentence-transformers rather than Foundry Local — revisit if/when Foundry Local ships an embedding model.
  • CLI only for now; a Streamlit/HTML UI, multi-language support, and answer-with-citation formatting are out of scope for v0.1.
  • No automated evaluation layer yet — correctness was checked manually.
  • Packaged as a pip install-able CLI (pyproject.toml + local-rag-qa entry point); not yet published to PyPI — pip install -e . from a clone until then.
  • Automated tests cover the pure-logic helpers (chunking, cosine similarity); ingest/retrieve/generate aren't covered yet since they need a live Foundry Local instance.

Contributing

Issues and PRs welcome — see CONTRIBUTING.md (coming soon) or just open an issue with what you'd like to change.

License

MIT

Metadata

Release files for local-rag-qa 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for local-rag-qa 0.1.0
File Size Uploaded
local_rag_qa-0.1.0.tar.gz 12.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for local-rag-qa 0.1.0
File Interpreter ABI Platform
local_rag_qa-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 21.6 kB

Release files / local_rag_qa-0.1.0.tar.gz

Download URL local_rag_qa-0.1.0.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
30d8c48296d935ba1fb6e33cb425ab59b010a4caa3f7f412a53f53d6c9f91eb5
BLAKE2b-256 checksum
How to use checksums
54ef0f04da8ac3c1f6128cd73d39a78edbcc4dcb89470faef13992c050e291d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / local_rag_qa-0.1.0-py3-none-any.whl

Download URL local_rag_qa-0.1.0-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa718d44db84261d0e2403b336b74ee14a04c0b03ae5eafb82038a0a5b03952c
BLAKE2b-256 checksum
How to use checksums
bf118054ea7b0a94ca36399268ff509557ce782ccd56e37d1f44b187a178f556
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page