windlass.providers.embeddings.openai¶
openai
¶
OpenAI embedding models.
Works with OpenAI and any OpenAI-compatible embedding endpoint. Install with::
pip install "windlass[openai]"
Example
from windlass import Windlass # doctest: +SKIP emb = Windlass.embedding("openai", model="text-embedding-3-small") # doctest: +SKIP len(emb.embed_one("hello")) # doctest: +SKIP 1536
OpenAIEmbedder
¶
OpenAIEmbedder(
model: str = "",
*,
api_key: str | None = None,
base_url: str | None = None,
dimensions: int | None = None,
**config: Any
)
Bases: Embedder
Embeddings via the official openai SDK.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model id, e.g. |
''
|
api_key
|
str | None
|
Credential. Falls back to |
None
|
base_url
|
str | None
|
Endpoint override for compatible gateways. |
None
|
dimensions
|
int | None
|
Request a reduced dimensionality. Supported by the
|
None
|
**config
|
Any
|
Forwarded to :class: |
{}
|
Raises:
| Type | Description |
|---|---|
MissingDependencyError
|
When |
AuthenticationError
|
When no API key can be found. |
Source code in src\windlass\providers\embeddings\openai.py
default_model
classmethod
¶
native
¶
aembed_texts
async
¶
Embed a batch via the embeddings endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
list[str]
|
The texts to embed. |
required |
kind
|
str
|
Ignored — OpenAI embeddings are symmetric. |
'document'
|
Returns:
| Type | Description |
|---|---|
list[list[float]]
|
One vector per input, in request order. |
Raises:
| Type | Description |
|---|---|
ProviderError
|
For any API failure, translated from the SDK error. |