Skip to content
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

fix: text and character limits on Cohere embedding API #376

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jimfingal
Copy link
Contributor

In a previous PR, I added support for retrieving more than one embedding at once from the Cohere embedding API.

@romenlee pointed out that this causes problems with a large number of texts. It looks like the Cohere embedding API has a limit of either 96 texts, or 2048 characters.

This PR implements more intelligent batching that respects these limits -- it batches texts in chunks that are at most 96 texts or 2048 characters, submits them to the embedding API, and combines the results.

There is a complexity vs. efficiency tradeoff call to make here for the maintainers. This code is much more complex than the original naive code, pre #350 -- but it is much more efficient with network calls so will execute faster. An alternative if we don't want to take on this complexity would be to just revert #350, which would restore functionality for embedding large texts at the cost of giving up performance improvements.

@jimfingal jimfingal changed the title bugfix: text and character limits on Cohere embedding API fix: text and character limits on Cohere embedding API Feb 27, 2025
@michaelnchin michaelnchin added this to the 2025 March Release 1 milestone Mar 1, 2025
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.

2 participants