-
Notifications
You must be signed in to change notification settings - Fork 16.1k
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
mongodb: [performance] Increase DEFAULT_INSERT_BATCH_SIZE to 100,000 and introduce sizing constraints #19608
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
if texts_batch: | ||
result_ids.extend(self._insert_texts(texts_batch, metadatas_batch)) | ||
result_ids.extend(self._insert_texts(texts_batch, metadatas_batch)) # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The one concern here is what happens when someone calls add_texts() with a generator that yields a large amount of data. With this new code we'll inflate the entire thing into memory which can degrade performance. For example:
add_texts((random_large_string() for i in range(1_000_000))
In this case it would be best to limit the batches roughly based on the string size in addition to batch_size
. We could do that by tracking the sum total of the batch's text:
size += len(text)
texts_batch.append(text)
metadatas_batch.append(metadata)
if (i + 1) % batch_size == 0 or size >= 47_000_000:
47MB is the maxMessageSizeBytes that pymongo can batch in one message minus 1MB of overhead to account for other bson data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's fine with me. We'll re-introduce BATCH_SIZE as 100_000
and also have an additional bounding of 47_000_000
on the text aggregate text length. In this case, then, should we also include the length of the accompanying metadata?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thank you for contributing to LangChain!
Increase DEFAULT_INSERT_BATCH_SIZE to 100,000 and introduce sizing constraints
[x]
Lint and test: Run
make format
,make lint
andmake test
from the root of the package(s) you've modified. See contribution guidelines for more: https://python.langchain.com/docs/contributing/Additional guidelines:
If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, hwchase17.