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

Small refactor of unit tests to consolidate language and add a query and check helper to test_ingestion.py #176

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions apis/python/test/test_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_cloud_flat(self):
k = 100
nqueries = 100

query_vectors = load_fvecs(queries_uri)
queries = load_fvecs(queries_uri)
gt_i, gt_d = get_groundtruth_ivec(gt_uri, k=k, nqueries=nqueries)

index = vs.ingest(
Expand All @@ -50,7 +50,7 @@ def test_cloud_flat(self):
config=tiledb.cloud.Config().dict(),
mode=Mode.BATCH,
)
_, result_i = index.query(query_vectors, k=k)
_, result_i = index.query(queries, k=k)
assert accuracy(result_i, gt_i) > MINIMUM_ACCURACY

def test_cloud_ivf_flat(self):
Expand All @@ -63,7 +63,7 @@ def test_cloud_ivf_flat(self):
nqueries = 100
nprobe = 20

query_vectors = load_fvecs(queries_uri)
queries = load_fvecs(queries_uri)
gt_i, gt_d = get_groundtruth_ivec(gt_uri, k=k, nqueries=nqueries)

index = vs.ingest(
Expand All @@ -79,16 +79,16 @@ def test_cloud_ivf_flat(self):
# mode=Mode.BATCH,
)

_, result_i = index.query(query_vectors, k=k, nprobe=nprobe)
_, result_i = index.query(queries, k=k, nprobe=nprobe)
assert accuracy(result_i, gt_i) > MINIMUM_ACCURACY

_, result_i = index.query(
query_vectors, k=k, nprobe=nprobe, mode=Mode.REALTIME, num_partitions=2, resource_class="standard"
queries, k=k, nprobe=nprobe, mode=Mode.REALTIME, num_partitions=2, resource_class="standard"
)
assert accuracy(result_i, gt_i) > MINIMUM_ACCURACY

_, result_i = index.query(
query_vectors, k=k, nprobe=nprobe, mode=Mode.LOCAL, num_partitions=2
queries, k=k, nprobe=nprobe, mode=Mode.LOCAL, num_partitions=2
)
assert accuracy(result_i, gt_i) > MINIMUM_ACCURACY

Expand All @@ -97,20 +97,20 @@ def test_cloud_ivf_flat(self):

# Cannot pass resource_class or resources to LOCAL mode or to no mode.
with self.assertRaises(TypeError):
index.query(query_vectors, k=k, nprobe=nprobe, mode=Mode.LOCAL, resource_class="large")
index.query(queries, k=k, nprobe=nprobe, mode=Mode.LOCAL, resource_class="large")
with self.assertRaises(TypeError):
index.query(query_vectors, k=k, nprobe=nprobe, mode=Mode.LOCAL, resources=resources)
index.query(queries, k=k, nprobe=nprobe, mode=Mode.LOCAL, resources=resources)
with self.assertRaises(TypeError):
index.query(query_vectors, k=k, nprobe=nprobe, resource_class="large")
index.query(queries, k=k, nprobe=nprobe, resource_class="large")
with self.assertRaises(TypeError):
index.query(query_vectors, k=k, nprobe=nprobe, resources=resources)
index.query(queries, k=k, nprobe=nprobe, resources=resources)

# Cannot pass resources to REALTIME.
with self.assertRaises(TypeError):
index.query(query_vectors, k=k, nprobe=nprobe, mode=Mode.REALTIME, resources=resources)
index.query(queries, k=k, nprobe=nprobe, mode=Mode.REALTIME, resources=resources)

# Cannot pass both resource_class and resources.
with self.assertRaises(TypeError):
index.query(query_vectors, k=k, nprobe=nprobe, mode=Mode.REALTIME, resource_class="large", resources=resources)
index.query(queries, k=k, nprobe=nprobe, mode=Mode.REALTIME, resource_class="large", resources=resources)
with self.assertRaises(TypeError):
index.query(query_vectors, k=k, nprobe=nprobe, mode=Mode.BATCH, resource_class="large", resources=resources)
index.query(queries, k=k, nprobe=nprobe, mode=Mode.BATCH, resource_class="large", resources=resources)
4 changes: 2 additions & 2 deletions apis/python/test/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def test_index_with_incorrect_num_of_query_columns_simple(tmp_path):
index.query(np.random.rand(*query_shape).astype(np.float32), k=10)

# Okay otherwise.
query_vectors = load_fvecs(queries_uri)
index.query(query_vectors, k=10)
queries = load_fvecs(queries_uri)
index.query(queries, k=10)

def test_index_with_incorrect_num_of_query_columns_complex(tmp_path):
# Tests that we raise a TypeError if the number of columns in the query is not the same as the
Expand Down
Loading
Loading