Skip to content

Commit 6d3d608

Browse files
committed
Validate bit_width
1 parent 5af42b6 commit 6d3d608

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

vicinity/backends/turbovec.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ def from_vectors(
4545
metric_enum = Metric.from_string(metric)
4646

4747
if metric_enum not in cls.supported_metrics:
48-
raise ValueError(
49-
f"Metric '{metric_enum.value}' is not supported by TurboVecBackend. Only cosine is supported."
50-
)
48+
raise ValueError(f"Metric '{metric_enum.value}' is not supported by TurboVecBackend.")
49+
50+
if bit_width not in (2, 3, 4):
51+
raise ValueError(f"bit_width must be 2, 3, or 4, got {bit_width}.")
5152

5253
dim = vectors.shape[1]
5354
index = TurboQuantIndex(dim=dim, bit_width=bit_width)
@@ -86,7 +87,7 @@ def query(self, vectors: npt.NDArray, k: int) -> QueryResult:
8687
"""Query the backend and return results as tuples of keys and distances."""
8788
k = min(k, len(self))
8889
scores_batch, indices_batch = self.index.search(vectors.astype(np.float32), k=k)
89-
# turbovec returns cosine similarity scores (higher=better); convert to cosine distance
90+
# TurboVec returns cosine similarity scores; convert to cosine distance
9091
distances_batch = 1.0 - scores_batch
9192
return [(indices_batch[i], distances_batch[i].astype(np.float32)) for i in range(len(vectors))]
9293

0 commit comments

Comments
 (0)