Querying a live deployment (modeling objectives) from workshop or functions, but not samplewise (like with scenarios)

183 Views Asked by At

I have an optimization algorithm deployed as a live deployment. It takes a set of objects and returns a set of objects with potentially different size. This works just fine when I'm using the REST api.

The problem is, I want to let the user of the workshop app query the model with a set of objects. The returned objects need to be written back to the ontology.

  • I looked into an action backed function but it seems like I can't query the model from a function?!
  • I looked into webhooks but it seems to not fit the purpose and I also would need to handle the API key and can't write back to the ontology?!
  • I know how to query the model with scenarios but it is per sample and that does not fit the purpose, plus I cant write back to the ontology.

My questions:

  • Is there any way to call the model from a function and write the return back to the ontology?
  • Is there any way to call a model from workshop with a set of objects and write back to the ontology?
  • Is modeling objectives just the wrong place for this usecase?
  • Do I need to implement the optimization in Functions itself?

1

There are 1 best solutions below

0
On BEST ANSWER

I answered the questions, as well I tried to address some of the earlier points.

  • Q: "I looked into an action backed function but it seems like I can't query the model from a function?!"
  • A: That is correct, at this time you can't query a model from a function. However there are javascript based linear optimization libraries which can be used in a function.
  • Q: "I looked into webhooks but it seems to not fit the purpose and I also would need to handle the API key and can't write back to the ontology?!"
  • A: Webhooks are for hitting resources on networks where a magritte agent are installed. So if you have like a flask app on your corporate network you could hit that app to conduct the optimization. Then set the webhook as "writeback" on an action and use the webhook outputs as inputs for a ontology edit function.
  • Q: "I know how to query the model with scenarios but it is per sample and that does not fit the purpose, plus I cant write back to the ontology."
  • A: When querying a model via workshop you can pass in a single object as well as any objects linked in a 1:1 relationship with that object. This linking is defined in the modeling objective modeling api. You are correct to understand you can't pass in an arbitrary collection of objects. You can write back to the ontology however, you have to set up an action to apply the scenario back to the ontology (https://www.palantir.com/docs/foundry/workshop/scenarios-apply/).
  • Q: "Is there any way to call the model from a function and write the return back to the ontology?"
  • A: Not from an ontology edit function
  • Q: "Is there any way to call a model from workshop with a set of objects and write back to the ontology?"
  • A: Only object sets where the objects have 1:1 links within the ontology. You can writeback by appyling the scenario (https://www.palantir.com/docs/foundry/workshop/scenarios-apply/).
  • Q: "Is modeling objectives just the wrong place for this usecase? Do I need to implement the optimization in Functions itself?"
  • A: If you can write the optimization in an ontology edit function it will be quite a bit more straightforward. The main limitation of this is you have to use Typescript which is not as commonly used for this kind of thing as Python. There are some basic linear optimization libraries available for JS/TS.