One Logo Pool Ball
_CoreSpotlight_FoundationModels · IOS API REFERENCE

SpotlightSearchTool

struct · iOS 27.0+ · SDK 27.1

struct SpotlightSearchTool

A tool you use to make your app’s custom data available to Foundation Models. The `SpotlightSearchTool` type implements the protocol that Foundation Models use to run custom tools when resolving prompts. If you implement intelligent features using the Foundation Models framework, you can use this tool to provide your app’s data to the model as additional contextual information. The model can use this additional data to answer questions specific to your app’s content. For example, a note-taking app that runs the prompt “Find my meeting notes from last Tuesday” can use this tool to make its notes available to the model. Create an instance of `SpotlightSearchTool` before configuring a <doc://com.apple.documentation/documentation/foundationmodels/languagemodelsession> object to run prompts. Configure the tool with the sources and options you want to use to search your particular content. For example, you can direct the tool to search your app’s Spotlight index, files and directories your app created, or both. Use the tool options to offer guidance on how to perform searches efficiently on your content. The following example shows you how to create and configure this tool with a custom source. ```swift import CoreSpotlight import FoundationModels // Search the app’s Spotlight index and fetch specific attributes for each result. var csSource = CoreSpotlightSource(fetchAttributes: [.subject, .authorNames, .contentDescription]) csSource.sourceOptions = [.allowMail] csSource.maximumResultCount = 20 // Create and configure the search tool. let configuration = SpotlightSearchTool.Configuration(sources: [coreSpotlight(csSource)]) let tool = SpotlightSearchTool(configuration: configuration) // Set up the Foundation Models session and run a prompt. let session = LanguageModelSession(tools: [tool]) let response = try await session.respond(to: "Find my notes about the project deadline") ```

Members (9)

get · iOS 27.0+

parameters

TypeScript
get parameters(): _FoundationModels_GenerationSchema
Swift declaration
var parameters: GenerationSchema { get }

The schema for the parameters this tool accepts. The Spotlight search tool implements this property as part of its conformance to the <doc://com.apple.documentation/documentation/foundationmodels/tool> protocol.

get · iOS 27.0+

description

TypeScript
get description(): string
Swift declaration
var description: String { get }

A natural language description of when and how to use the Spotlight search tool. The Spotlight search tool implements this property as part of its conformance to the <doc://com.apple.documentation/documentation/foundationmodels/tool> protocol.

init · iOS 27.0+

init

TypeScript
static init(configuration?: SpotlightSearchTool_Configuration): SpotlightSearchTool
Swift declaration
init(configuration: SpotlightSearchTool.Configuration = Configuration(sources: [.coreSpotlight]))
get · iOS 27.0+

configuration

TypeScript
get configuration(): SpotlightSearchTool_Configuration
Swift declaration
let configuration: SpotlightSearchTool.Configuration

The configuration details for the search tool. Use this property to specify the configuration data you want to use with the tool. You use this property to configure the data sources for the tool to search, guidance on how to perform searches, and any custom processing steps your app provides. For more information on how to configure and use ``SpotlightSearchTool``, see <doc:making-your-indexed-content-available-to-foundation-models>.

get · iOS 27.0+

searchResults

TypeScript
get searchResults(): SDKHandle
Swift declaration
var searchResults: some AsyncSequence<SpotlightSearchTool.SearchReply, Never> { get }

An asynchronous stream that delivers the results of a search to your app for processing. Use this property to monitor the search results as the tool generates them. Each time the model calls the Spotlight search tool’s <doc://com.apple.documentation/documentation/foundationmodels/tool/call(arguments:)> method, the tool generates one or more ``SearchReply`` structures with information about the results. Use this information to track the tool’s behavior while responding to the model’s requests. Monitor the asynchronous stream using a `for await` loop in a separate task, as shown in the following example: ```swift let tool = SpotlightSearchTool() let session = LanguageModelSession(tools: [tool]) Task { for await result in tool.searchResults { // Process each search result as it arrives. } } let response = try await session.respond(to: "Show me recent emails from Shelly”) ``` For more information about how to process search results, see <doc:making-your-indexed-content-available-to-foundation-models>.

get · iOS 27.0+

includesSchemaInInstructions

TypeScript
get includesSchemaInInstructions(): boolean
Swift declaration
var includesSchemaInInstructions: Bool { get }

A Boolean value that indicates whether to inject the model’s name, description, and parameters schema into the instructions of sessions. The Spotlight search tool implements this property as part of its conformance to the <doc://com.apple.documentation/documentation/foundationmodels/tool> protocol.

method · iOS 27.0+

call

TypeScript
call(arguments_: _FoundationModels_GeneratedContent): Promise<SDKHandle>
Swift declaration
nonisolated(nonsending) func call(arguments: GeneratedContent) async throws -> some PromptRepresentable

Performs the tool's action when a language model wants to use this tool. If errors are throw in the body of this method, the framework wraps them in a ``LanguageModelSession/ToolCallError`` and rethrows them at the call site of ``LanguageModelSession/respond(to:options:)-(Prompt,_)``. - Note: This method may be invoked concurrently with itself or with other tools.

get · iOS 27.0+

name

TypeScript
get name(): string
Swift declaration
var name: String

The unique name for the Spotlight search tool. The Spotlight search tool implements this property as part of its conformance to the <doc://com.apple.documentation/documentation/foundationmodels/tool> protocol.

set · iOS 27.0+

name

TypeScript
set name(value: string)
Swift declaration
var name: String

The unique name for the Spotlight search tool. The Spotlight search tool implements this property as part of its conformance to the <doc://com.apple.documentation/documentation/foundationmodels/tool> protocol.

Skipped declarations

No declarations were skipped in this snapshot.

All _CoreSpotlight_FoundationModels types →