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
This commit is contained in:
Christophe Bornet 2024-03-19 19:04:36 +01:00 committed by GitHub
parent 17c62e0f3a
commit 30e4a35d7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 2 deletions

View File

@ -56,7 +56,7 @@ See the [usage example](/docs/integrations/memory/astradb_chat_message_history#e
```python ```python
from langchain.globals import set_llm_cache from langchain.globals import set_llm_cache
from langchain_community.cache import AstraDBCache from langchain_astradb import AstraDBCache
set_llm_cache(AstraDBCache( set_llm_cache(AstraDBCache(
api_endpoint=ASTRA_DB_API_ENDPOINT, api_endpoint=ASTRA_DB_API_ENDPOINT,
@ -71,7 +71,7 @@ Learn more in the [example notebook](/docs/integrations/llms/llm_caching#astra-d
```python ```python
from langchain.globals import set_llm_cache from langchain.globals import set_llm_cache
from langchain_community.cache import from langchain_astradb import AstraDBSemanticCache
set_llm_cache(AstraDBSemanticCache( set_llm_cache(AstraDBSemanticCache(
embedding=my_embedding, embedding=my_embedding,

View File

@ -62,6 +62,7 @@ try:
except ImportError: except ImportError:
from sqlalchemy.ext.declarative import declarative_base 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.caches import RETURN_VAL_TYPE, BaseCache
from langchain_core.embeddings import Embeddings from langchain_core.embeddings import Embeddings
from langchain_core.language_models.llms import LLM, aget_prompts, get_prompts 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" 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): class AstraDBCache(BaseCache):
@staticmethod @staticmethod
def _make_id(prompt: str, llm_string: str) -> str: 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 return decorating_function
@deprecated(
since="0.0.28",
removal="0.2.0",
alternative_import="langchain_astradb.AstraDBSemanticCache",
)
class AstraDBSemanticCache(BaseCache): class AstraDBSemanticCache(BaseCache):
def __init__( def __init__(
self, self,