Skip to content

add EMBEDDINGS_CHUNK_SIZE parameter for Azure + OpenAI #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def init_embeddings(provider, model):
api_key=RAG_OPENAI_API_KEY,
openai_api_base=RAG_OPENAI_BASEURL,
openai_proxy=RAG_OPENAI_PROXY,
chunk_size=EMBEDDINGS_CHUNK_SIZE,
)
elif provider == EmbeddingsProvider.AZURE:
from langchain_openai import AzureOpenAIEmbeddings
Expand All @@ -199,6 +200,7 @@ def init_embeddings(provider, model):
api_key=RAG_AZURE_OPENAI_API_KEY,
azure_endpoint=RAG_AZURE_OPENAI_ENDPOINT,
api_version=RAG_AZURE_OPENAI_API_VERSION,
chunk_size=EMBEDDINGS_CHUNK_SIZE,
)
elif provider == EmbeddingsProvider.HUGGINGFACE:
from langchain_huggingface import HuggingFaceEmbeddings
Expand Down Expand Up @@ -237,8 +239,12 @@ def init_embeddings(provider, model):

if EMBEDDINGS_PROVIDER == EmbeddingsProvider.OPENAI:
EMBEDDINGS_MODEL = get_env_variable("EMBEDDINGS_MODEL", "text-embedding-3-small")
# 1000 is the default chunk size for OpenAI, but this causes API rate limits to be hit
EMBEDDINGS_CHUNK_SIZE = get_env_variable("EMBEDDINGS_CHUNK_SIZE", 200)
elif EMBEDDINGS_PROVIDER == EmbeddingsProvider.AZURE:
EMBEDDINGS_MODEL = get_env_variable("EMBEDDINGS_MODEL", "text-embedding-3-small")
# 2048 is the default (and maximum) chunk size for Azure, but this often causes unexpected 429 errors
EMBEDDINGS_CHUNK_SIZE = get_env_variable("EMBEDDINGS_CHUNK_SIZE", 200)
elif EMBEDDINGS_PROVIDER == EmbeddingsProvider.HUGGINGFACE:
EMBEDDINGS_MODEL = get_env_variable(
"EMBEDDINGS_MODEL", "sentence-transformers/all-MiniLM-L6-v2"
Expand Down