fix: adjust max token size for openai ADA-v2 embeddings - #3793
Conversation
julian-risch
left a comment
There was a problem hiding this comment.
@LeoGitGuy Thank you for opening this PR. The added functionality looks very good. 👍 I just have a small change request about moving two lines of code so that we use
# OpenAI has a max seq length of 2048 tokens and unknown max batch size
self.max_seq_len = min(2048, max_seq_len)in the _setup_encoding_models method instead of the init method. My comment below describes that in more detail. Once you add this change, I will merge your PR.
| self.max_seq_len = min(8191, max_seq_len) | ||
| else: | ||
| self.query_encoder_model = f"text-search-{model_class}-query-001" | ||
| self.doc_encoder_model = f"text-search-{model_class}-doc-001" |
There was a problem hiding this comment.
Let's add self.max_seq_len = min(2048, max_seq_len) after this line of code instead of having it in the init method. If we add it here, we can remove line 394 and 395 (the self.max_seq_len=... assignment and the comment # OpenAI has a max seq length of 2048 tokens and unknown max batch size) from the init.
That makes it easier to read the code and see where the max_seq_len is set based on the inferred generation of embedding models (Dec 2022 or earlier).
There was a problem hiding this comment.
Thanks a lot for your reply! I added your proposed change and also fixed a small error since for the earlier embedding models the max_seq_len is 2046 instead of 2048 (see https://beta.openai.com/docs/guides/embeddings/what-are-embeddings). I tested it and hope everything is fine now
Apparently the limit for the older models is 2046 and not 2048, I included this change directly. See (https://beta.openai.com/docs/guides/embeddings/what-are-embeddings) to check.
julian-risch
left a comment
There was a problem hiding this comment.
Looks very good to me and I will merge it now. 👍 @LeoGitGuy thank you so much for your contribution.
Related Issues
Proposed Changes:
The following code shows that the max_seq_len is set to 2048 or lower:
To fix this, I added the user specified parameter
retriever.max_seq_lento the functionself._setup_encoding_models()and change the max_seq_len when the if clause for the new text-embedding is called, so the function definition will look like this:How did you test it?
manual tests with text-embedding set to text-embedding-ada-002 and number of tokens set to 8191
Notes for the reviewer
n/A
Checklist
this is my first pull request so I'm sorry if I did something wrong, tried my best