Embedding
Embedding
any_llm.embedding(model, inputs, *, provider=None, api_key=None, api_base=None, **kwargs)
Create an embedding.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
str
|
Model identifier. Recommended: Use with separate |
required |
provider
|
str | ProviderName | None
|
Recommended: Provider name to use for the request (e.g., 'openai', 'mistral'). When provided, the model parameter should contain only the model name. |
None
|
inputs
|
str | list[str]
|
The input text to embed |
required |
api_key
|
str | None
|
API key for the provider |
None
|
api_base
|
str | None
|
Base URL for the provider API |
None
|
**kwargs
|
Any
|
Additional provider-specific parameters |
{}
|
Returns:
Type | Description |
---|---|
CreateEmbeddingResponse
|
The embedding of the input text |
Source code in src/any_llm/api.py
any_llm.aembedding(model, inputs, *, provider=None, api_key=None, api_base=None, **kwargs)
async
Create an embedding asynchronously.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
str
|
Model identifier in format 'provider/model' (e.g., 'openai/text-embedding-3-small'). If provider is provided, we assume that the model does not contain the provider name. Otherwise, we assume that the model contains the provider name, like 'openai/gpt-4o'. |
required |
provider
|
str | ProviderName | None
|
Provider name to use for the request. If provided, we assume that the model does not contain the provider name. Otherwise, we assume that the model contains the provider name, like 'openai:gpt-4o'. |
None
|
inputs
|
str | list[str]
|
The input text to embed |
required |
api_key
|
str | None
|
API key for the provider |
None
|
api_base
|
str | None
|
Base URL for the provider API |
None
|
**kwargs
|
Any
|
Additional provider-specific parameters |
{}
|
Returns:
Type | Description |
---|---|
CreateEmbeddingResponse
|
The embedding of the input text |