Skip to main content
Open In Colab在 GitHub 上打开

AstraDB 数据库

DataStax Astra DB 是一个无服务器 基于 AI 就绪型数据库Apache Cassandra®并方便使用 通过易于使用的 JSON API。

概述

Astra DB Document Loader 返回 Langchain 列表Document从 Astra DB 集合中读取的对象。

加载程序采用以下参数:

  • api_endpoint:Astra DB API 端点。看来https://01234567-89ab-cdef-0123-456789abcdef-us-east1.apps.astra.datastax.com
  • token:Astra DB 令牌。看来AstraCS:aBcD0123...
  • collection_name:AstraDB 集合名称
  • namespace:(可选)AstraDB 命名空间(在 Astra DB 中称为密钥空间
  • filter_criteria:(可选)查找查询中使用的筛选条件
  • projection:(可选)查找查询中使用的投影
  • limit:(可选)要检索的最大文档数
  • extraction_function:(可选)将 AstraDB 文档转换为 LangChain 的函数page_content字符串。默认为json.dumps

加载程序为其读取的文档设置以下元数据:

metadata={
"namespace": "...",
"api_endpoint": "...",
"collection": "..."
}

设置

!pip install "langchain-astradb>=0.6,<0.7"

使用 Document Loader 装入文档

from langchain_astradb import AstraDBLoader
API 参考:AstraDBLoader

API 参考: AstraDBLoader

from getpass import getpass

ASTRA_DB_API_ENDPOINT = input("ASTRA_DB_API_ENDPOINT = ")
ASTRA_DB_APPLICATION_TOKEN = getpass("ASTRA_DB_APPLICATION_TOKEN = ")
ASTRA_DB_API_ENDPOINT =  https://01234567-89ab-cdef-0123-456789abcdef-us-east1.apps.astra.datastax.com
ASTRA_DB_APPLICATION_TOKEN = ········
loader = AstraDBLoader(
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
collection_name="movie_reviews",
projection={"title": 1, "reviewtext": 1},
limit=10,
)
docs = loader.load()
docs[0]
Document(metadata={'namespace': 'default_keyspace', 'api_endpoint': 'https://01234567-89ab-cdef-0123-456789abcdef-us-east1.apps.astra.datastax.com', 'collection': 'movie_reviews'}, page_content='{"_id": "659bdffa16cbc4586b11a423", "title": "Dangerous Men", "reviewtext": "\\"Dangerous Men,\\" the picture\'s production notes inform, took 26 years to reach the big screen. After having seen it, I wonder: What was the rush?"}')