Skip to main content

Overview

OpenAI provides high-quality embedding models including text-embedding-3-small, text-embedding-3-large, and text-embedding-ada-002. These models offer excellent performance for document and query embeddings with automatic batching and rate limiting. Provider Class: OpenAIEmbedding Config Class: OpenAIEmbeddingConfig

Dependencies

pip install openai

Examples

from upsonic import Agent, Task, KnowledgeBase
from upsonic.embeddings import OpenAIEmbedding, OpenAIEmbeddingConfig
from upsonic.vectordb import ChromaProvider, ChromaConfig, ConnectionConfig, Mode

# Create embedding provider
embedding = OpenAIEmbedding(OpenAIEmbeddingConfig(
    model_name="text-embedding-3-small",
    batch_size=100
))

# Setup KnowledgeBase
vectordb = ChromaProvider(ChromaConfig(
    collection_name="openai_docs",
    vector_size=1536,
    connection=ConnectionConfig(mode=Mode.IN_MEMORY)
))

kb = KnowledgeBase(
    sources=["document.txt"],
    embedding_provider=embedding,
    vectordb=vectordb
)

# Query with Agent
agent = Agent("openai/gpt-4o")
task = Task("What is this document about?", context=[kb])
result = agent.do(task)
print(result)

Parameters

ParameterTypeDescriptionDefaultSource
model_namestrOpenAI embedding model name"text-embedding-3-small"Specific
api_keystr | NoneOpenAI API key (uses OPENAI_API_KEY env var if None)NoneSpecific
organizationstr | NoneOpenAI organization IDNoneSpecific
base_urlstr | NoneCustom OpenAI API base URLNoneSpecific
enable_rate_limitingboolEnable intelligent rate limitingTrueSpecific
requests_per_minuteintMax requests per minute3000Specific
tokens_per_minuteintMax tokens per minute1000000Specific
parallel_requestsintNumber of parallel requests5Specific
request_timeoutfloatRequest timeout in seconds60.0Specific
batch_sizeintBatch size for document embedding100Base
max_retriesintMaximum number of retries on failure3Base
normalize_embeddingsboolWhether to normalize embeddings to unit lengthTrueBase
show_progressboolWhether to show progress during batch operationsTrueBase