Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions redisvl/extensions/cache/embeddings/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ def get_by_key(self, key: str) -> Optional[Dict[str, Any]]:

embedding_data = cache.get_by_key("embedcache:1234567890abcdef")
"""
if self._owns_redis_client is False and self._redis_client is None:
logger.warning(
"You are using redis_client but you had initialised the EmbeddingCache with an async_redis_client only. "
"If you intended to use async_redis_client, please use async aget(text, model_name) method of EmbeddingCache instead "
"of get(text, model_name)."
)

client = self._get_redis_client()

# Get all fields
Expand Down Expand Up @@ -202,6 +209,13 @@ def mget_by_keys(self, keys: List[str]) -> List[Optional[Dict[str, Any]]]:
if not keys:
return []

if self._owns_redis_client is False and self._redis_client is None:
logger.warning(
"You are using redis_client but you had initialised the EmbeddingCache with an async_redis_client only. "
"If you intended to use async_redis_client, please use async amget(texts, model_name) method of EmbeddingCache instead "
"of mget(texts, model_name)."
)

client = self._get_redis_client()

with client.pipeline(transaction=False) as pipeline:
Expand Down Expand Up @@ -283,6 +297,13 @@ def set(
text, model_name, embedding, metadata
)

if self._owns_redis_client is False and self._redis_client is None:
logger.warning(
"You are using redis_client but you had initialised the EmbeddingCache with an async_redis_client only. "
"If you intended to use async_redis_client, please use async aset(text, model_name, embedding, metadata=None, ttl=None) "
"method of EmbeddingCache instead of set(text, model_name, embedding, metadata=None, ttl=None)."
)

# Store in Redis
client = self._get_redis_client()
client.hset(name=key, mapping=cache_entry) # type: ignore
Expand Down Expand Up @@ -333,6 +354,13 @@ def mset(
if not items:
return []

if self._owns_redis_client is False and self._redis_client is None:
logger.warning(
"You are using redis_client but you had initialised the EmbeddingCache with an async_redis_client only. "
"If you intended to use async_redis_client, please use async amset(items, ttl=None) method of EmbeddingCache instead "
"of mset(items, ttl=None)."
)

client = self._get_redis_client()
keys = []

Expand Down
Loading