Skip to content

Update config.py #150

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

Update config.py #150

wants to merge 1 commit into from

Conversation

diegogm
Copy link

@diegogm diegogm commented May 7, 2025

fix(embeddings): increase chunk_size for OpenAIEmbeddings to avoid API limits

Adjusted the chunk_size parameter in the OpenAIEmbeddings class to 200, based on the calculation:

  • Maximum payload size: 300 000 tokens
  • Upper‐bound chunk size: 1 500 tokens
  • ⇒ 300 000 / 1 500 = 200

This ensures embedding requests stay within OpenAI’s maximum input size and prevents failures due to oversized requests.

fix(embeddings): increase chunk_size for OpenAIEmbeddings to avoid API limits

Adjusted the `chunk_size` parameter in the `OpenAIEmbeddings` class to 200, based on the calculation:
- Maximum payload size: 300 000 tokens  
- Upper‐bound chunk size: 1 500 tokens  
- ⇒ 300 000 / 1 500 = 200  

This ensures embedding requests stay within OpenAI’s maximum input size and prevents failures due to oversized requests.
@danny-avila
Copy link
Owner

Were you not able to customize the chunk size via the .env variable? See the Readme.md

@diegogm
Copy link
Author

diegogm commented May 7, 2025

The two settings are not the same. The chunk_size value in the .env file determines the chunk size used by the recursive text splitter (the function that breaks the text into chunks). On the other hand, the chunk_size parameter in the embedding process defines the maximum number of tokens that can be sent to the OpenAI API per request. Unfortunately, both parameters share the same name, which can be confusing.

For example, if you set chunk_size to 1000 in the .env file and load a document that produces more than 300 chunks, the OpenAI API will return an error because it supports a maximum of 300,000 tokens per call.

@@ -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=200
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than hardcode a value, it would be better to make this configurable

@rubentalstra
Copy link
Collaborator

@diegogm diegogm#1

please have a look :)

@laszlovandenhoek
Copy link

laszlovandenhoek commented May 15, 2025

I have the same problem, but with Azure OpenAI. I have opened a separate pull request that implements the requested change and applies it to both OpenAI and Azure OpenAI:

#151

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants