A small local RAG agent for Apple Silicon Macs that combines Edge0-35B, Microsoft Learn retrieval, and on-device Apple Translation.
This Gist contains three files:
README.md: setup and execution guideapple_translate.swift: a minimal CLI wrapper around the macOS Translation frameworkmicrosoft_expert_agent.py: the Python agent with Microsoft Learn retrieval, Edge0 streaming, TTFT measurement, and output throughput metrics
Korean question
↓
Deterministic Korean question normalization
↓
Apple Translation
Korean → English
↓
Microsoft Learn semantic search
↓
Build a compact grounding context
↓
Edge0-35B streaming inference
↓
Sentence-level Apple Translation
English → Korean
↓
Korean answer + sources + performance metrics
The model is not treated as the authoritative knowledge store. Microsoft Learn provides the factual grounding, while Edge0 reads the retrieved passages and synthesizes the answer.
This sample assumes:
- Apple Silicon Mac
- A macOS version supported by Edge0
- Python 3.12 recommended
- Node.js 22 or later
- Xcode Command Line Tools
- Enough free storage for the roughly 23GB Edge0-35B checkpoint
- Korean and English translation resources installed in macOS
Related projects:
- Edge0: https://github.com/Edge0-AI/Edge0
- Microsoft Learn MCP: https://learn.microsoft.com/en-us/training/support/mcp
- Microsoft Learn MCP on GitHub: https://github.com/MicrosoftDocs/mcp
Clone the repository.
git clone https://github.com/Edge0-AI/Edge0.git
cd Edge0Create and activate a Python virtual environment.
python3.12 -m venv .venv
source .venv/bin/activateInstall Edge0 and the packages used by this sample.
pip install -e '.[dev,fetch]'
pip install flask requestspython scripts/fetch_models.py \
--tier edge0-35b \
--target-dir modelsSet the model path for the current shell.
export EDGE0_35B_MODEL="$PWD/models/edge0-35b"A newly opened terminal does not inherit the active Python virtual environment.
Activate it again.
cd /path/to/Edge0
source .venv/bin/activateSet the model path again because this is a new shell.
export EDGE0_35B_MODEL="$PWD/models/edge0-35b"Start Edge0 with the Flask transport so the client can receive SSE streaming responses.
edge0 serve edge0-35b \
--host 127.0.0.1 \
--port 8083 \
--flaskKeep this terminal running.
You can verify the server from another shell.
curl http://127.0.0.1:8083/healthzInstall Node.js 22 or later, then install the CLI.
npm install -g @microsoft/learn-cliTest the semantic document search.
mslearn search \
".NET NativeAOT Reflection.Emit" \
--jsonmicrosoft_expert_agent.py launches this CLI as a subprocess and consumes the JSON search results.
The sample intentionally uses the CLI rather than implementing the MCP transport directly so the code stays focused on retrieval and local inference.
Save apple_translate.swift from this Gist in the Edge0 repository directory.
Compile it.
xcrun swiftc \
-parse-as-library \
apple_translate.swift \
-o apple_translate-parse-as-library is important when compiling this single Swift source file with an @main entry point.
If the Korean or English translation resources are missing, the CLI can fail with an error similar to:
TranslationError.Cause.notInstalled
Install Korean and English translation languages in macOS settings, then test the CLI.
./apple_translate ko en \
"NativeAOT에서 Reflection.Emit을 사용할 수 있습니까?"A valid English translation should be printed.
Save microsoft_expert_agent.py from this Gist in the Edge0 repository root.
Example directory layout:
Edge0/
├── .venv/
├── models/
│ └── edge0-35b/
├── apple_translate
├── apple_translate.swift
└── microsoft_expert_agent.py
Keep the Edge0 server running in Terminal 1.
Open a second terminal and move to the Edge0 directory.
cd /path/to/Edge0Activate the virtual environment again in this shell.
source .venv/bin/activateMake sure requests is installed in the active environment.
pip install requestsStart the agent.
python microsoft_expert_agent.pyThe console UI itself is in English, while the sample accepts Korean questions and returns Korean answers.
Microsoft Technology Expert Agent
Microsoft Learn + Edge0-35B
Exit: /exit Clear history: /clear
Question> NativeAOT에서 Reflection.Emit을 사용할 수 있는지도 설명해주세요.
The host normalizes the Korean indirect question, translates it into English, and searches Microsoft Learn.
A real M2 MacBook Air 16GB test selected the following sources:
Grounding sources
[1] Native AOT deployment
[2] Introduction to AOT warnings
[3] ASP.NET Core support for Native AOT
While Edge0 is processing the prompt, the client prints an observable progress update every five seconds.
[ 2.6s] Sending request to Edge0-35B
[ 7.6s] Edge0 is processing; waiting for first token: 5s
[ 12.6s] Edge0 is processing; waiting for first token: 10s
...
[ 56.1s] First token received (TTFT 53.5s)
The English token stream is not translated token by token. The host buffers the stream until a full sentence is available, then translates that sentence to Korean.
A real measurement from an M2 MacBook Air 16GB produced:
Metrics
TTFT 53.47s
Total generation 82.11s
Completion tokens 119
Time after first 28.64s
Output speed 4.15 tok/s
These numbers represent one request with one particular prompt and grounding set. They will vary with the Mac model, cache state, prompt length, retrieval results, and output length.
Clear the in-memory conversation history:
/clear
Exit the agent:
/exit
The Python sample limits the number and size of Microsoft Learn search passages.
MAX_SOURCES = 3
MAX_SOURCE_CHARS = 1800Longer grounding can substantially increase TTFT on slower local hardware.
If the retrieved information is insufficient, increase these values and compare the resulting TTFT.
The sample does not keep previous Microsoft Learn grounding passages in the conversation history.
It only retains recent user questions and Edge0 English responses.
MAX_HISTORY_TURNS = 2Each new user request performs a fresh Microsoft Learn search and supplies only the grounding needed for that request.
This prevents the prompt from growing continuously across a long conversation.
The source file intentionally contains a small number of Korean string patterns.
They are functional input-normalization rules rather than UI text.
During testing, Korean indirect questions such as:
런타임에 새로운 실행 코드를 생성하는지도 설명해주세요.
could be mistranslated into a request asking how to generate executable code instead of whether runtime generation occurs.
The agent therefore rewrites a few known indirect-question forms into explicit yes/no questions before translation.
The current normalizer handles patterns similar to:
~할 수 있는지도~되는지도~하는지도~필요한지도
For example:
생성하는지도 설명해주세요.
is normalized into:
생성합니까?
그 여부도 설명해주세요.
This is not a general Korean rewriting system. Unknown sentence forms are left unchanged.
Time from starting the HTTP request until the first SSE token arrives.
It may include server queue time, tokenization, prompt prefill, and the first decode step.
Time from starting the request until the server sends [DONE].
The sample counts SSE events that contain generated content.
This is a lightweight measurement based on the current Edge0 streaming behavior.
If a future server version batches multiple generated tokens into one SSE event, use tokenizer-based counting instead.
Completion token count divided by the time between the first token and [DONE].
Separating TTFT from sustained decode speed is useful when tuning a local RAG system. A long grounding context can primarily increase TTFT even when steady-state token generation remains acceptable.
This is a proof-of-concept and experimentation sample.
It does not implement:
- authentication
- persistent per-user sessions
- multi-user concurrent serving
- a production request queue
- retry policies
- direct MCP protocol integration
- a retrieval reranker
- prompt-injection defenses
- structured audit logging
- document-level authorization filtering
The current Edge0 server should also not be treated as a production-grade multi-session continuous-batching inference server.
Use this sample for personal experiments or tightly scoped PoCs.
Exit the Python agent with:
/exit
Stop the Edge0 server in Terminal 1 with Ctrl+C.