← All courses ← Course home

Lesson 01 of 05

Keep search on the phone

Private notes stay on the device. Apple gives you SpotlightSearchTool. A BM25 plus dense plus rerank stack is something you own.

Agent brief (llms.md)

Users will not put a diary, a medical note, or a work memo into a public search API. EDGE FDE retrieval means the index and the query stay on iOS 27 or macOS 27.

Two honest paths

Path A, Apple's tool. Donate items to Core Spotlight. Add SpotlightSearchTool to a LanguageModelSession. The model writes queries. You hydrate full items through a Spotlight delegate. WWDC26 session 246 covers this. It is local RAG. It is not a BM25 type, and it is not a Core AI embedding index you control.

Path B, a stack you own. Chunk files, score words with BM25 you implement, embed chunks with a Core AI catalog embedder, merge and rerank, then hand a small list to the context packer. This course builds Path B and keeps Path A named so you do not pretend they are the same API.

DonateCore Spotlight items
ToolSpotlightSearchTool
SessionGrounded reply
ChunkYour notes
BM25Your scorer
DenseCore AI embed
RerankShort list

You can use both. Spotlight is the fast product path when donated metadata is good. The owned stack is for files Spotlight should not see, or when you need a ranker you can unit test. Path A is Swift on the session. Path B can build the index on a Mac in Python, then query it on the phone in Swift.

import FoundationModels

// Illustrative. Confirm SpotlightSearchTool in the installed SDK (WWDC26 246).
let session = LanguageModelSession(tools: [SpotlightSearchTool()])
Honesty rule. If a lesson says BM25, the code is yours. If it says SpotlightSearchTool, the type is Apple's.

Next, chunk notes so both paths have something to find.

Key concepts

  • Path A donates to Core Spotlight and adds SpotlightSearchTool to the session.
  • Path B is chunk, BM25 you write, Core AI embed, merge rerank, then pack.
  • SpotlightSearchTool is local RAG, not BM25 or a Core AI index you control.
  • Both paths can coexist.

Takeaways

  • If a lesson says BM25, the code is yours. If it says SpotlightSearchTool, the type is Apple's.
  • Users will not put private notes into a public search API.
  • Owned stack is for testable rankers and hidden files.