Skip to content

Commit 474c4c8

Browse files
tylerhutchersonSam Partee
andauthored
Improve RedisVL filter handling, docs, and examples (#72)
Addresses https://github.com/RedisVentures/redisvl/issues/71 which highlights the need to support more edge case queries like "empty queries" or more sophisticated text LIKE query patterns. - Improves module readability and testability for the individual filter classes. - Adds support for various filter edge cases (described in the issue above). - Also fixes a bug in the index creation routine that originally ignored the `overwrite=False` case. - Adds more docstrings, unit tests and integration tests to improve our coverage on these cases. - Improves documentation coverage for hybrid queries and getting started. --------- Co-authored-by: Sam Partee <sam.partee@redis.com>
1 parent 4e3de2d commit 474c4c8

File tree

12 files changed

+1214
-356
lines changed

12 files changed

+1214
-356
lines changed

docs/user_guide/getting_started_01.ipynb

Lines changed: 354 additions & 56 deletions
Large diffs are not rendered by default.

docs/user_guide/hybrid_queries_02.ipynb

Lines changed: 342 additions & 50 deletions
Large diffs are not rendered by default.

redisvl/index.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ def connect(self, url: str, **kwargs):
150150
def disconnect(self):
151151
"""Disconnect from the Redis instance"""
152152
self._redis_conn = None
153+
return self
153154

154155
def key(self, key_value: str) -> str:
155156
"""
@@ -317,6 +318,7 @@ def connect(self, url: Optional[str] = None, **kwargs):
317318
ValueError: If the REDIS_URL env var is not set and url is not provided.
318319
"""
319320
self._redis_conn = get_redis_connection(url, **kwargs)
321+
return self
320322

321323
@check_connected("_redis_conn")
322324
def create(self, overwrite: Optional[bool] = False):
@@ -332,14 +334,21 @@ def create(self, overwrite: Optional[bool] = False):
332334

333335
if not self._fields:
334336
raise ValueError("No fields defined for index")
335-
336-
if self.exists() and overwrite:
337+
if not isinstance(overwrite, bool):
338+
raise TypeError("overwrite must be of type bool")
339+
340+
if self.exists():
341+
if not overwrite:
342+
print("Index already exists, not overwriting.")
343+
return None
344+
print("Index already exists, overwriting.")
337345
self.delete()
338346

339347
# set storage_type, default to hash
340348
storage_type = IndexType.HASH
341-
if self._storage.lower() == "json":
342-
storage_type = IndexType.JSON
349+
# TODO - enable JSON support
350+
# if self._storage.lower() == "json":
351+
# storage_type = IndexType.JSON
343352

344353
# Create Index
345354
# will raise correct response error if index already exists
@@ -499,6 +508,7 @@ def connect(self, url: Optional[str] = None, **kwargs):
499508
ValueError: If no Redis URL is provided and REDIS_URL env var is not set.
500509
"""
501510
self._redis_conn = get_async_redis_connection(url, **kwargs)
511+
return self
502512

503513
@check_connected("_redis_conn")
504514
async def create(self, overwrite: Optional[bool] = False):
@@ -510,14 +520,26 @@ async def create(self, overwrite: Optional[bool] = False):
510520
Raises:
511521
redis.exceptions.ResponseError: If the index already exists.
512522
"""
513-
exists = await self.exists()
514-
if exists and overwrite:
523+
# TODO - enable async version of this
524+
# check_redis_modules_exist(self._redis_conn)
525+
526+
if not self._fields:
527+
raise ValueError("No fields defined for index")
528+
if not isinstance(overwrite, bool):
529+
raise TypeError("overwrite must be of type bool")
530+
531+
if await self.exists():
532+
if not overwrite:
533+
print("Index already exists, not overwriting.")
534+
return None
535+
print("Index already exists, overwriting.")
515536
await self.delete()
516537

517538
# set storage_type, default to hash
518539
storage_type = IndexType.HASH
519-
if self._storage.lower() == "json":
520-
storage_type = IndexType.JSON
540+
# TODO - enable JSON support
541+
# if self._storage.lower() == "json":
542+
# storage_type = IndexType.JSON
521543

522544
# Create Index
523545
await self._redis_conn.ft(self._name).create_index( # type: ignore

0 commit comments

Comments
 (0)