View Source ExOpenAI.Embeddings (ex_openai.ex v1.6.0)

Modules for interacting with the embeddings group of OpenAI APIs

API Reference: https://platform.openai.com/docs/api-reference/embeddings

Summary

Functions

Creates an embedding vector representing the input text.

Functions

Link to this function

create_embedding(input, model, opts \\ [])

View Source
@spec create_embedding(
  [[integer()]] | [integer()] | [String.t()] | String.t(),
  (:"text-embedding-3-large"
   | :"text-embedding-3-small"
   | :"text-embedding-ada-002")
  | String.t(),
  openai_organization_key: String.t(),
  openai_api_key: String.t(),
  user: String.t(),
  encoding_format: :base64 | :float,
  dimensions: integer(),
  stream_to: (... -> any()) | pid()
) :: {:ok, ExOpenAI.Components.CreateEmbeddingResponse.t()} | {:error, any()}

Creates an embedding vector representing the input text.

Endpoint: https://api.openai.com/v1/embeddings

Method: POST

Docs: https://platform.openai.com/docs/api-reference/embeddings


Required Arguments:

  • input: Input text to embed, encoded as a string or array of tokens. To embed multiple inputs in a single request, pass an array of strings or array of token arrays. The input must not exceed the max input tokens for the model (8192 tokens for text-embedding-ada-002), cannot be an empty string, and any array must be 2048 dimensions or less. Example Python code for counting tokens.

  • model: ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them.

Optional Arguments:

  • stream_to: PID or function of where to stream content to

  • dimensions: The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models.

  • encoding_format: The format to return the embeddings in. Can be either float or base64.

Example: "float"

  • user: A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.

Example: "user-1234"

  • openai_api_key: OpenAI API key to pass directly. If this is specified, it will override the api_key config value.

  • openai_organization_key: OpenAI API key to pass directly. If this is specified, it will override the organization_key config value.