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

请参见使用示例

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

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

自查询检索器

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

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

Byte Store

from langchain_astradb import AstraDBByteStore

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

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


此页面是否有帮助?


您还可以留下详细的反馈 在 GitHub 上