pyseekdb.utils.embedding_functions.OpenAIEmbeddingFunction
- class pyseekdb.utils.embedding_functions.OpenAIEmbeddingFunction(model_name: str = 'text-embedding-3-small', api_key_env: str | None = None, api_base: str | None = None, dimensions: int | None = None, **kwargs: Any)[source]
Bases:
OpenAIBaseEmbeddingFunctionA convenient embedding function for OpenAI embedding models.
This class provides a simplified interface to OpenAI embedding models using the OpenAI API.
For more information about OpenAI models, see https://platform.openai.com/docs/guides/embeddings
Example
pip install pyseekdb openai
- __init__(model_name: str = 'text-embedding-3-small', api_key_env: str | None = None, api_base: str | None = None, dimensions: int | None = None, **kwargs: Any)[source]
Initialize OpenAIEmbeddingFunction.
- Parameters:
model_name (str, optional) – Name of the OpenAI embedding model. Defaults to “text-embedding-3-small”.
api_key_env (str, optional) – Name of the environment variable containing the OpenAI API key. Defaults to “OPENAI_API_KEY” if not provided.
api_base (str, optional) – Base URL for the API endpoint. Defaults to “https://api.openai.com/v1” if not provided. Useful for OpenAI-compatible proxies or custom endpoints.
dimensions (int, optional) – The number of dimensions the resulting embeddings should have. Only supported for text-embedding-3 models. Can reduce dimensions from default (1536 for text-embedding-3-small, 3072 for text-embedding-3-large).
**kwargs – Additional arguments to pass to the OpenAI client. Common options include: - timeout: Request timeout in seconds - max_retries: Maximum number of retries - See https://github.com/openai/openai-python for more options
Methods
__init__([model_name, api_key_env, ...])Initialize OpenAIEmbeddingFunction.
build_from_config(config)Get the configuration dictionary for the OpenAIBaseEmbeddingFunction.
name()support_persistence(embedding_function)Check if the embedding function supports persistence.
Attributes
dimensionGet the dimension of embeddings produced by this function.