From 30e4a35d7aa1bcba365077995aa9a2bc836e1eac Mon Sep 17 00:00:00 2001 From: Christophe Bornet Date: Tue, 19 Mar 2024 19:04:36 +0100 Subject: [PATCH] community: Use langchain-astradb for AstraDB caches (#18419) - [x] Needs https://github.com/langchain-ai/langchain-datastax/pull/4 - [x] Needs a new release of langchain-astradb --- docs/docs/integrations/providers/astradb.mdx | 4 ++-- libs/community/langchain_community/cache.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/docs/integrations/providers/astradb.mdx b/docs/docs/integrations/providers/astradb.mdx index bda86213957..49a41ee5caa 100644 --- a/docs/docs/integrations/providers/astradb.mdx +++ b/docs/docs/integrations/providers/astradb.mdx @@ -56,7 +56,7 @@ See the [usage example](/docs/integrations/memory/astradb_chat_message_history#e ```python from langchain.globals import set_llm_cache -from langchain_community.cache import AstraDBCache +from langchain_astradb import AstraDBCache set_llm_cache(AstraDBCache( api_endpoint=ASTRA_DB_API_ENDPOINT, @@ -71,7 +71,7 @@ Learn more in the [example notebook](/docs/integrations/llms/llm_caching#astra-d ```python from langchain.globals import set_llm_cache -from langchain_community.cache import +from langchain_astradb import AstraDBSemanticCache set_llm_cache(AstraDBSemanticCache( embedding=my_embedding, diff --git a/libs/community/langchain_community/cache.py b/libs/community/langchain_community/cache.py index f247b5643a6..584c7aa7f6b 100644 --- a/libs/community/langchain_community/cache.py +++ b/libs/community/langchain_community/cache.py @@ -62,6 +62,7 @@ try: except ImportError: from sqlalchemy.ext.declarative import declarative_base +from langchain_core._api.deprecation import deprecated from langchain_core.caches import RETURN_VAL_TYPE, BaseCache from langchain_core.embeddings import Embeddings from langchain_core.language_models.llms import LLM, aget_prompts, get_prompts @@ -1390,6 +1391,11 @@ class SQLAlchemyMd5Cache(BaseCache): ASTRA_DB_CACHE_DEFAULT_COLLECTION_NAME = "langchain_astradb_cache" +@deprecated( + since="0.0.28", + removal="0.2.0", + alternative_import="langchain_astradb.AstraDBCache", +) class AstraDBCache(BaseCache): @staticmethod def _make_id(prompt: str, llm_string: str) -> str: @@ -1588,6 +1594,11 @@ def _async_lru_cache(maxsize: int = 128, typed: bool = False) -> Callable: return decorating_function +@deprecated( + since="0.0.28", + removal="0.2.0", + alternative_import="langchain_astradb.AstraDBSemanticCache", +) class AstraDBSemanticCache(BaseCache): def __init__( self,