mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-19 13:23:35 +00:00
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:
parent
17c62e0f3a
commit
30e4a35d7a
@ -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,
|
||||||
|
@ -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,
|
||||||
|
Loading…
Reference in New Issue
Block a user