2828import redis .asyncio as aredis
2929from redis .commands .search .indexDefinition import IndexDefinition
3030
31- from redisvl .exceptions import RedisModuleVersionError , RedisSearchError
31+ from redisvl .exceptions import (
32+ RedisModuleVersionError ,
33+ RedisSearchError ,
34+ RedisVLError ,
35+ SchemaValidationError ,
36+ )
3237from redisvl .index .storage import BaseStorage , HashStorage , JsonStorage
3338from redisvl .query import BaseQuery , CountQuery , FilterQuery
3439from redisvl .query .filter import FilterExpression
@@ -574,27 +579,8 @@ def load(
574579 List[str]: List of keys loaded to Redis.
575580
576581 Raises:
577- ValueError: If the length of provided keys does not match the length
578- of objects or if validation fails when validate_on_load is enabled.
579-
580- .. code-block:: python
581-
582- data = [{"test": "foo"}, {"test": "bar"}]
583-
584- # simple case
585- keys = index.load(data)
586-
587- # set 360 second ttl policy on data
588- keys = index.load(data, ttl=360)
589-
590- # load data with predefined keys
591- keys = index.load(data, keys=["rvl:foo", "rvl:bar"])
592-
593- # load data with preprocessing step
594- def add_field(d):
595- d["new_field"] = 123
596- return d
597- keys = index.load(data, preprocess=add_field)
582+ SchemaValidationError: If validation fails when validate_on_load is enabled.
583+ RedisVLError: If there's an error loading data to Redis.
598584 """
599585 try :
600586 return self ._storage .write (
@@ -607,9 +593,14 @@ def add_field(d):
607593 batch_size = batch_size ,
608594 validate = self ._validate_on_load ,
609595 )
610- except :
611- logger .exception ("Error while loading data to Redis" )
596+ except SchemaValidationError :
597+ # Pass through validation errors directly
598+ logger .exception ("Schema validation error while loading data" )
612599 raise
600+ except Exception as e :
601+ # Wrap other errors as general RedisVL errors
602+ logger .exception ("Error while loading data to Redis" )
603+ raise RedisVLError (f"Failed to load data: { str (e )} " ) from e
613604
614605 def fetch (self , id : str ) -> Optional [Dict [str , Any ]]:
615606 """Fetch an object from Redis by id.
@@ -1134,8 +1125,8 @@ async def load(
11341125 List[str]: List of keys loaded to Redis.
11351126
11361127 Raises:
1137- ValueError : If the length of provided keys does not match the
1138- length of objects or if validation fails when validate_on_load is enabled .
1128+ SchemaValidationError : If validation fails when validate_on_load is enabled.
1129+ RedisVLError: If there's an error loading data to Redis .
11391130
11401131 .. code-block:: python
11411132
@@ -1169,9 +1160,14 @@ def add_field(d):
11691160 batch_size = batch_size ,
11701161 validate = self ._validate_on_load ,
11711162 )
1172- except :
1173- logger .exception ("Error while loading data to Redis" )
1163+ except SchemaValidationError :
1164+ # Pass through validation errors directly
1165+ logger .exception ("Schema validation error while loading data" )
11741166 raise
1167+ except Exception as e :
1168+ # Wrap other errors as general RedisVL errors
1169+ logger .exception ("Error while loading data to Redis" )
1170+ raise RedisVLError (f"Failed to load data: { str (e )} " ) from e
11751171
11761172 async def fetch (self , id : str ) -> Optional [Dict [str , Any ]]:
11771173 """Asynchronously etch an object from Redis by id. The id is typically
0 commit comments