Skip to content

Instantly share code, notes, and snippets.

@ajhwb
Created May 16, 2022 03:56
Show Gist options
  • Select an option

  • Save ajhwb/429198befc4d163e301d8cc766ca53b7 to your computer and use it in GitHub Desktop.

Select an option

Save ajhwb/429198befc4d163e301d8cc766ca53b7 to your computer and use it in GitHub Desktop.
test_list_closest
def test_list_closest(self, test_client: Client, test_dataset: Dataset):
n_clusters = 10
clusterer = test_client.ClusterOps(
alias="new_clustering",
model=MiniBatchKMeans(n_clusters=n_clusters),
)
clusterer.run(
dataset_id=test_dataset.dataset_id,
vector_fields=["sample_1_vector_"],
)
cluster_ids = ["cluster-0", "cluster-6"]
closests = clusterer.list_closest(
dataset_id=test_dataset.dataset_id,
vector_field="sample_1_vector_",
cluster_ids=cluster_ids,
select_fields=["_id"],
)["results"]
assert len(closests) == len(cluster_ids)
clusterer = test_client.ClusterOps(
alias="new_clustering",
model="kmeans",
n_clusters=n_clusters,
)
clusterer.run(
dataset_id=test_dataset.dataset_id,
vector_fields=["sample_1_vector_"],
)
closests = clusterer.list_closest(
dataset_id=test_dataset.dataset_id,
vector_field="sample_1_vector_",
)["results"]
assert len(closests) == n_clusters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment