OpenAITextEmbedder
Embeds strings using OpenAI models.
Basic Information
- Type:
haystack_integrations.embedders.openai_text_embedder.OpenAITextEmbedder
Inputs
| Parameter | Type | Default | Description |
|---|---|---|---|
| text | str | Text to embed. |
Outputs
| Parameter | Type | Default | Description |
|---|---|---|---|
| embedding | List[float] | A dictionary with the following keys: - embedding: The embedding of the input text. - meta: Information about the usage of the model. | |
| meta | Dict[str, Any] | A dictionary with the following keys: - embedding: The embedding of the input text. - meta: Information about the usage of the model. |
Overview
Embeds strings using OpenAI models.
You can use it to embed user query and send it to an embedding Retriever.
Usage Example
components:
OpenAITextEmbedder:
type: components.embedders.openai_text_embedder.OpenAITextEmbedder
init_parameters:
Parameters
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
| api_key | Secret | Secret.from_env_var('OPENAI_API_KEY') | The OpenAI API key. You can set it with an environment variable OPENAI_API_KEY, or pass with this parameter during initialization. |
| model | str | text-embedding-ada-002 | The name of the model to use for calculating embeddings. The default model is text-embedding-ada-002. |
| dimensions | Optional[int] | None | The number of dimensions of the resulting embeddings. Only text-embedding-3 and later models support this parameter. |
| api_base_url | Optional[str] | None | Overrides default base URL for all HTTP requests. |
| organization | Optional[str] | None | Your organization ID. See OpenAI's production best practices for more information. |
| prefix | str | A string to add at the beginning of each text to embed. | |
| suffix | str | A string to add at the end of each text to embed. | |
| timeout | Optional[float] | None | Timeout for OpenAI client calls. If not set, it defaults to either the OPENAI_TIMEOUT environment variable, or 30 seconds. |
| max_retries | Optional[int] | None | Maximum number of retries to contact OpenAI after an internal error. If not set, it defaults to either the OPENAI_MAX_RETRIES environment variable, or set to 5. |
| http_client_kwargs | Optional[Dict[str, Any]] | None | A dictionary of keyword arguments to configure a custom httpx.Clientor httpx.AsyncClient. For more information, see the HTTPX documentation. |
Run Method Parameters
These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.
| Parameter | Type | Default | Description |
|---|---|---|---|
| text | str | Text to embed. |
Was this page helpful?