Skip to content

Commit 10a9766

Browse files
Sam ParteeSpartee
authored andcommitted
Documentation formatting and update (#99)
Update the documentation for 0.0.6 release.
1 parent 4010a57 commit 10a9766

File tree

21 files changed

+246
-195
lines changed

21 files changed

+246
-195
lines changed

docs/api/indexschema.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
*****
2+
***********
33
IndexSchema
4-
*****
4+
***********
55

66
IndexSchema
77
===========
@@ -19,10 +19,10 @@ IndexSchema
1919
IndexSchema.storage_type
2020
IndexSchema.fields
2121
IndexSchema.redis_fields
22-
SearchIndex.add_field
23-
SearchIndex.add_fields
24-
SearchIndex.remove_field
25-
SearchIndex.generate_fields
22+
IndexSchema.add_field
23+
IndexSchema.add_fields
24+
IndexSchema.remove_field
25+
IndexSchema.generate_fields
2626
IndexSchema.from_yaml
2727
IndexSchema.to_yaml
2828
IndexSchema.from_dict

docs/api/searchindex.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
*****
1+
***********
22
SearchIndex
3-
*****
3+
***********
44

55
SearchIndex
66
===========

docs/api/vectorizer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ VertexAITextVectorizer
6363

6464

6565
CohereTextVectorizer
66-
======================
66+
====================
6767

6868
.. _coheretextvectorizer_api:
6969

docs/overview/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ myst:
55
Installation instructions for RedisVL
66
---
77

8-
## Install RedisVL
8+
# Install RedisVL
99

1010
There are a few ways to install RedisVL. The easiest way is to use pip.
1111

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.black]
2-
target-version = ['py37', 'py38', 'py39', 'py310']
2+
target-version = ['py37', 'py38', 'py39', 'py310', 'py311']
33
exclude = '''
44
(
55
| \.egg

redisvl/index.py

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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

redisvl/llmcache/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def store(
4848
vector: Optional[List[float]] = None,
4949
metadata: Optional[dict] = {},
5050
) -> str:
51-
"""Stores the specified key-value pair in the cache along
52-
with metadata."""
51+
"""Stores the specified key-value pair in the cache along with
52+
metadata."""
5353
raise NotImplementedError
5454

5555
def hash_input(self, prompt: str):

redisvl/llmcache/semantic.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,10 @@ def set_threshold(self, distance_threshold: float) -> None:
183183
self._distance_threshold = float(distance_threshold)
184184

185185
def set_vectorizer(self, vectorizer: BaseVectorizer) -> None:
186-
"""Sets the vectorizer for the LLM cache. Must be a valid subclass of
187-
BaseVectorizer and have equivalent dimensions to the vector field
188-
defined int he schema.
186+
"""Sets the vectorizer for the LLM cache.
187+
188+
Must be a valid subclass of BaseVectorizer and have equivalent
189+
dimensions to the vector field defined in the schema.
189190
190191
Args:
191192
vectorizer (BaseVectorizer): The RedisVL vectorizer to use for
@@ -210,14 +211,15 @@ def set_vectorizer(self, vectorizer: BaseVectorizer) -> None:
210211
self._vectorizer = vectorizer
211212

212213
def clear(self) -> None:
213-
"""Clear the cache of all keys while preserving the index"""
214+
"""Clear the cache of all keys while preserving the index."""
214215
with self._index.client.pipeline(transaction=False) as pipe: # type: ignore
215216
for key in self._index.client.scan_iter(match=f"{self._index.prefix}:*"): # type: ignore
216217
pipe.delete(key)
217218
pipe.execute()
218219

219220
def delete(self) -> None:
220-
"""Clear the semantic cache of all keys and remove the underlying search index."""
221+
"""Clear the semantic cache of all keys and remove the underlying search
222+
index."""
221223
self._index.delete(drop=True)
222224

223225
def _refresh_ttl(self, key: str) -> None:
@@ -275,9 +277,8 @@ def check(
275277
num_results: int = 1,
276278
return_fields: Optional[List[str]] = None,
277279
) -> List[Dict[str, Any]]:
278-
"""
279-
Checks the semantic cache for results similar to the specified prompt or
280-
vector.
280+
"""Checks the semantic cache for results similar to the specified prompt
281+
or vector.
281282
282283
This method searches the cache using vector similarity with
283284
either a raw text prompt (converted to a vector) or a provided vector as
@@ -303,7 +304,8 @@ def check(
303304
ValueError: If neither a `prompt` nor a `vector` is specified.
304305
TypeError: If `return_fields` is not a list when provided.
305306
306-
Example:
307+
.. code-block:: python
308+
307309
response = cache.check(
308310
prompt="What is the captial city of France?"
309311
)
@@ -343,7 +345,8 @@ def store(
343345
ValueError: If neither prompt nor vector is specified.
344346
TypeError: If provided metadata is not a dictionary.
345347
346-
Example:
348+
.. code-block:: python
349+
347350
key = cache.store(
348351
prompt="What is the captial city of France?",
349352
response="Paris",

0 commit comments

Comments
 (0)