Functions enable code authors to write logic that can be executed quickly in operational contexts, such as dashboards and applications designed to empower decision-making processes. This logic is executed on the server side in an isolated environment.
Notably, Functions include first-class support for authoring logic based on the Foundry ontology. This includes support for reading properties of various object types, traversing links, and flexibly making ontology edits.
Common use cases for Functions include:
The languages supported by Functions are TypeScript ↗ and Python (Beta)↗.
To get started using Functions in Foundry, we recommend the following tutorials:
Not all features are supported by both languages. Refer to the chart below for language support for specific features.
Functions capability | Supported in Typescript | Supported in Python | Description |
---|---|---|---|
Ontology object support | Yes | Yes | The ability to access Ontology objects in your function. |
Ontology edits support | Yes | Yes | The ability to edit Ontology objects in your function. |
Queryable in Workshop | Yes | Yes | Invoking a function from a workshop app. |
Usable in Pipeline Builder | No | Yes | Calling a function from Pipeline Builder pipelines. |
Functions on models support | Yes | No | Writing functions that can be embedded within a model. |
Semantic search support | Yes | No | Use functions to create vectors for semantic search. |
External API call support | Yes | Yes | Querying external services from within functions. |
Serverless execution support | Yes | Yes | A serverless function will be spun up on demand when invoked. Refer to serverless Python functions below for more information. |
Deployed execution support | No | Yes | A deployed function will have dedicated resources allocated to it, ready to serve requests. |
Calling function from API Gateway | Yes | Yes | The ability to hit a Query function from the API gateway. |
Marketplace support | Yes | No | The ability to package and ship functions via Marketplace. |
Currently, each serverless function is allocated a total of 60 seconds of wall time to run. This includes 30 seconds of CPU time and a 30-second buffer for any network delays. The function will fail if the timeout is exceeded.
Currently, each deployed function is allocated a total of 60 seconds of wall time to run. The function will fail if the timeout is exceeded.
If serverless Python functions are enabled for your enrollment, new repositories will use serverless functions by default. We recommend using serverless functions instead of deployed functions for most use cases. With serverless functions, you can have multiple versions of a single function available on demand, making upgrades safer. Serverless functions are in beta and may not be available on all enrollments. If this functionality is not enabled on your enrollment, you can use deployed Python functions as an alternative.
There are also some cases where deployed functions are preferred or must be used instead of serverless, but these are not common. If available, serverless functions are preferred for several reasons: