CoreAIKit

SpotlightChat

Local RAG with Apple’s SpotlightSearchTool (WWDC26) driven by your own model. The search tool is a plain FoundationModels.Tool, so it rides behind any LanguageModel — here a Core AI zoo bundle via KitLanguageModel, not the system model. Everything runs on device.

The realistic on-device RAG shape, all behind one third-party model:

  1. spotlight_search (Apple’s system tool) finds candidate notes in the Core Spotlight index.
  2. fetch_note (this app’s own tool) reads a note’s full body from the app’s store.
  3. The model grounds its answer in the text it read.

Run

swift run -c release SpotlightChat                       # downloads qwen3-4B on first run
swift run -c release SpotlightChat --ask "What did I write about the Granite Pass attempt?"
swift run -c release SpotlightChat --system              # SystemLanguageModel baseline
swift run -c release SpotlightChat --model /path/to/bundle  # flagship zoo bundle (see note)

Expected (default question, qwen3-4B) — abridged: the real run also prints [index] setup lines, first-run download progress, and a full [transcript] dump, and the [spotlight] stream interleaves with the model’s tool calls rather than in this fixed order. The salient lines are:

> What did I write about the night hike?
  [spotlight] items[5] label=night hike: ... | Pine Hollow night hike | ...
  [fetch_note] note-003
  toolOutput Pine Hollow night hike: First night hike of the season. Headlamp died halfway …
[answer] You wrote about Pine Hollow — your first night hike of the season; your headlamp
         died halfway, so pack spare batteries next time.

What this demonstrates

Notes & gotchas (27.0 beta)