ReqLLM.Embedding (ReqLLM v1.0.0-rc.1)
View SourceEmbedding functionality for ReqLLM.
This module provides embedding generation capabilities with support for:
- Single text embedding generation
- Batch text embedding generation
- Model validation for embedding support
Currently only OpenAI models are supported for embeddings.
Summary
Functions
Builds a dynamic schema by composing the base schema with provider-specific options.
Generates embeddings for a single text input.
Generates embeddings for multiple text inputs.
Returns the base embedding options schema.
Returns the list of supported embedding model specifications.
Validates that a model supports embedding operations.
Functions
@spec dynamic_schema(module()) :: NimbleOptions.t()
Builds a dynamic schema by composing the base schema with provider-specific options.
Parameters
provider_mod- Provider module that defines provider_schema/0 function
@spec embed( String.t() | {atom(), keyword()} | struct(), String.t(), keyword() ) :: {:ok, [float()]} | {:error, term()}
Generates embeddings for a single text input.
Parameters
model_spec- Model specification in various formatstext- Text to generate embeddings foropts- Additional options (keyword list)
Options
:dimensions- Number of dimensions for embeddings:encoding_format- Format for encoding ("float" or "base64"):user- User identifier for tracking:provider_options- Provider-specific options
Examples
{:ok, embedding} = ReqLLM.Embedding.embed("openai:text-embedding-3-small", "Hello world")
#=> {:ok, [0.1, -0.2, 0.3, ...]}
@spec embed_many( String.t() | {atom(), keyword()} | struct(), [String.t()], keyword() ) :: {:ok, [[float()]]} | {:error, term()}
Generates embeddings for multiple text inputs.
Parameters
model_spec- Model specification in various formatstexts- List of texts to generate embeddings foropts- Additional options (keyword list)
Options
Same as embed/3.
Examples
{:ok, embeddings} = ReqLLM.Embedding.embed_many(
"openai:text-embedding-3-small",
["Hello", "World"]
)
#=> {:ok, [[0.1, -0.2, ...], [0.3, 0.4, ...]]}
@spec schema() :: NimbleOptions.t()
Returns the base embedding options schema.
This schema contains embedding-specific options that are vendor-neutral.
@spec supported_models() :: [String.t()]
Returns the list of supported embedding model specifications.
Examples
ReqLLM.Embedding.supported_models()
#=> ["openai:text-embedding-3-small", "openai:text-embedding-3-large", "openai:text-embedding-ada-002"]
@spec validate_model(String.t() | {atom(), keyword()} | struct()) :: {:ok, ReqLLM.Model.t()} | {:error, term()}
Validates that a model supports embedding operations.
Parameters
model_spec- Model specification in various formats
Examples
ReqLLM.Embedding.validate_model("openai:text-embedding-3-small")
#=> {:ok, %ReqLLM.Model{provider: :openai, model: "text-embedding-3-small"}}
ReqLLM.Embedding.validate_model("anthropic:claude-3-sonnet")
#=> {:error, :embedding_not_supported}