mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
community[patch]: Redis.delete should be a regular method not a static method (#23873)
The `langchain_common.vectostore.Redis.delete()` must not be a `@staticmethod`. With the current implementation, it's not possible to have multiple instances of Redis vectorstore because all versions must share the `REDIS_URL`. It's not conform with the base class.
This commit is contained in:
parent
2274d2b966
commit
289960bc60
@ -582,8 +582,8 @@ class Redis(VectorStore):
|
|||||||
with open(path, "w+") as f:
|
with open(path, "w+") as f:
|
||||||
yaml.dump(self.schema, f)
|
yaml.dump(self.schema, f)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def delete(
|
def delete(
|
||||||
|
self,
|
||||||
ids: Optional[List[str]] = None,
|
ids: Optional[List[str]] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
@ -602,30 +602,12 @@ class Redis(VectorStore):
|
|||||||
ValueError: If the redis python package is not installed.
|
ValueError: If the redis python package is not installed.
|
||||||
ValueError: If the ids (keys in redis) are not provided
|
ValueError: If the ids (keys in redis) are not provided
|
||||||
"""
|
"""
|
||||||
redis_url = get_from_dict_or_env(kwargs, "redis_url", "REDIS_URL")
|
client = self.client
|
||||||
|
|
||||||
if ids is None:
|
|
||||||
raise ValueError("'ids' (keys)() were not provided.")
|
|
||||||
|
|
||||||
try:
|
|
||||||
import redis # noqa: F401
|
|
||||||
except ImportError:
|
|
||||||
raise ImportError(
|
|
||||||
"Could not import redis python package. "
|
|
||||||
"Please install it with `pip install redis`."
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
# We need to first remove redis_url from kwargs,
|
|
||||||
# otherwise passing it to Redis will result in an error.
|
|
||||||
if "redis_url" in kwargs:
|
|
||||||
kwargs.pop("redis_url")
|
|
||||||
client = get_client(redis_url=redis_url, **kwargs)
|
|
||||||
except ValueError as e:
|
|
||||||
raise ValueError(f"Your redis connected error: {e}")
|
|
||||||
# Check if index exists
|
# Check if index exists
|
||||||
try:
|
try:
|
||||||
client.delete(*ids)
|
if ids:
|
||||||
logger.info("Entries deleted")
|
client.delete(*ids)
|
||||||
|
logger.info("Entries deleted")
|
||||||
return True
|
return True
|
||||||
except: # noqa: E722
|
except: # noqa: E722
|
||||||
# ids does not exist
|
# ids does not exist
|
||||||
|
Loading…
Reference in New Issue
Block a user