To use Palantir-provided language models, AIP must first be enabled on your enrollment. You also must have permissions to use AIP developer capabilities. Using a custom model? Review Using custom models to create a semantic search workflow instead.
This page illustrates the process of building a notional end-to-end semantic search workflow using a Palantir-provided embedding model.
To begin, you need to generate embeddings and store them in an object type with a vector
type. Then, you can setup a semantic search workflow in Workshop, build an AIP Agent empowered workflow, or create a custom semantic search function for use in Workshop and AIP Logic.
Prerequisite:
Options:
We will use Pipeline Builder to embed text in the dataset as vectors with the Text to Embeddings expression. The expression takes a string and converts it to a vector using one of the Palantir-provided models - in our case the text-embedding-ada-002
embedding model.
These embeddings can then be added to the Ontology as a vector property.
If you would like more control around the generation of embeddings using Palantir-provided models, see Language models within Python Transforms.
Configuring a KNN object set within Workshop is an easy no-code way to build a semantic search workflow.
+ On a property
option, then from the list of properties in the menu, select your embedding property.Within this panel, you can configure:
For more customized semantic search logic, see the section on functions.
AIP Agents created in AIP Agent Studio are good for beginning semantic searches across your objects because they do not require any code. Learn more about incorporating semantic search with more control over the functionality.
Follow the instructions on the getting started guide to create an AIP Agent and either add Ontology context or an Ontology semantic search tool. This initial setup will enable you to ask the AIP Agent to semantically search the objects.
We can create a typescript repository and create a function to query our object type. The overall goal is to be able to take some user input, generate a vector using the same Palantir-provided model used earlier, and then do a KNN search over our object type. For more information on how to import Palantir-provided models, review Language models within Functions.
In the code snippet below, replace every instance of ObjectApiName
for your unique ObjectType. Note that the identifier may sometimes appear as objectApiName
with the first letter in lowercase.
Before proceeding, ensure that the entry "enableVectorProperties": true
is present in the functions.json
file in your Functions code repository. If this entry is not present, add it to functions.json
and commit the change to proceed. Contact your Palantir representative if you need further assistance.
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import { Function, Integer } from "@foundry/functions-api"; import { Objects, ObjectApiName } from "@foundry/ontology-api"; import { TextEmbeddingAda_002 } from "@foundry/models-api/language-models" export class MyFunctions { @Function() public async findRelevantObjects( query: string, kValue: Integer, ): Promise<ObjectApiName[]> { if (query.length < 1) { return [] } const embedding = await TextEmbeddingAda_002.createEmbeddings({inputs: [query]}).then(r => r.embeddings[0]); return Objects.search() .objectApiName() .nearestNeighbors(obj => obj.embeddings.near(embedding, {kValue: kValue})) .orderByRelevance() .take(kValue); } }
At this point, we have a function that can run semantic search to query objects with natural language. Remember to publish the function so the function can be used anywhere within Foundry.
kValue
to however many results you want returned, subject to the specified limits.Add the published function as a tool within AIP Logic. Instruct the language model to use the tool with a prompt similar to this:
Use the fetchRelevantObjects tool with a kValue of 5 to find the most related objects. Remember to add quotes around query when using the tool.