Skip to content

Commit 00211d5

Browse files
authored
fix: Avoid catching non-exception; skip retry for ValueErrors from VertexAI (#470)
The `VertexAIVectorizer` attempts to handle an error from Google that, it turns out, is not an exception despite being in the Google exceptions module. This PR removes this catch, and adjusts retry logic to capture the correct set of exceptions for VertexAI use. In particular, this fixes an issue where using an invalid model name would break with an unclear error - this now breaks as expected, by reporting that the provided model name was not found. fixes #469
1 parent 5cdac13 commit 00211d5

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

redisvl/utils/vectorize/vertexai.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@
66
from tenacity import retry, stop_after_attempt, wait_random_exponential
77
from tenacity.retry import retry_if_not_exception_type
88

9-
from redisvl.utils.utils import lazy_import
10-
119
if TYPE_CHECKING:
1210
from redisvl.extensions.cache.embeddings.embeddings import EmbeddingsCache
1311

1412
from redisvl.utils.vectorize.base import BaseVectorizer
1513

16-
InvalidArgument = lazy_import("google.api_core.exceptions.InvalidArgument")
17-
1814

1915
class VertexAIVectorizer(BaseVectorizer):
2016
"""The VertexAIVectorizer uses Google's VertexAI embedding model
@@ -233,7 +229,7 @@ def _set_model_dims(self) -> int:
233229
@retry(
234230
wait=wait_random_exponential(min=1, max=60),
235231
stop=stop_after_attempt(6),
236-
retry=retry_if_not_exception_type(TypeError),
232+
retry=retry_if_not_exception_type((TypeError, ValueError)),
237233
)
238234
def _embed(self, content: Any, **kwargs) -> List[float]:
239235
"""
@@ -286,15 +282,13 @@ def _embed(self, content: Any, **kwargs) -> List[float]:
286282
else:
287283
return self._client.get_embeddings([content], **kwargs)[0].values
288284

289-
except InvalidArgument as e:
290-
raise TypeError(f"Invalid input for embedding: {str(e)}") from e
291285
except Exception as e:
292286
raise ValueError(f"Embedding input failed: {e}")
293287

294288
@retry(
295289
wait=wait_random_exponential(min=1, max=60),
296290
stop=stop_after_attempt(6),
297-
retry=retry_if_not_exception_type(TypeError),
291+
retry=retry_if_not_exception_type((TypeError, ValueError)),
298292
)
299293
def _embed_many(
300294
self, contents: List[str], batch_size: int = 10, **kwargs
@@ -311,7 +305,6 @@ def _embed_many(
311305
List[List[float]]: List of vector embeddings as lists of floats
312306
313307
Raises:
314-
TypeError: If contents is not a list of strings
315308
ValueError: If embedding fails
316309
"""
317310
if self.is_multimodal:
@@ -329,8 +322,6 @@ def _embed_many(
329322
response = self._client.get_embeddings(batch, **kwargs)
330323
embeddings.extend([r.values for r in response])
331324
return embeddings
332-
except InvalidArgument as e:
333-
raise TypeError(f"Invalid input for embedding: {str(e)}") from e
334325
except Exception as e:
335326
raise ValueError(f"Embedding texts failed: {e}")
336327

tests/integration/test_redis_cluster_support.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def test_search_index_cluster_info(redis_cluster_url):
8989
finally:
9090
index.delete(drop=True)
9191

92+
9293
@pytest.mark.requires_cluster
9394
@pytest.mark.asyncio
9495
async def test_async_search_index_cluster_info(redis_cluster_url):
@@ -110,6 +111,7 @@ async def test_async_search_index_cluster_info(redis_cluster_url):
110111
await index.delete(drop=True)
111112
await client.aclose()
112113

114+
113115
@pytest.mark.requires_cluster
114116
@pytest.mark.asyncio
115117
async def test_async_search_index_client(redis_cluster_url):

tests/integration/test_search_index.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ def test_search_index_delete(index):
304304
assert not index.exists()
305305
assert index.name not in convert_bytes(index.client.execute_command("FT._LIST"))
306306

307+
307308
@pytest.mark.parametrize("num_docs", [0, 1, 5, 10, 2042])
308309
def test_search_index_clear(index, num_docs):
309310
index.create(overwrite=True, drop=True)

0 commit comments

Comments
 (0)