AstraDB
DataStax Astra DB 是一個基於 Cassandra 建構的、具備向量功能的無伺服器資料庫,並透過易於使用的 JSON API 提供便利的存取。
概觀
AstraDB Document Loader 從 AstraDB 資料庫傳回 Langchain 文件清單。
Loader 接受以下參數:
api_endpoint
:AstraDB API 端點。看起來像https://01234567-89ab-cdef-0123-456789abcdef-us-east1.apps.astra.datastax.com
token
:AstraDB 權杖。看起來像AstraCS:6gBhNmsk135....
collection_name
:AstraDB 集合名稱namespace
:(選用)AstraDB 命名空間filter_criteria
:(選用)在 find 查詢中使用的篩選條件projection
:(選用)在 find 查詢中使用的投影find_options
:(選用)在 find 查詢中使用的選項nb_prefetched
:(選用)Loader 預先提取的文件數量extraction_function
:(選用)將 AstraDB 文件轉換為 LangChainpage_content
字串的函數。預設為json.dumps
以下元資料會設定為 LangChain Documents 元資料輸出:
{
metadata : {
"namespace": "...",
"api_endpoint": "...",
"collection": "..."
}
}
使用 Document Loader 載入文件
from langchain_community.document_loaders import 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 = ")
loader = AstraDBLoader(
api_endpoint=ASTRA_DB_API_ENDPOINT,
token=ASTRA_DB_APPLICATION_TOKEN,
collection_name="movie_reviews",
projection={"title": 1, "reviewtext": 1},
find_options={"limit": 10},
)
docs = loader.load()
docs[0]
Document(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?"}', metadata={'namespace': 'default_keyspace', 'api_endpoint': 'https://01234567-89ab-cdef-0123-456789abcdef-us-east1.apps.astra.datastax.com', 'collection': 'movie_reviews'})