Skip to content

raggy.utilities.embeddings

create_openai_embeddings async

Create OpenAI embeddings for a list of texts.

Parameters:

Name Type Description Default
input_ str | list[str]

The input text or list of texts to embed

required
timeout int

The maximum time to wait for the request to complete

60
model str

The model to use for the embeddings. Defaults to the value of raggy.settings.openai_embeddings_model, which is "text-embedding-3-small" by default

openai_embeddings_model

Returns:

Type Description
list[float] | list[list[float]]

The embeddings for the input text or list of texts

Raises:

Type Description
TypeError

If input_ is not a str or a list of str

Examples:

Create an embedding for a single text:

from raggy.utilities.embeddings import create_openai_embeddings

embedding = await create_openai_embeddings("Hello, world!")

Create embeddings for a list of texts:

from raggy.utilities.embeddings import create_openai_embeddings

embeddings = await create_openai_embeddings([
    "Hello, world!",
    "Goodbye, world!",
])