@@ -147,15 +147,24 @@ class SearchIndex:
147147 This class is a wrapper around the redis-py client that provides
148148 purpose-built methods for interacting with Redis as a vector database.
149149
150- Example:
150+ .. code-block:: python
151+
151152 from redisvl.index import SearchIndex
153+
154+ # initialize the index object with schema from file
152155 index = SearchIndex.from_yaml("schema.yaml", redis_url="redis://localhost:6379")
156+
157+ # create the index
153158 index.create(overwrite=True)
154- index.load(data) # data is an iterable of dictionaries
155- # Use an async connection
159+
160+ # data is an iterable of dictionaries
161+ index.load(data)
162+
163+ # Do the same with an an async connection
156164 index = SearchIndex.from_yaml("schema.yaml", redis_url="redis://localhost:6379", use_async=True)
157165 await index.acreate(overwrite=True)
158166 await index.aload(data)
167+
159168 """
160169
161170 _STORAGE_MAP = {
@@ -171,9 +180,8 @@ def __init__(
171180 connection_args : Dict [str , Any ] = {},
172181 ** kwargs ,
173182 ):
174- """Initialize the RedisVL search index class with a schema,
175- redis_url, connection_args, and other kwargs.
176- """
183+ """Initialize the RedisVL search index class with a schema, redis_url,
184+ connection_args, and other kwargs."""
177185 # final validation on schema object
178186 if not schema or not isinstance (schema , IndexSchema ):
179187 raise ValueError ("Must provide a valid schema object" )
@@ -221,7 +229,8 @@ def client(self) -> Optional[Union[redis.Redis, aredis.Redis]]:
221229 @classmethod
222230 def from_existing (cls ):
223231 raise DeprecationWarning (
224- "This method is deprecated since 0.0.5. Use the from_yaml or from_dict constructors with an IndexSchema instead."
232+ "This method is deprecated since 0.0.5. Use the from_yaml or\
233+ from_dict constructors with an IndexSchema instead."
225234 )
226235
227236 @classmethod
@@ -238,7 +247,8 @@ def from_yaml(
238247 Returns:
239248 SearchIndex: A RedisVL SearchIndex object.
240249
241- Example:
250+ .. code-block:: python
251+
242252 from redisvl.index import SearchIndex
243253 index = SearchIndex.from_yaml("schema.yaml", redis_url="redis://localhost:6379")
244254 index.create(overwrite=True)
@@ -260,7 +270,8 @@ def from_dict(
260270 Returns:
261271 SearchIndex: A RedisVL SearchIndex object.
262272
263- Example:
273+ .. code-block:: python
274+
264275 from redisvl.index import SearchIndex
265276 index = SearchIndex.from_dict({
266277 "index": {
@@ -273,6 +284,7 @@ def from_dict(
273284 }
274285 }, redis_url="redis://localhost:6379")
275286 index.create(overwrite=True)
287+
276288 """
277289 schema = IndexSchema .from_dict (schema_dict )
278290 return cls (schema = schema , connection_args = connection_args , ** kwargs )
@@ -304,11 +316,13 @@ def connect(
304316 ValueError: If the Redis URL is not provided nor accessible
305317 through the `REDIS_URL` environment variable.
306318
307- Example:
319+ .. code-block:: python
320+
308321 # standard sync Redis connection
309322 index.connect(redis_url="redis://localhost:6379")
310323 # async Redis connection
311324 index.connect(redis_url="redis://localhost:6379", use_async=True)
325+
312326 """
313327 self ._redis_conn .connect (redis_url , use_async , ** kwargs )
314328 return self
@@ -332,8 +346,7 @@ def set_client(self, client: Union[redis.Redis, aredis.Redis]):
332346 Raises:
333347 TypeError: If the provided client is not valid.
334348
335- Example:
336- import redis
349+ .. code-block:: python
337350
338351 r = redis.Redis.from_url("redis://localhost:6379")
339352 index.set_client(r)
@@ -343,6 +356,7 @@ def set_client(self, client: Union[redis.Redis, aredis.Redis]):
343356
344357 r = aredis.Redis.from_url("redis://localhost:6379")
345358 index.set_client(r)
359+
346360 """
347361 self ._redis_conn .set_client (client )
348362 return self
@@ -421,9 +435,8 @@ def load(
421435 preprocess : Optional [Callable ] = None ,
422436 batch_size : Optional [int ] = None ,
423437 ) -> List [str ]:
424- """
425- Load a batch of objects to Redis. Returns the list of keys loaded
426- to Redis.
438+ """Load a batch of objects to Redis. Returns the list of keys loaded to
439+ Redis.
427440
428441 Args:
429442 data (Iterable[Any]): An iterable of objects to store.
@@ -446,7 +459,8 @@ def load(
446459 ValueError: If the length of provided keys does not match the length
447460 of objects.
448461
449- Example:
462+ .. code-block:: python
463+
450464 keys = index.load([{"test": "foo"}, {"test": "bar"}])
451465 """
452466 return self ._storage .write (
@@ -460,10 +474,11 @@ def load(
460474 )
461475
462476 def fetch (self , id : str ) -> Dict [str , Any ]:
463- """
464- Fetch an object from Redis by id. The id is typically either a
465- unique identifier, or derived from some domain-specific metadata
466- combination (like a document id or chunk id).
477+ """Fetch an object from Redis by id.
478+
479+ The id is typically either a unique identifier,
480+ or derived from some domain-specific metadata combination
481+ (like a document id or chunk id).
467482
468483 Args:
469484 id (str): The specified unique identifier for a particular
@@ -513,8 +528,10 @@ def query(self, query: BaseQuery) -> List[Dict[str, Any]]:
513528 Returns:
514529 List[Result]: A list of search results.
515530
516- Example:
531+ .. code-block:: python
532+
517533 results = index.query(query)
534+
518535 """
519536 return self ._query (query )
520537
@@ -537,10 +554,12 @@ def query_batch(self, query: BaseQuery, batch_size: int = 30) -> Generator:
537554 TypeError: If the batch size is not an integer
538555 ValueError: If the batch size is less than or equal to zero.
539556
540- Example:
557+ .. code-block:: python
558+
541559 for batch in index.query_batch(query, batch_size=10):
542560 # process batched results
543561 pass
562+
544563 """
545564 if not isinstance (batch_size , int ):
546565 raise TypeError ("batch_size must be an integer" )
@@ -645,9 +664,8 @@ async def aload(
645664 preprocess : Optional [Callable ] = None ,
646665 concurrency : Optional [int ] = None ,
647666 ) -> List [str ]:
648- """
649- Asynchronously load objects to Redis with concurrency control. Returns
650- the list of keys loaded to Redis.
667+ """Asynchronously load objects to Redis with concurrency control.
668+ Returns the list of keys loaded to Redis.
651669
652670 Args:
653671 data (Iterable[Any]): An iterable of objects to store.
@@ -670,8 +688,10 @@ async def aload(
670688 ValueError: If the length of provided keys does not match the
671689 length of objects.
672690
673- Example:
691+ .. code-block:: python
692+
674693 keys = await index.aload([{"test": "foo"}, {"test": "bar"}])
694+
675695 """
676696 return await self ._storage .awrite (
677697 self ._redis_conn .client , # type: ignore
@@ -684,11 +704,9 @@ async def aload(
684704 )
685705
686706 async def afetch (self , id : str ) -> Dict [str , Any ]:
687- """
688- Asynchronously etch an object from Redis by id. The id is typically
707+ """Asynchronously etch an object from Redis by id. The id is typically
689708 either a unique identifier, or derived from some domain-specific
690- metadata
691- combination (like a document id or chunk id).
709+ metadata combination (like a document id or chunk id).
692710
693711 Args:
694712 id (str): The specified unique identifier for a particular
@@ -738,7 +756,8 @@ async def aquery(self, query: BaseQuery) -> List[Dict[str, Any]]:
738756 Returns:
739757 List[Result]: A list of search results.
740758
741- Example:
759+ .. code-block:: python
760+
742761 results = await aindex.query(query)
743762 """
744763 return await self ._aquery (query )
@@ -764,7 +783,8 @@ async def aquery_batch(
764783 TypeError: If the batch size is not an integer
765784 ValueError: If the batch size is less than or equal to zero.
766785
767- Example:
786+ .. code-block:: python
787+
768788 async for batch in index.aquery_batch(query, batch_size=10):
769789 # process batched results
770790 pass
0 commit comments