This agent uses the configured AI model’s embedding feature to transform a string of text into a vector embedding. At present, it is assumed that only one AI mode will be set in configuration.yaml. This agent will discover its type (ie OpenAI, Hugging Face, Vertex) and use the corresponding library to generate the embedding. It is up to the developer to match the correct embedding model with the configured AI model.
JSON and String inputs
This agent currently only accepts JSON-formatted inputs.
Either ensure the input is JSON, or put the agent before the compute-ai-embeddings agent in your pipeline:
pipeline:
- name: "convert-to-json"
type: "document-to-json"
input: "input-topic"
configuration:
text-field: "question"
- name: "compute-embeddings"
id: "step1"
type: "compute-ai-embeddings"
input: "input-topic"
output: "output-topic"
configuration:
model: "${secrets.open-ai.embeddings-model}" # This needs to match the name of the model deployment, not the base model
embeddings-field: "value.embeddings"
text: "{{ value.name }} {{ value.description }}"
batch-size: 10
# this is in milliseconds. It is important to take this value into consideration when using this agent in the chat response pipeline
# in fact this value impacts the latency of the response
# for latency sensitive applications, consider to set batch-size to 1 or flush-interval to 0
flush-interval: 500
Ollama models may compute embeddings but they are currently not as good as models provided by OpenAI or Huggingface. Ollama will provide models specifically for embeddings in the future.
- name: "compute-embeddings"
id: "step1"
type: "compute-ai-embeddings"
input: "input-topic"
output: "output-topic"
configuration:
model: "${secrets.open-ai.embeddings-model}" # This needs to match the name of the model deployment, not the base model
embeddings-field: "value.embeddings"
text: "{{ value.name }} {{ value.description }}"
batch-size: 10
# this is in milliseconds. It is important to take this value into consideration when using this agent in the chat response pipeline
# in fact this value impacts the latency of the response
# for latency sensitive applications, consider to set batch-size to 1 or flush-interval to 0
flush-interval: 500
Set HUGGING_FACE_PROVIDER=api and provide your Huggingface key and embeddings model to use the HF inference API:
When you use "loop-over", the agent executes for each element in a list instead of operating on the whole message. Use "record.xxx" to refer to the current element in the list.
The snippet above computes the embeddings for each element in the list "documents_to_retrieve". The list is expected to be a struct like this:
{
"documents_to_retrieve": [
{
"text": "the text of the first document"
},
{
"text": "the text of the second document"
}
]
}
After running the agent the contents of the list are:
{
"documents_to_retrieve": [
{
"text": "the text of the first document",
"embeddings": [1,2,3,4,5]
},
{
"text": "the text of the second document",
"embeddings": [6,7,8,9,10]
}
]
}
Topics
Input
Output
Configuration
Set up the OpenAI LLM . Add the compute-ai-embeddings agent:
Set up the Vertex LLM . Add the compute-ai-embeddings agent:
Refer to the to find a list of models.
Setup the Ollama .
Set up the Amazon Bedrock LLM . Add the compute-ai-embeddings agent:
Set up the Huggingface resource . Add the compute-ai-embeddings agent:
The above example will use the multilingual-e5-small Huggingface model locally via the .
It is possible to perform the same computation over a list of inputs - for example, a list of questions. You can take the as an example.
Structured and unstructured text
Implicit topic
Templating
Structured text
Implicit topic
Check out the full configuration properties in the .