AstraDB
DataStax Astra DB 是一個以 Cassandra 為基礎建構的無伺服器、具備向量功能的資料庫,並透過易於使用的 JSON API 方便地提供使用。
概觀
AstraDB Document Loader 從 AstraDB 資料庫傳回 Langchain 文件列表。
載入器採用以下參數
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
:(選用)載入器預先提取的文件數量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'})