---
title: "Add dense search with Core AI"
lesson_id: "04"
---

# Add dense search with Core AI

- **Lesson ID:** 04
- **Goal:** Embed chunks with a documented Core AI or Foundation Models embedder and rank by cosine.
- **Human lesson:** [04-dense-search-core-ai.html](04-dense-search-core-ai.html)

## Prerequisites

- Lesson 02 chunks.
- Xcode 27 with Core AI.

## Inputs, outputs, and artifacts

- **Inputs:** Chunks and a query.
- **Outputs:** Top dense hits, or an honest "no embedder" fallback.

## Agent build steps

1. Look up a catalog embedder or Foundation Models helper. Confirm names.
2. Do not treat SystemLanguageModel as an embedder.
3. Prepare once and re-embed on edit.
4. If no embedder exists, keep BM25 + Spotlight and document the gap.
5. Refuse a hosted embed API.

## Constraints

Honest APIs. iOS 27 and macOS 27. No em dashes.

## Key concepts

- Embed each chunk once, embed the query, rank by cosine similarity.
- Use a Core AI catalog embedder, not `CoreAILanguageModel` and not a chat prompt that returns a vector.
- Dense finds meaning when words do not match. It is weak on exact ids.
- Write model name and dimension beside the index file.

## Takeaways

- Do not prompt `SystemLanguageModel` to return a vector.
- If no on-device embedder exists, ship BM25 plus Spotlight and document the limit.
- Do not call a hosted embedding API.

## Acceptance checks

- Dense index is shown.
- Language-model-as-embedder is rejected.
- Agent brief link is present.
