Embedding#

class isek.embedding.openai_embedding.OpenAIEmbedding(dim: int | None = None, model_name: str = 'text-embedding-3-small', api_key: str | None = None, base_url: str | None = None)[source]#

Bases: AbstractEmbedding

An implementation of AbstractEmbedding that uses OpenAI's API to generate text embeddings.

This class connects to the OpenAI API (or a compatible endpoint) to convert text data into numerical vector representations using specified OpenAI embedding models.

embedding(datas: List[str]) List[List[float]][source]#

Generates embeddings for a list of text strings using the configured OpenAI model.

The input data is split into chunks to respect API limits (e.g., batch size). The dim parameter passed during initialization might be used by some models to specify the output dimensionality.

Parameters:

datas (List[str]) -- A list of text strings to be embedded.

Returns:

A list of embedding vectors. Each inner list is a list of floats representing the embedding for the corresponding input string.

Return type:

List[List[float]]

Raises:

openai.APIError -- If the OpenAI API returns an error.