Skip to content

Conversation

@jean-lucas
Copy link
Contributor

@jean-lucas jean-lucas commented Oct 14, 2022

Use the new endpoint build_slice to create a slice with Smart Sample.

Works for the backend in the PR: https://github.com/scaleapi/scaleapi/pull/48465

Examples:

import nucleus
from nucleus.slice import SliceBuilderFilters, SliceBuilderMethods, SliceBuilderFilterAutotag

API_KEY = ""
client = nucleus.NucleusClient(API_KEY, endpoint='http://localhost:3000/v1/nucleus')
d = client.get_dataset('ds_ccg9nsz861gg0b1dq68g')

# no filters
d.build_slice('slice_1', 20, SliceBuilderMethods.UNIQUENESS)

# slice filter
f = SliceBuilderFilters(slice_id="slc_cd41q746nncpvqy16h6g")
d.build_slice('slice_2', 20, SliceBuilderMethods.UNIQUENESS, f)

# autotag filter
f = SliceBuilderFilters(autotag=SliceBuilderFilterAutotag('tag_cd41jhjdqytg07g7m1n0', [-0.5, 0.5]))
d.build_slice('slice_3', 20, SliceBuilderMethods.UNIQUENESS, f)

@jean-lucas jean-lucas self-assigned this Oct 14, 2022
@jean-lucas jean-lucas requested a review from gatli October 14, 2022 09:17
Copy link
Contributor

@gatli gatli left a comment

Choose a reason for hiding this comment

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

LGTM 👍

I'd just add docstrings to explain the dataclasses

Comment on lines 533 to 561
def create_slice_builder_payload(
name: str,
sample_size: int,
sample_method: Union[str, "SliceBuilderMethods"],
filters: Optional["SliceBuilderFilters"],
):
# enum or string
sampleMethod = (
sample_method.value
if isinstance(sample_method, SliceBuilderMethods)
else sample_method
)

filter_payload: Dict[str, Union[str, dict]] = {}
if filters is not None:
if filters.slice_id is not None:
filter_payload["sliceId"] = filters.slice_id
if filters.autotag is not None:
filter_payload["autotag"] = {
"autotagId": filters.autotag.autotag_id,
"range": filters.autotag.score_range,
}

return {
"name": name,
"sampleSize": sample_size,
"sampleMethod": sampleMethod,
"filters": filter_payload,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of using helper methods for payload building. I'd rather just use pydantic off the bat and serialize that. Using validators for sanitizing gives them a "home" that is guaranteed to be called for the payload.

But yeah, don't worry about refactoring this. If it works we can merge it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've forgotten about pydantic. But its a good callout, would be better to have everything in one central place.
If i revisit this, i will migrate it to pydantic

Comment on lines +144 to 147
@pytest.mark.skip(
reason="Skip Temporarily - Need to find issue with customObjectIndexingJobId"
)
def test_box_gt_upload_embedding(CLIENT, dataset):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gatli I am skipping these two tests for now, to unblock CI.

They are consistently failing with customObjectIndexingJobId not being in the response.
ie: https://app.circleci.com/pipelines/github/scaleapi/nucleus-python-client/2311/workflows/8c84e971-e6c9-47d3-889a-c7616871f433/jobs/4800/parallel-runs/2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jean-lucas jean-lucas merged commit d045384 into master Oct 17, 2022
@jean-lucas jean-lucas deleted the jean-lucas-slice-builder-endpoint branch October 17, 2022 13:59
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.

3 participants