How do I change the current RedisVectorStore class to use redis client instead of the redis url? #11388
Replies: 3 comments
-
🤖 Hey there, @rahulkrprajapati! Fancy seeing you here again. Diving back into the code trenches, I see? Let's get cracking on that Redis conundrum of yours. To modify the def __init__(
self,
index_name: str,
index_prefix: str = "llama_index",
prefix_ending: str = "/vector",
index_args: Optional[Dict[str, Any]] = None,
metadata_fields: Optional[List[str]] = None,
redis_client: Optional[RedisType] = None,
overwrite: bool = False,
**kwargs: Any,
) -> None:
"""Initialize RedisVectorStore.
Args:
index_name (str): Name of the index.
index_prefix (str): Prefix for the index. Defaults to "llama_index".
prefix_ending (str): Prefix ending for the index. Defaults to "/vector".
index_args (Dict[str, Any]): Arguments for the index. Defaults to None.
metadata_fields (List[str]): List of metadata fields to store in the index
(only supports TAG fields).
redis_client (RedisType): Redis client instance. Defaults to None.
overwrite (bool): Whether to overwrite the index if it already exists.
Defaults to False.
kwargs (Any): Additional arguments to pass to the redis client.
Raises:
ValueError: If redis-py is not installed
ValueError: If RediSearch is not installed
"""
if redis_client is None:
raise ValueError("A Redis client instance is required.")
self._redis_client = redis_client
try:
# check if redis has redisearch module installed
check_redis_modules_exist(self._redis_client)
except ValueError as e:
raise ValueError(f"Redis failed to connect: {e}")
# index identifiers
self._prefix = index_prefix + prefix_ending
self._index_name = index_name
self._index_args = index_args if index_args is not None else {}
self._metadata_fields = metadata_fields if metadata_fields is not None else []
self._overwrite = overwrite
self._vector_field = str(self._index_args.get("vector_field", "vector"))
self._vector_key = str(self._index_args.get("vector_key", "vector"))
self._tokenizer = TokenEscaper()
super().__init__() This modification will allow you to pass a Redis client instance when creating a You can find the current implementation of the Sources
|
Beta Was this translation helpful? Give feedback.
-
You might be able to modify the
Although it's not ideal since |
Beta Was this translation helpful? Give feedback.
-
@MeshanKhosla I was using upstash then. I had already tried this out. It seems they've disabled Module from their end on the redis instance that they provide. This did not work . I migrated to using my own redis instance off a docker container and that seems to work fine. |
Beta Was this translation helpful? Give feedback.
-
I want the current
RedisVectorStore
to accept a redis client like:Beta Was this translation helpful? Give feedback.
All reactions