Skip to main content

OpenAITextEmbedder

Embeds strings using OpenAI models.

Basic Information

  • Type: haystack_integrations.embedders.openai_text_embedder.OpenAITextEmbedder

Inputs

ParameterTypeDefaultDescription
textstrText to embed.

Outputs

ParameterTypeDefaultDescription
embeddingList[float]A dictionary with the following keys: - embedding: The embedding of the input text. - meta: Information about the usage of the model.
metaDict[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:

ParameterTypeDefaultDescription
api_keySecretSecret.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.
modelstrtext-embedding-ada-002The name of the model to use for calculating embeddings. The default model is text-embedding-ada-002.
dimensionsOptional[int]NoneThe number of dimensions of the resulting embeddings. Only text-embedding-3 and later models support this parameter.
api_base_urlOptional[str]NoneOverrides default base URL for all HTTP requests.
organizationOptional[str]NoneYour organization ID. See OpenAI's production best practices for more information.
prefixstrA string to add at the beginning of each text to embed.
suffixstrA string to add at the end of each text to embed.
timeoutOptional[float]NoneTimeout for OpenAI client calls. If not set, it defaults to either the OPENAI_TIMEOUT environment variable, or 30 seconds.
max_retriesOptional[int]NoneMaximum 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_kwargsOptional[Dict[str, Any]]NoneA 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.

ParameterTypeDefaultDescription
textstrText to embed.