Implementing EntityQuery Against a Custom External SQLite Database

In our application, we have dynamic records (sessions, workspaces, and logs) stored in a local SQLite database that is modified in real-time by a background command-line tool. We want Siri to resolve these as AppEntity types (e.g., 'Siri, show status of [Session Name]' or 'Siri, export log for [Project]').

Since EntityQuery requires returning list/suggested entities, how do we efficiently synchronize or query the external SQLite file from the App Intent extension? Are there file-locking or concurrency issues we should be aware of when the CLI tool is writing to the database while Siri is querying it? Is there a performance penalty or memory limit when returning thousands of dynamically generated AppEntity instances in suggestedEntities()? Should we implement custom indexing or virtual tables to support Siri's fuzzy name matching?

Answered by Frameworks Engineer in 891869022

Synchronization between processes is always tricky. NSFileCoordinator can help share access more safely

Alternatively you could implement an XPC service that owns the database and exposed an interface that allows both the CLI and the App to access resources through a shared mediator

As for suggestedEntities(), there can be performance issues if you return 1000s of entities, I would suggest returning a handful of the most recently created/modified entities. Think of these as "suggestions". If you want more detailed search in Shortcuts, checkout EntityPropertyQuery which can query based on Entity properties.

Siri search is primarily based on Spotlight, so you need to donate IndexedEntities for them to be surfaced (assuming your types implement a Schema)

Synchronization between processes is always tricky. NSFileCoordinator can help share access more safely

Alternatively you could implement an XPC service that owns the database and exposed an interface that allows both the CLI and the App to access resources through a shared mediator

As for suggestedEntities(), there can be performance issues if you return 1000s of entities, I would suggest returning a handful of the most recently created/modified entities. Think of these as "suggestions". If you want more detailed search in Shortcuts, checkout EntityPropertyQuery which can query based on Entity properties.

Siri search is primarily based on Spotlight, so you need to donate IndexedEntities for them to be surfaced (assuming your types implement a Schema)

Implementing EntityQuery Against a Custom External SQLite Database
 
 
Q