Jido.AI.Actions.OpenaiEx.Embeddings (Jido AI v0.5.2)
View SourceAction module for generating vector embeddings using OpenAI Ex.
This module supports embedding generation with both OpenAI and OpenRouter providers. Embeddings are useful for semantic search, clustering, classification, and other similarity-based operations.
Features
- Support for both OpenAI and OpenRouter providers
- Single string or batch processing of multiple strings
- Configurable dimensions and encoding format
- Consistent error handling and validation
Usage
# Generate embeddings for a single string
{:ok, result} = Jido.AI.Actions.OpenaiEx.Embeddings.run(
%{
model: %Jido.AI.Model{provider: :openai, model: "text-embedding-ada-002", api_key: "key"},
input: "Hello, world!"
},
%{}
)
# Generate embeddings for multiple strings
{:ok, result} = Jido.AI.Actions.OpenaiEx.Embeddings.run(
%{
model: %Jido.AI.Model{provider: :openai, model: "text-embedding-ada-002", api_key: "key"},
input: ["Hello", "World"]
},
%{}
)
Summary
Functions
Callback implementation for Jido.Action.on_after_run/1
.
Callback implementation for Jido.Action.on_after_validate_params/1
.
Callback implementation for Jido.Action.on_before_validate_params/1
.
Callback implementation for Jido.Action.on_error/4
.
Generates embeddings for the given input using OpenAI Ex.
Validates the input parameters for the Action.
Functions
Callback implementation for Jido.Action.on_after_run/1
.
Callback implementation for Jido.Action.on_after_validate_params/1
.
Callback implementation for Jido.Action.on_before_validate_params/1
.
Callback implementation for Jido.Action.on_error/4
.
@spec run(map(), map()) :: {:ok, map()} | {:error, any()}
@spec run(map(), map()) :: {:ok, %{embeddings: [[float()]]}} | {:error, String.t()}
Generates embeddings for the given input using OpenAI Ex.
Parameters
- params: Map containing:
- model: Either a %Jido.AI.Model{} struct or a tuple of {provider, opts}
- input: String or list of strings to generate embeddings for
- dimensions: Optional number of dimensions (model dependent)
- encoding_format: Optional format for the embeddings (:float or :base64)
- context: The action context containing state and other information
Returns
- } on success where embeddings is a list of vectors
- on failure
Validates the input parameters for the Action.
Examples
iex> defmodule ExampleAction do
...> use Jido.Action,
...> name: "example_action",
...> schema: [
...> input: [type: :string, required: true]
...> ]
...> end
...> ExampleAction.validate_params(%{input: "test"})
{:ok, %{input: "test"}}
iex> ExampleAction.validate_params(%{})
{:error, "Invalid parameters for Action: Required key :input not found"}