A retrieval-augmented generation (RAG) application that answers questions about a collection of documents entirely on-device — no cloud, no API keys.
Based on the official Microsoft tutorial: Tutorial: Build a RAG application — Foundry Local
- Knowledge base — a list of text documents defined in
main.py. - Embeddings — each document is converted into a numerical vector using the
local
qwen3-embedding-0.6bmodel. - Retrieval — when you ask a question, it is embedded too, and the top-2 most similar documents are found using cosine similarity.
- Generation — the retrieved documents are placed in the system prompt, and the
local
qwen2.5-0.5bchat model generates an answer grounded in that context (streamed token by token).
Question ──▶ embed query ──▶ cosine similarity vs. document vectors
│
▼
top-2 relevant documents (context)
│
▼
chat model ──▶ grounded, streamed answer
- Windows, macOS, or Linux with at least 8 GB RAM
- Python 3.11+
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txtOn macOS/Linux use
pip install foundry-local-sdk openaiinstead of the Windows (-winml) package.
python main.pyOn first run, the two models are downloaded automatically and cached locally, so later runs start much faster. Then ask questions like:
- "What programming languages does the SDK support?"
- "How does Foundry Local run models?"
- "What is retrieval-augmented generation?"
Type quit to exit.
| File | Purpose |
|---|---|
main.py |
The complete RAG application |
requirements.txt |
Python dependencies |