Tahoe Intelligence: on-device AI for an Obsidian vault
An Obsidian plugin that answers questions from your notes with citations, finds related notes and duplicate ideas, and helps with writing, using Apple's on-device model or a local Ollama model.

The problem
Apple's on-device model is free and private, but it is reachable only from Swift, its context window is small, and an Obsidian plugin is JavaScript running in Electron. Most of the work went into bridging those three facts.
Talking to Apple Intelligence: a Swift helper
The plugin ships the Swift source of a helper inside its bundle (src/helper.swift, imported as a string in src/engine.js). On first use, Engine.compileHelper checks for Xcode's command line tools with xcode-select -p, so a missing install never triggers a system prompt. If they are there, it writes the source to ~/Library/Caches/tahoe-intelligence/ and builds it with xcrun --sdk macosx swiftc -O. The binary name includes HELPER_VERSION, so a new helper is rebuilt.
Engine.start spawns the binary once and keeps it running. The protocol is JSON lines over stdin and stdout. Each request carries an id, and the helper's handle function dispatches on op: status, generate, embed, image, cancel, plus Reminders and Calendar ops that are off by default. Inside, generate uses the Foundation Models framework (SystemLanguageModel.default, LanguageModelSession). Streamed output is sent as delta messages, or as a reset when a new snapshot doesn't extend the previous one. Structured output works by turning a small JSON schema spec into a DynamicGenerationSchema (buildSchema).
The model handles one request at a time, so Engine.serial chains every generate call onto a single promise queue.
Ollama as a fallback
Engine.provider picks Apple Intelligence unless the setting says Ollama or Apple's model is unavailable. Then it asks Ollama for its models at 127.0.0.1:11434/api/tags and picks the one closest to 5 GB unless you've chosen one. generateOllama posts to /api/chat and parses the streamed NDJSON. toJsonSchema turns the same schema spec into JSON Schema for Ollama's format field, so features that rely on structured output work with either engine. Ollama is only used for text generation. Embeddings always come from the Mac, so the search features need macOS.
Embeddings and the meaning index
The helper's embed op uses NLContextualEmbedding for English. It splits text into chunks of up to 900 characters (chunks), embeds at most 24 of them, mean-pools every token vector into one vector, and returns the vectors as base64 Float32.
SemanticIndex in src/index.js keeps one vector per note, embedding the title plus plain text (plainText in src/vault.js strips front matter, code blocks and embeds). It skips notes under 40 characters and excluded folders. Raw embeddings made every note look alike, so build() subtracts the vault's mean vector and normalises before cosine comparison.
Storage is two files per vault in ~/Library/Caches/tahoe-intelligence: index-<hash>.bin (vectors back to back) and .meta.json (paths, mtimes, dimension). save() writes .tmp files and renames them into place, so a crash can't leave half an index. Saves happen at most once a minute, and on quit.
Updates are incremental. On startup, scan() queues only notes whose mtime differs from the stored one. Edits are debounced by 5 seconds (enqueueSoon), then embedded in batches of 8 with a 30 ms pause between batches. Renames move the stored vector instead of re-embedding.
Meaning alone handles short notes and formulas badly, so src/keywords.js adds a tf-idf KeywordIndex. hybridRelated blends the two half and half for Related notes. isHub leaves out daily notes, weekly reviews and maps, since they relate to everything.
Ask your notes, with citations
retrieve in src/features/ask.js has four steps:
- Ask the model for a short sample answer, and embed the question plus that answer, since a sample answer finds better matches than a bare question.
- Take the 10 nearest notes by meaning, plus up to 8 notes that share the question's rarer words.
- Split those notes into passages of about 650 characters, embed them in batches of 16 (cached by hash), and score them: 0.55 passage meaning, 0.2 note score, 0.12 word overlap, 0.15 title match.
- Keep the top 6 passages, at most 2 per note, so answers draw on several notes.
The passages go to the model as numbered sources, with instructions to use only them and cite [1], [2]. renderAnswer replaces each number with a [[note|1]] wiki link. Numbers that match no source are dropped.
Small context windows
The comment in engine.js puts the on-device model at about 4,000 tokens, prompt and answer together, so INPUT_CHAR_BUDGET is 7,000 characters. clip() keeps the first 80% of the budget and the last 15% of the text. Features set smaller limits, such as 2,200 characters per note when comparing duplicates and 6,200 for the Ask prompt. Weekly review and maps of content read one note per call into a one-line summary, then write from the summaries. If the window still overflows, the helper maps exceededContextWindowSize to a context code and the UI suggests a shorter selection.
Where the network is used
The JavaScript loads Node's http module, not https. The only requests in the source are the two in engine.js, both to 127.0.0.1:11434. Generation and embedding run in a local process on the Mac. The helper and index stay in ~/Library/Caches, which isn't synced.
More write-ups: A notebook inside a note · Refraction in CSS and SVG · Shipping nine packages