Docs: Add self-querying retriever and store to AstraDB provider doc (#16362)

Add self-querying retriever and store to AstraDB provider doc
This commit is contained in:
Christophe Bornet 2024-01-22 16:24:28 +01:00 committed by GitHub
parent 076dbb1a8f
commit f9be877ed7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,10 +20,10 @@ pip install "astrapy>=0.5.3"
```python ```python
from langchain_community.vectorstores import AstraDB from langchain_community.vectorstores import AstraDB
vector_store = AstraDB( vector_store = AstraDB(
embedding=my_embedding, embedding=my_embedding,
collection_name="my_store", collection_name="my_store",
api_endpoint="...", api_endpoint="...",
token="...", token="...",
) )
``` ```
@ -40,7 +40,7 @@ set_llm_cache(AstraDBCache(
)) ))
``` ```
Learn more in the [example notebook](/docs/integrations/llms/llm_caching) (scroll to the Astra DB section). Learn more in the [example notebook](/docs/integrations/llms/llm_caching#astra-db-caches) (scroll to the Astra DB section).
### Semantic LLM Cache ### Semantic LLM Cache
@ -55,14 +55,14 @@ set_llm_cache(AstraDBSemanticCache(
)) ))
``` ```
Learn more in the [example notebook](/docs/integrations/llms/llm_caching) (scroll to the appropriate section). Learn more in the [example notebook](/docs/integrations/llms/llm_caching#astra-db-caches) (scroll to the appropriate section).
### Chat message history ### Chat message history
```python ```python
from langchain.memory import AstraDBChatMessageHistory from langchain.memory import AstraDBChatMessageHistory
message_history = AstraDBChatMessageHistory( message_history = AstraDBChatMessageHistory(
session_id="test-session" session_id="test-session",
api_endpoint="...", api_endpoint="...",
token="...", token="...",
) )
@ -75,14 +75,62 @@ Learn more in the [example notebook](/docs/integrations/memory/astradb_chat_mess
```python ```python
from langchain_community.document_loaders import AstraDBLoader from langchain_community.document_loaders import AstraDBLoader
loader = AstraDBLoader( loader = AstraDBLoader(
collection_name="my_collection",
api_endpoint="...", api_endpoint="...",
token="...", token="..."
collection_name="my_collection"
) )
``` ```
Learn more in the [example notebook](/docs/integrations/document_loaders/astradb). Learn more in the [example notebook](/docs/integrations/document_loaders/astradb).
### Self-querying retriever
```python
from langchain_community.vectorstores import AstraDB
from langchain.retrievers.self_query.base import SelfQueryRetriever
vector_store = AstraDB(
embedding=my_embedding,
collection_name="my_store",
api_endpoint="...",
token="...",
)
retriever = SelfQueryRetriever.from_llm(
my_llm,
vector_store,
document_content_description,
metadata_field_info
)
```
Learn more in the [example notebook](/docs/integrations/retrievers/self_query/astradb).
### Store
```python
from langchain_community.storage import AstraDBStore
store = AstraDBStore(
collection_name="my_kv_store",
api_endpoint="...",
token="..."
)
```
Learn more in the [example notebook](/docs/integrations/stores/astradb#astradbstore).
### Byte Store
```python
from langchain_community.storage import AstraDBByteStore
store = AstraDBByteStore(
collection_name="my_kv_store",
api_endpoint="...",
token="..."
)
```
Learn more in the [example notebook](/docs/integrations/stores/astradb#astradbbytestore).
## Apache Cassandra and Astra DB through CQL ## Apache Cassandra and Astra DB through CQL
@ -98,12 +146,12 @@ Hence, a different set of connectors, outlined below, shall be used.
```python ```python
from langchain_community.vectorstores import Cassandra from langchain_community.vectorstores import Cassandra
vector_store = Cassandra( vector_store = Cassandra(
embedding=my_embedding, embedding=my_embedding,
table_name="my_store", table_name="my_store",
) )
``` ```
Learn more in the [example notebook](/docs/integrations/vectorstores/astradb) (scroll down to the CQL-specific section). Learn more in the [example notebook](/docs/integrations/vectorstores/astradb#apache-cassandra-and-astra-db-through-cql) (scroll down to the CQL-specific section).
### Memory ### Memory
@ -123,7 +171,7 @@ from langchain.cache import CassandraCache
langchain.llm_cache = CassandraCache() langchain.llm_cache = CassandraCache()
``` ```
Learn more in the [example notebook](/docs/integrations/llms/llm_caching) (scroll to the Cassandra section). Learn more in the [example notebook](/docs/integrations/llms/llm_caching#cassandra-caches) (scroll to the Cassandra section).
### Semantic LLM Cache ### Semantic LLM Cache
@ -131,9 +179,9 @@ Learn more in the [example notebook](/docs/integrations/llms/llm_caching) (scrol
```python ```python
from langchain.cache import CassandraSemanticCache from langchain.cache import CassandraSemanticCache
cassSemanticCache = CassandraSemanticCache( cassSemanticCache = CassandraSemanticCache(
embedding=my_embedding, embedding=my_embedding,
table_name="my_store", table_name="my_store",
) )
``` ```
Learn more in the [example notebook](/docs/integrations/llms/llm_caching) (scroll to the appropriate section). Learn more in the [example notebook](/docs/integrations/llms/llm_caching#cassandra-caches) (scroll to the appropriate section).