-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[ENH] Max batch size warning #995
Merged
+71
−3
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,9 +68,13 @@ def __init__( | |
self.callback = callback | ||
|
||
_subscriptions: Dict[str, Set[Subscription]] | ||
_max_batch_size: Optional[int] | ||
# How many variables are in the insert statement for a single record | ||
VARIABLES_PER_RECORD = 6 | ||
|
||
def __init__(self, system: System): | ||
self._subscriptions = defaultdict(set) | ||
self._max_batch_size = None | ||
super().__init__(system) | ||
|
||
@override | ||
|
@@ -115,6 +119,15 @@ def submit_embeddings( | |
if len(embeddings) == 0: | ||
return [] | ||
|
||
if len(embeddings) > self.max_batch_size: | ||
raise ValueError( | ||
f""" | ||
Cannot submit more than {self.max_batch_size:,} embeddings at once. | ||
Please submit your embeddings in batches of size | ||
{self.max_batch_size:,} or less. | ||
""" | ||
) | ||
|
||
t = Table("embeddings_queue") | ||
insert = ( | ||
self.querybuilder() | ||
|
@@ -208,6 +221,28 @@ def min_seqid(self) -> SeqId: | |
def max_seqid(self) -> SeqId: | ||
return 2**63 - 1 | ||
|
||
@property | ||
@override | ||
def max_batch_size(self) -> int: | ||
if self._max_batch_size is None: | ||
with self.tx() as cur: | ||
cur.execute("PRAGMA compile_options;") | ||
compile_options = cur.fetchall() | ||
|
||
for option in compile_options: | ||
if "MAX_VARIABLE_NUMBER" in option[0]: | ||
# The pragma returns a string like 'MAX_VARIABLE_NUMBER=999' | ||
self._max_batch_size = int(option[0].split("=")[1]) // ( | ||
self.VARIABLES_PER_RECORD | ||
) | ||
|
||
if self._max_batch_size is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fallback is purely defensive. |
||
# This value is the default for sqlite3 versions < 3.32.0 | ||
# It is the safest value to use if we can't find the pragma for some | ||
# reason | ||
self._max_batch_size = 999 // self.VARIABLES_PER_RECORD | ||
return self._max_batch_size | ||
|
||
def _prepare_vector_encoding_metadata( | ||
self, embedding: SubmitEmbeddingRecord | ||
) -> Tuple[Optional[bytes], Optional[str], Optional[str]]: | ||
|
This file contains 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
This file contains 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
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.
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.
We will cache this.