Skip to content

Commit 39b7c24

Browse files
committed
Update redisvl docs for redisvl 0.4.1
1 parent e5da3e1 commit 39b7c24

File tree

6 files changed

+447
-167
lines changed

6 files changed

+447
-167
lines changed

content/integrate/redisvl/api/searchindex.md

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type: integration
1414

1515
## SearchIndex
1616

17-
### `class SearchIndex(schema, redis_client=None, redis_url=None, connection_args={}, **kwargs)`
17+
### `class SearchIndex(schema, redis_client=None, redis_url=None, connection_kwargs=None, **kwargs)`
1818

1919
A search index class for interacting with Redis as a vector database.
2020

@@ -26,8 +26,7 @@ settings and field configurations.
2626
from redisvl.index import SearchIndex
2727

2828
# initialize the index object with schema from file
29-
index = SearchIndex.from_yaml("schemas/schema.yaml")
30-
index.connect(redis_url="redis://localhost:6379")
29+
index = SearchIndex.from_yaml("schemas/schema.yaml", redis_url="redis://localhost:6379")
3130

3231
# create the index
3332
index.create(overwrite=True)
@@ -49,7 +48,7 @@ kwargs.
4948
instantiated redis client.
5049
* **redis_url** (*Optional* *[* *str* *]*) – The URL of the Redis server to
5150
connect to.
52-
* **connection_args** (*Dict* *[* *str* *,* *Any* *]* *,* *optional*) – Redis client connection
51+
* **connection_kwargs** (*Dict* *[* *str* *,* *Any* *]* *,* *optional*) – Redis client connection
5352
args.
5453

5554
#### `aggregate(*args, **kwargs)`
@@ -85,13 +84,13 @@ extra options specific to the Redis connection.
8584

8685
* **Parameters:**
8786
**redis_url** (*Optional* *[* *str* *]* *,* *optional*) – The URL of the Redis server to
88-
connect to. If not provided, the method defaults to using the
89-
REDIS_URL environment variable.
87+
connect to.
9088
* **Raises:**
9189
* **redis.exceptions.ConnectionError** – If the connection to the Redis
9290
server fails.
9391
* **ValueError** – If the Redis URL is not provided nor accessible
9492
through the REDIS_URL environment variable.
93+
* **ModuleNotFoundError** – If required Redis modules are not installed.
9594

9695
```python
9796
index.connect(redis_url="redis://localhost:6379")
@@ -158,6 +157,16 @@ Check if the index exists in Redis.
158157
* **Return type:**
159158
bool
160159

160+
#### `expire_keys(keys, ttl)`
161+
162+
Set the expiration time for a specific entry or entries in Redis.
163+
164+
* **Parameters:**
165+
* **keys** (*Union* *[* *str* *,* *List* *[* *str* *]* *]*) – The entry ID or IDs to set the expiration for.
166+
* **ttl** (*int*) – The time-to-live in seconds.
167+
* **Return type:**
168+
int | *List*[int]
169+
161170
#### `fetch(id)`
162171

163172
Fetch an object from Redis by id.
@@ -210,6 +219,9 @@ Initialize from an existing search index in Redis by index name.
210219
instantiated redis client.
211220
* **redis_url** (*Optional* *[* *str* *]*) – The URL of the Redis server to
212221
connect to.
222+
* **Raises:**
223+
* **ValueError** – If redis_url or redis_client is not provided.
224+
* **RedisModuleVersionError** – If required Redis modules are not installed.
213225

214226
#### `classmethod from_yaml(schema_path, **kwargs)`
215227

@@ -438,7 +450,7 @@ hash or json.
438450

439451
## AsyncSearchIndex
440452

441-
### `class AsyncSearchIndex(schema, **kwargs)`
453+
### `class AsyncSearchIndex(schema, *, redis_url=None, redis_client=None, connection_kwargs=None, **kwargs)`
442454

443455
A search index class for interacting with Redis as a vector database in
444456
async-mode.
@@ -451,8 +463,10 @@ various settings and field configurations.
451463
from redisvl.index import AsyncSearchIndex
452464

453465
# initialize the index object with schema from file
454-
index = AsyncSearchIndex.from_yaml("schemas/schema.yaml")
455-
await index.connect(redis_url="redis://localhost:6379")
466+
index = AsyncSearchIndex.from_yaml(
467+
"schemas/schema.yaml",
468+
redis_url="redis://localhost:6379"
469+
)
456470

457471
# create the index
458472
await index.create(overwrite=True)
@@ -468,7 +482,11 @@ Initialize the RedisVL async search index with a schema.
468482

469483
* **Parameters:**
470484
* **schema** ([*IndexSchema*]({{< relref "schema/#indexschema" >}})) – Index schema object.
471-
* **connection_args** (*Dict* *[* *str* *,* *Any* *]* *,* *optional*) – Redis client connection
485+
* **redis_url** (*Optional* *[* *str* *]* *,* *optional*) – The URL of the Redis server to
486+
connect to.
487+
* **redis_client** (*Optional* *[* *aredis.Redis* *]*) – An
488+
instantiated redis client.
489+
* **connection_kwargs** (*Optional* *[* *Dict* *[* *str* *,* *Any* *]* *]*) – Redis client connection
472490
args.
473491

474492
#### `async aggregate(*args, **kwargs)`
@@ -494,27 +512,12 @@ available and in-place for future insertions or updates.
494512
* **Return type:**
495513
int
496514

497-
#### `async connect(redis_url=None, **kwargs)`
498-
499-
Connect to a Redis instance using the provided redis_url, falling
500-
back to the REDIS_URL environment variable (if available).
515+
#### `connect(redis_url=None, **kwargs)`
501516

502-
Note: Additional keyword arguments (\*\*kwargs) can be used to provide
503-
extra options specific to the Redis connection.
517+
[DEPRECATED] Connect to a Redis instance. Use connection parameters in \_\_init_\_.
504518

505519
* **Parameters:**
506-
**redis_url** (*Optional* *[* *str* *]* *,* *optional*) – The URL of the Redis server to
507-
connect to. If not provided, the method defaults to using the
508-
REDIS_URL environment variable.
509-
* **Raises:**
510-
* **redis.exceptions.ConnectionError** – If the connection to the Redis
511-
server fails.
512-
* **ValueError** – If the Redis URL is not provided nor accessible
513-
through the REDIS_URL environment variable.
514-
515-
```python
516-
index.connect(redis_url="redis://localhost:6379")
517-
```
520+
**redis_url** (*str* *|* *None*)
518521

519522
#### `async create(overwrite=False, drop=False)`
520523

@@ -553,9 +556,9 @@ Delete the search index.
553556
* **Raises:**
554557
**redis.exceptions.ResponseError** – If the index does not exist.
555558

556-
#### `disconnect()`
559+
#### `async disconnect()`
557560

558-
Disconnect and cleanup the underlying async redis connection.
561+
Disconnect from the Redis database.
559562

560563
#### `async drop_keys(keys)`
561564

@@ -577,6 +580,16 @@ Check if the index exists in Redis.
577580
* **Return type:**
578581
bool
579582

583+
#### `async expire_keys(keys, ttl)`
584+
585+
Set the expiration time for a specific entry or entries in Redis.
586+
587+
* **Parameters:**
588+
* **keys** (*Union* *[* *str* *,* *List* *[* *str* *]* *]*) – The entry ID or IDs to set the expiration for.
589+
* **ttl** (*int*) – The time-to-live in seconds.
590+
* **Return type:**
591+
int | *List*[int]
592+
580593
#### `async fetch(id)`
581594

582595
Asynchronously etch an object from Redis by id. The id is typically
@@ -805,29 +818,13 @@ to the redis-py ft.search() method.
805818
* **Return type:**
806819
Result
807820

808-
#### `async set_client(redis_client)`
821+
#### `set_client(redis_client)`
809822

810-
Manually set the Redis client to use with the search index.
811-
812-
This method configures the search index to use a specific
813-
Async Redis client. It is useful for cases where an external,
814-
custom-configured client is preferred instead of creating a new one.
823+
[DEPRECATED] Manually set the Redis client to use with the search index.
824+
This method is deprecated; please provide connection parameters in \_\_init_\_.
815825

816826
* **Parameters:**
817-
**redis_client** (*aredis.Redis*) – An Async Redis
818-
client instance to be used for the connection.
819-
* **Raises:**
820-
**TypeError** – If the provided client is not valid.
821-
822-
```python
823-
import redis.asyncio as aredis
824-
from redisvl.index import AsyncSearchIndex
825-
826-
# async Redis client and index
827-
client = aredis.Redis.from_url("redis://localhost:6379")
828-
index = AsyncSearchIndex.from_yaml("schemas/schema.yaml")
829-
await index.set_client(client)
830-
```
827+
**redis_client** (*Redis* *|* *Redis*)
831828

832829
#### `property client: Redis | None`
833830

content/integrate/redisvl/overview/cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Before running this notebook, be sure to
1919
!rvl version
2020
```
2121

22-
18:12:25 [RedisVL] INFO RedisVL version 0.3.9
22+
16:19:10 [RedisVL] INFO RedisVL version 0.4.0
2323

2424

2525
## Commands

content/integrate/redisvl/user_guide/getting_started.md

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ index = SearchIndex.from_dict(schema)
148148
Now we also need to facilitate a Redis connection. There are a few ways to do this:
149149

150150
- Create & manage your own client connection (recommended)
151-
- Provide a simple Redis URL and let RedisVL connect on your behalf
151+
- Provide a Redis URL and let RedisVL connect on your behalf (by default, it will connect to "redis://localhost:6379")
152152

153153
### Bring your own Redis connection instance
154154

@@ -159,9 +159,14 @@ This is ideal in scenarios where you have custom settings on the connection inst
159159
from redis import Redis
160160
161161
client = Redis.from_url("redis://localhost:6379")
162+
index = SearchIndex.from_dict(schema, redis_client=client)
163+
164+
# alternatively, provide an async Redis client object to enable async index operations
165+
# from redis.asyncio import Redis
166+
# from redisvl.index import AsyncSearchIndex
167+
# client = Redis.from_url("redis://localhost:6379")
168+
# index = AsyncSearchIndex.from_dict(schema, redis_client=client)
162169
163-
index.set_client(client)
164-
# optionally provide an async Redis client object to enable async index operations
165170
```
166171

167172

@@ -177,8 +182,10 @@ This is ideal for simple cases:
177182

178183

179184
```python
180-
index.connect("redis://localhost:6379")
181-
# optionally use an async client by passing use_async=True
185+
index = SearchIndex.from_dict(schema, redis_url="redis://localhost:6379")
186+
187+
# If you don't specify a client or Redis URL, the index will attempt to
188+
# connect to Redis at the default address ("redis://localhost:6379").
182189
```
183190

184191

@@ -299,8 +306,11 @@ results = index.query(query)
299306
result_print(results)
300307
```
301308

309+
*=>[KNN 3 @user_embedding $vector AS vector_distance] RETURN 6 user age job credit_score vector_distance vector_distance SORTBY vector_distance ASC DIALECT 2 LIMIT 0 3
302310

303-
<table><tr><th>vector_distance</th><th>user</th><th>age</th><th>job</th><th>credit_score</th></tr><tr><td>0</td><td>john</td><td>1</td><td>engineer</td><td>high</td></tr><tr><td>0</td><td>mary</td><td>2</td><td>doctor</td><td>low</td></tr><tr><td>0.0566299557686</td><td>tyler</td><td>9</td><td>engineer</td><td>high</td></tr></table>
311+
312+
313+
table><tr><th>vector_distance</th><th>user</th><th>age</th><th>job</th><th>credit_score</th></tr><tr><td>0</td><td>john</td><td>1</td><td>engineer</td><td>high</td></tr><tr><td>0</td><td>mary</td><td>2</td><td>doctor</td><td>low</td></tr><tr><td>0.0566299557686</td><td>tyler</td><td>9</td><td>engineer</td><td>high</td></tr></table>
304314

305315

306316
## Using an Asynchronous Redis Client
@@ -337,8 +347,7 @@ from redis.asyncio import Redis
337347
338348
client = Redis.from_url("redis://localhost:6379")
339349
340-
index = AsyncSearchIndex.from_dict(schema)
341-
await index.set_client(client)
350+
index = AsyncSearchIndex.from_dict(schema, redis_client=client)
342351
```
343352

344353

@@ -393,7 +402,7 @@ index.schema.add_fields([
393402
await index.create(overwrite=True, drop=False)
394403
```
395404

396-
11:53:25 redisvl.index.index INFO Index already exists, overwriting.
405+
11:28:32 redisvl.index.index INFO Index already exists, overwriting.
397406

398407

399408

@@ -404,7 +413,7 @@ result_print(results)
404413
```
405414

406415

407-
<table><tr><th>vector_distance</th><th>user</th><th>age</th><th>job</th><th>credit_score</th></tr><tr><td>0</td><td>john</td><td>1</td><td>engineer</td><td>high</td></tr><tr><td>0</td><td>mary</td><td>2</td><td>doctor</td><td>low</td></tr><tr><td>0.0566299557686</td><td>tyler</td><td>9</td><td>engineer</td><td>high</td></tr></table>
416+
<table><tr><th>vector_distance</th><th>user</th><th>age</th><th>job</th><th>credit_score</th></tr><tr><td>0</td><td>mary</td><td>2</td><td>doctor</td><td>low</td></tr><tr><td>0</td><td>john</td><td>1</td><td>engineer</td><td>high</td></tr><tr><td>0.0566299557686</td><td>tyler</td><td>9</td><td>engineer</td><td>high</td></tr></table>
408417

409418

410419
## Check Index Stats
@@ -426,19 +435,19 @@ Use the `rvl` CLI to check the stats for the index:
426435
│ num_records │ 22 │
427436
│ percent_indexed │ 1 │
428437
│ hash_indexing_failures │ 0 │
429-
│ number_of_uses │ 5
430-
│ bytes_per_record_avg │ 50.9091
438+
│ number_of_uses │ 2
439+
│ bytes_per_record_avg │ 47.8
431440
│ doc_table_size_mb │ 0.000423431 │
432-
│ inverted_sz_mb │ 0.00106812
441+
│ inverted_sz_mb │ 0.000911713
433442
│ key_table_size_mb │ 0.000165939 │
434-
│ offset_bits_per_record_avg │ 8
435-
│ offset_vectors_sz_mb │ 5.72205e-06
436-
│ offsets_per_term_avg │ 0.272727
437-
│ records_per_doc_avg │ 5.5
443+
│ offset_bits_per_record_avg │ nan
444+
│ offset_vectors_sz_mb │ 0
445+
│ offsets_per_term_avg │ 0
446+
│ records_per_doc_avg │ 5
438447
│ sortable_values_size_mb │ 0 │
439-
│ total_indexing_time │ 0.197
440-
│ total_inverted_index_blocks │ 12
441-
│ vector_index_sz_mb │ 0.0201416
448+
│ total_indexing_time │ 0.239
449+
│ total_inverted_index_blocks │ 11
450+
│ vector_index_sz_mb │ 0.235603
442451
╰─────────────────────────────┴─────────────╯
443452

444453

0 commit comments

Comments
 (0)