Skip to main content

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,
)

查看使用示例

大型语言模型缓存

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部分)。

语义大型语言模型缓存

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,
)

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

自查询检索器

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,
)

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

字节存储

from langchain_astradb import AstraDBByteStore

store = AstraDBByteStore(
collection_name="my_kv_store",
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
)

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


Was this page helpful?


You can also leave detailed feedback on GitHub.

扫我,入群扫我,找书