跳到主要内容
Open on GitHub

Astra DB

DataStax Astra DB 是一个无服务器的向量数据库,构建于 Apache Cassandra® 之上,并通过易于使用的 JSON API 便捷地提供。

查看 DataStax 提供的教程

安装和设置

安装以下 Python 包

pip install "langchain-astradb>=0.1.0"

获取连接密钥。设置以下环境变量

ASTRA_DB_APPLICATION_TOKEN="TOKEN"
ASTRA_DB_API_ENDPOINT="API_ENDPOINT"

向量存储

from langchain_astradb import AstraDBVectorStore

vector_store = AstraDBVectorStore(
embedding=my_embedding,
collection_name="my_store",
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
)

示例笔记本中了解更多信息。

查看 DataStax 提供的示例

聊天消息历史记录

from langchain_astradb import AstraDBChatMessageHistory

message_history = AstraDBChatMessageHistory(
session_id="test-session",
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
)

查看使用示例

LLM 缓存

from langchain.globals import set_llm_cache
from langchain_astradb import AstraDBCache

set_llm_cache(AstraDBCache(
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
))

示例笔记本中了解更多信息(滚动到 Astra DB 部分)。

语义 LLM 缓存

from langchain.globals import set_llm_cache
from langchain_astradb import AstraDBSemanticCache

set_llm_cache(AstraDBSemanticCache(
embedding=my_embedding,
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
))

示例笔记本中了解更多信息(滚动到相应部分)。

示例笔记本中了解更多信息。

文档加载器

from langchain_astradb import AstraDBLoader

loader = AstraDBLoader(
collection_name="my_collection",
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
)
API 参考:AstraDBLoader

示例笔记本中了解更多信息。

自查询检索器

from langchain_astradb import AstraDBVectorStore
from langchain.retrievers.self_query.base import SelfQueryRetriever

vector_store = AstraDBVectorStore(
embedding=my_embedding,
collection_name="my_store",
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
)

retriever = SelfQueryRetriever.from_llm(
my_llm,
vector_store,
document_content_description,
metadata_field_info
)

示例笔记本中了解更多信息。

存储

from langchain_astradb import AstraDBStore

store = AstraDBStore(
collection_name="my_kv_store",
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
)
API 参考:AstraDBStore

请参阅 AstraDBStore 的 API 参考。

字节存储

from langchain_astradb import AstraDBByteStore

store = AstraDBByteStore(
collection_name="my_kv_store",
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
)
API 参考:AstraDBByteStore

请参阅 AstraDBByteStore 的 API 参考。


此页是否对您有帮助?