FoundationModels and Core Data

Hi, I have an app that uses Core Data to store user information and display it in various views. I want to know if it's possible to easily integrate this setup with FoundationModels to make it easier for the user to query and manipulate the information, and if so, how would I go about it? Can the model be pointed to the database schema file and the SQLite file sitting in the user's app group container to parse out the information needed? And/or should the NSManagedObjects be made @Generable for better output? Any guidance about this would be useful.

Answered by DTS Engineer in 842785022

The FoundationModels framework provides a way that allows you to integrate your own data with the Apple Foundation Models, that is, tool calling. For more details on this topic, please see the following article:

I don't think you can mark NSManagedObject as Generable, because to do so, all the types used in NSManagedObjects must be Generable, which isn't realistic.

If you need to have the Foundation Models generate a Core Data managed object, consider creating a struct that contains the information you need, and making it Generable. After the models generate the struct, you convert it to NSManagedObject, which can then be persisted to your Core Data store.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

The FoundationModels framework provides a way that allows you to integrate your own data with the Apple Foundation Models, that is, tool calling. For more details on this topic, please see the following article:

I don't think you can mark NSManagedObject as Generable, because to do so, all the types used in NSManagedObjects must be Generable, which isn't realistic.

If you need to have the Foundation Models generate a Core Data managed object, consider creating a struct that contains the information you need, and making it Generable. After the models generate the struct, you convert it to NSManagedObject, which can then be persisted to your Core Data store.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

FoundationModels and Core Data
 
 
Q