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

Testing utils for plugins #2374

Merged
merged 5 commits into from
Aug 8, 2024

Conversation

jieguangzhou
Copy link
Collaborator

Description

Related Issues

Checklist

  • Is this code covered by new or existing unit tests or integration tests?
  • Did you run make unit_testing and make integration-testing successfully?
  • Do new classes, functions, methods and parameters all have docstrings?
  • Were existing docstrings updated, if necessary?
  • Was external documentation updated, if necessary?

Additional Notes or Comments

@jieguangzhou jieguangzhou linked an issue Aug 6, 2024 that may be closed by this pull request
@jieguangzhou jieguangzhou changed the title Add database test utils Testing utils for plugins Aug 6, 2024
@jieguangzhou jieguangzhou marked this pull request as draft August 6, 2024 15:38
@jieguangzhou jieguangzhou force-pushed the feat/test-utils branch 2 times, most recently from df0e08a to 4de19fd Compare August 7, 2024 08:59
@jieguangzhou jieguangzhou marked this pull request as ready for review August 7, 2024 09:00
Comment on lines +660 to +710
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
Copy link
Collaborator Author

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’.

@jieguangzhou jieguangzhou requested a review from kartik4949 August 7, 2024 10:42
assert artifact_store.exists("id")

# test get_bytes
assert artifact_store.get_bytes("id") == b"hello"
Copy link
Contributor

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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applied to?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@applies_to()

@jieguangzhou jieguangzhou merged commit 59b54a7 into superduper-io:main Aug 8, 2024
3 checks passed
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.

[SIMPLIFY-2] Testing utils for plugins
2 participants