-
Notifications
You must be signed in to change notification settings - Fork 478
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
Testing utils for plugins #2374
Conversation
4988bec
to
371d393
Compare
371d393
to
ff6bd5c
Compare
ff6bd5c
to
5874fee
Compare
df0e08a
to
4de19fd
Compare
4de19fd
to
2effd46
Compare
def _execute_pre_like(self, parent): | ||
assert self.parts[0][0] == 'like' | ||
assert self.parts[1][0] in ['find', 'find_one', 'select'] | ||
|
||
similar_ids, similar_scores = self._prepare_pre_like(parent) | ||
|
||
query = self[1:] | ||
query = query.filter(query[self.primary_id].isin(similar_ids)) | ||
result = query.execute() | ||
result.scores = similar_scores | ||
return result | ||
|
||
def _execute_post_like(self, parent): | ||
assert self.parts[0][0] in { | ||
'find', | ||
'select', | ||
}, "Post like query must start with find/select" | ||
if self.parts[-1][0] != 'like': | ||
raise ValueError('Post like query must end with like') | ||
like_kwargs = self.parts[-1][2] | ||
like_args = self.parts[-1][1] | ||
assert 'vector_index' in like_kwargs | ||
|
||
if not like_args and 'r' in like_kwargs: | ||
like_args = (like_kwargs['r'],) | ||
|
||
assert like_args | ||
|
||
query = self[:-1] | ||
result = list(query.execute()) | ||
ids = [str(r[self.primary_id]) for r in query.execute()] | ||
|
||
similar_ids, scores = self.db.select_nearest( | ||
like=like_args[0], | ||
ids=ids, | ||
vector_index=like_kwargs.get('vector_index'), | ||
n=like_kwargs.get('n', 100), | ||
) | ||
scores = dict(zip(similar_ids, scores)) | ||
|
||
result = [r for r in result if str(r[self.primary_id]) in similar_ids] | ||
|
||
from superduper.base.cursor import SuperDuperCursor | ||
|
||
cursor = SuperDuperCursor( | ||
raw_cursor=result, | ||
db=self.db, | ||
id_field=self.primary_id, | ||
) | ||
cursor.scores = scores | ||
return cursor |
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.
All queries have the same logic regarding ‘like’.
2effd46
to
0781c88
Compare
assert artifact_store.exists("id") | ||
|
||
# test get_bytes | ||
assert artifact_store.get_bytes("id") == b"hello" |
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.
bytes('hello')
@@ -656,6 +657,58 @@ def table_or_collection(self): | |||
"""Return the table or collection to select from.""" | |||
return type(self)(table=self.table, db=self.db) | |||
|
|||
def _execute_pre_like(self, parent): |
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.
applied to?
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.
@applies_to()
Description
Related Issues
Checklist
make unit_testing
andmake integration-testing
successfully?Additional Notes or Comments