把 app 搜尋升級成 LLM 可用的 grounded retrieval layer
這場 session 示範 SpotlightSearchTool 如何讓 LanguageModelSession 直接查 Core Spotlight index,並用 index delegate、guidance profiles、knowledge providers、custom pipeline stages 與 Evaluations framework 讓回答更可控。
Apple 的方向不是讓 LLM 憑記憶回答 app 內容,而是把既有 Core Spotlight 捐贈資料變成模型可呼叫、可顯示、可評估的 tool-backed search layer。
這支影片在拆 app 內 LLM 搜尋的四個層次
模型先查 app index,再產生回答
SpotlightSearchTool 採用 Foundation Models Tool protocol,讓模型自行產生查詢參數,從 Core Spotlight 取回結果後再回答。
delegate 補回可讀的完整 item
Spotlight 某些 metadata 是壓縮表示,能搜但不一定能被模型讀取。新的 delegate method 可依 identifier 回傳完整 CSSearchableItem。
文字回答與搜尋結果可以分開呈現
assistant UI 可顯示 session response;list UI 可直接讀取 tool 的 search replies。批次回傳與 query token 可避免大型結果集讓畫面不同步。
guidance 與 pipeline 讓搜尋更貼近 domain
guidance profiles 限縮搜尋能力,knowledge providers 解 reference,custom pipeline stages 則把計算或 sentiment analysis 放到 Spotlight pipeline。
從 Core Spotlight index 到可評估 LLM search
先確保 app 內容已正確 donate
影片前提是 app 已把 searchable items 或 Apple Intelligence entities 放進 Core Spotlight,包含可查詢的 title、location、date、notes 等 metadata。
建立並加入 SpotlightSearchTool
匯入 CoreSpotlight 與 FoundationModels,建立 tool,選擇 model,然後把 tool 加進 LanguageModelSession。
用 index delegate 做 full item hydration
當工具需要模型讀取完整內容時,透過 searchableItems(forIdentifiers:) 回補完整 CSSearchableItem 與額外 attributes。
依 app domain 限縮與擴充搜尋能力
用 guidance profiles 告訴模型哪些 query capabilities 有用;用 contact resolver 等 provider 解「我附近」「我的朋友」這類 reference。
建立 result coverage evaluation
用 seed samples 或 Sample Generation APIs 建 dataset,期待 trajectory 包含 SpotlightSearchTool call,並用 expected identifiers 衡量結果覆蓋率。
實務啟發:搜尋品質先取決於 index 品質
這場 session 的核心不是「LLM 會幫你搜」,而是「LLM 只能合理使用你給它的可搜尋資料」。如果 Core Spotlight 裡的 metadata 粗糙、identifier 不穩、delegate 無法回補完整內容,模型回答就會變成漂亮但不可靠的摘要。
SpotlightSearchTool、LanguageModelSession、CSSearchableIndexDelegate、searchableItems(forIdentifiers:)、guidance profiles、knowledge providers、custom pipeline stages、Evaluations framework。風險與測試清單
第一,測 tool 是否真的被呼叫,而不是模型憑世界知識回答。第二,測 expected items 是否出現在結果與最終回答中。第三,測 large result set 的 batch replies 與 query token 是否讓 UI 正確更新。
custom pipeline stages 很有彈性,但也會把 app logic、ML 推論與搜尋結果混在一起。建議把每個 stage 的 input/output 型別、排序策略、錯誤 fallback 與可顯示資料都寫成明確契約,再放進 eval suite。
- 01
SpotlightSearchTool讓 Foundation Models 透過 tool calling 查 Core Spotlight,將 app 內容拿來 grounding 回答。 - 02index delegate 負責回補模型可讀的完整 item;guidance profiles 與 providers 則負責讓查詢更貼近 app domain。
- 03LLM search 需要 evaluation:用 expected identifiers、trajectory 與 result coverage 測工具呼叫和最終回答品質。