Apple Developer onepage/WWDC26
#WWDC26#CoreSpotlight#FoundationModels2026-06-08 · 16:25

把 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。

Apple Developer · WWDC26 · Video ID: sij24ohbRSgApple Developer 官方頁
Content map

這支影片在拆 app 內 LLM 搜尋的四個層次

Grounding

模型先查 app index,再產生回答

SpotlightSearchTool 採用 Foundation Models Tool protocol,讓模型自行產生查詢參數,從 Core Spotlight 取回結果後再回答。

Hydration

delegate 補回可讀的完整 item

Spotlight 某些 metadata 是壓縮表示,能搜但不一定能被模型讀取。新的 delegate method 可依 identifier 回傳完整 CSSearchableItem。

UI

文字回答與搜尋結果可以分開呈現

assistant UI 可顯示 session response;list UI 可直接讀取 tool 的 search replies。批次回傳與 query token 可避免大型結果集讓畫面不同步。

Customization

guidance 與 pipeline 讓搜尋更貼近 domain

guidance profiles 限縮搜尋能力,knowledge providers 解 reference,custom pipeline stages 則把計算或 sentiment analysis 放到 Spotlight pipeline。

Implementation flow

從 Core Spotlight index 到可評估 LLM search

1

先確保 app 內容已正確 donate

影片前提是 app 已把 searchable items 或 Apple Intelligence entities 放進 Core Spotlight,包含可查詢的 title、location、date、notes 等 metadata。

2

建立並加入 SpotlightSearchTool

匯入 CoreSpotlight 與 FoundationModels,建立 tool,選擇 model,然後把 tool 加進 LanguageModelSession。

3

用 index delegate 做 full item hydration

當工具需要模型讀取完整內容時,透過 searchableItems(forIdentifiers:) 回補完整 CSSearchableItem 與額外 attributes。

4

依 app domain 限縮與擴充搜尋能力

用 guidance profiles 告訴模型哪些 query capabilities 有用;用 contact resolver 等 provider 解「我附近」「我的朋友」這類 reference。

5

建立 result coverage evaluation

用 seed samples 或 Sample Generation APIs 建 dataset,期待 trajectory 包含 SpotlightSearchTool call,並用 expected identifiers 衡量結果覆蓋率。

實務啟發:搜尋品質先取決於 index 品質

這場 session 的核心不是「LLM 會幫你搜」,而是「LLM 只能合理使用你給它的可搜尋資料」。如果 Core Spotlight 裡的 metadata 粗糙、identifier 不穩、delegate 無法回補完整內容,模型回答就會變成漂亮但不可靠的摘要。

導入時要把 Core Spotlight donation 當成產品資料契約:哪些欄位可被搜尋、哪些欄位可被模型讀取、哪些欄位只在 hydration 時補上,都要與隱私和 UI 顯示策略一起設計。
API / framework 重點SpotlightSearchTool、LanguageModelSession、CSSearchableIndexDelegate、searchableItems(forIdentifiers:)、guidance profiles、knowledge providers、custom pipeline stages、Evaluations framework。
遷移注意事項若既有搜尋只為人類 UI 設計,可能缺少模型需要的 structured metadata、穩定 identifiers、批次結果 UI、以及能驗證 result coverage 的測試資料。

風險與測試清單

第一,測 tool 是否真的被呼叫,而不是模型憑世界知識回答。第二,測 expected items 是否出現在結果與最終回答中。第三,測 large result set 的 batch replies 與 query token 是否讓 UI 正確更新。

custom pipeline stages 很有彈性,但也會把 app logic、ML 推論與搜尋結果混在一起。建議把每個 stage 的 input/output 型別、排序策略、錯誤 fallback 與可顯示資料都寫成明確契約,再放進 eval suite。

// TL;DR