embeddings
The embeddings
module provides classes for creating embeddings from text inputs using OpenAI's models and supports both synchronous and asynchronous operations as well as the handling of raw responses and streaming response capabilities.
The module is appropriate for use in applications that require semantic analysis of text, like similarity searches, text clustering, and other natural language processing tasks that can benefit from high-dimensional vector representations of text.
Classes:
Name | Description |
---|---|
AsyncEmbeddings |
|
AsyncEmbeddingsWithRawResponse |
|
AsyncEmbeddingsWithStreamingResponse |
|
Embeddings |
|
EmbeddingsWithRawResponse |
|
EmbeddingsWithStreamingResponse |
|
AsyncEmbeddings
AsyncEmbeddings(client: AsyncOpenAI)
Methods:
Name | Description |
---|---|
create |
Creates an embedding vector representing the input text. |
with_raw_response |
|
with_streaming_response |
|
create
async
create(
*,
input: Union[
str,
List[str],
Iterable[int],
Iterable[Iterable[int]],
],
model: Union[
str,
Literal[
"text-embedding-ada-002",
"text-embedding-3-small",
"text-embedding-3-large",
],
],
dimensions: int | NotGiven = NOT_GIVEN,
encoding_format: (
Literal["float", "base64"] | NotGiven
) = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> CreateEmbeddingResponse
Creates an embedding vector representing the input text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
Union[str, List[str], Iterable[int], Iterable[Iterable[int]]]
|
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
|
required |
model
|
Union[str, Literal['text-embedding-ada-002', 'text-embedding-3-small', 'text-embedding-3-large']]
|
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. |
required |
dimensions
|
int | NotGiven
|
The number of dimensions the resulting output embeddings should have. Only
supported in |
NOT_GIVEN
|
encoding_format
|
Literal['float', 'base64'] | NotGiven
|
The format to return the embeddings in. Can be either |
NOT_GIVEN
|
user
|
str | NotGiven
|
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more. |
NOT_GIVEN
|
extra_headers
|
Headers | None
|
Send extra headers |
None
|
extra_query
|
Query | None
|
Add additional query parameters to the request |
None
|
extra_body
|
Body | None
|
Add additional JSON properties to the request |
None
|
timeout
|
float | Timeout | None | NotGiven
|
Override the client-level default timeout for this request, in seconds |
NOT_GIVEN
|
AsyncEmbeddingsWithRawResponse
AsyncEmbeddingsWithRawResponse(embeddings: AsyncEmbeddings)
Attributes:
Name | Type | Description |
---|---|---|
create |
|
AsyncEmbeddingsWithStreamingResponse
AsyncEmbeddingsWithStreamingResponse(
embeddings: AsyncEmbeddings,
)
Attributes:
Name | Type | Description |
---|---|---|
create |
|
Embeddings
Embeddings(client: OpenAI)
Methods:
Name | Description |
---|---|
create |
Creates an embedding vector representing the input text. |
with_raw_response |
|
with_streaming_response |
|
create
create(
*,
input: Union[
str,
List[str],
Iterable[int],
Iterable[Iterable[int]],
],
model: Union[
str,
Literal[
"text-embedding-ada-002",
"text-embedding-3-small",
"text-embedding-3-large",
],
],
dimensions: int | NotGiven = NOT_GIVEN,
encoding_format: (
Literal["float", "base64"] | NotGiven
) = NOT_GIVEN,
user: str | NotGiven = NOT_GIVEN,
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> CreateEmbeddingResponse
Creates an embedding vector representing the input text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
Union[str, List[str], Iterable[int], Iterable[Iterable[int]]]
|
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
|
required |
model
|
Union[str, Literal['text-embedding-ada-002', 'text-embedding-3-small', 'text-embedding-3-large']]
|
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. |
required |
dimensions
|
int | NotGiven
|
The number of dimensions the resulting output embeddings should have. Only
supported in |
NOT_GIVEN
|
encoding_format
|
Literal['float', 'base64'] | NotGiven
|
The format to return the embeddings in. Can be either |
NOT_GIVEN
|
user
|
str | NotGiven
|
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more. |
NOT_GIVEN
|
extra_headers
|
Headers | None
|
Send extra headers |
None
|
extra_query
|
Query | None
|
Add additional query parameters to the request |
None
|
extra_body
|
Body | None
|
Add additional JSON properties to the request |
None
|
timeout
|
float | Timeout | None | NotGiven
|
Override the client-level default timeout for this request, in seconds |
NOT_GIVEN
|
EmbeddingsWithRawResponse
EmbeddingsWithRawResponse(embeddings: Embeddings)
Attributes:
Name | Type | Description |
---|---|---|
create |
|
EmbeddingsWithStreamingResponse
EmbeddingsWithStreamingResponse(embeddings: Embeddings)
Attributes:
Name | Type | Description |
---|---|---|
create |
|