fix: batch embedding calls to prevent provider limit errors#73
Open
haosenwang1018 wants to merge 1 commit intozilliztech:mainfrom
Open
fix: batch embedding calls to prevent provider limit errors#73haosenwang1018 wants to merge 1 commit intozilliztech:mainfrom
haosenwang1018 wants to merge 1 commit intozilliztech:mainfrom
Conversation
When a markdown file produces more than 100 chunks, the single embed() call exceeds Google's BatchEmbedContentsRequest limit of 100 items, causing a 400 INVALID_ARGUMENT error. Add batching in _embed_and_store() with a default batch_size of 96, which stays safely under the lowest known provider limit (Google: 100). This also future-proofs against similar limits in other providers (Voyage: 128, OpenAI: 2048). Fixes zilliztech#72
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
memsearch indexcrashes withClientError: 400 INVALID_ARGUMENTwhen a markdown file produces more than 100 chunks while using the Google embedding provider. This is because_embed_and_store()sends all chunks toembed()in a single call with no batching.Fixes #72
Fix
Add batching in
_embed_and_store()with a defaultbatch_sizeof 96, which stays safely under the lowest known provider limit (Google: 100).Changes
src/memsearch/core.py: Batchembed()calls in_embed_and_store()The change is minimal and backward-compatible — behavior is identical for files that produce fewer than 96 chunks.