Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
OurBuilding Ambient Agents with LangGraph course is now available on LangChain Academy!
Open In ColabOpen on GitHub

AstraDB

DataStax Astra DB is a serverlessAI-ready database built onApache Cassandra® and made conveniently availablethrough an easy-to-use JSON API.

Overview

The Astra DB Document Loader returns a list of LangchainDocument objects read from an Astra DB collection.

The loader takes the following parameters:

  • api_endpoint: Astra DB API endpoint. Looks likehttps://01234567-89ab-cdef-0123-456789abcdef-us-east1.apps.astra.datastax.com
  • token: Astra DB token. Looks likeAstraCS:aBcD0123...
  • collection_name : AstraDB collection name
  • namespace: (Optional) AstraDB namespace (calledkeyspace in Astra DB)
  • filter_criteria: (Optional) Filter used in the find query
  • projection: (Optional) Projection used in the find query
  • limit: (Optional) Maximum number of documents to retrieve
  • extraction_function: (Optional) A function to convert the AstraDB document to the LangChainpage_content string. Defaults tojson.dumps

The loader sets the following metadata for the documents it reads:

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

Setup

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

Load documents with the Document Loader

from langchain_astradbimport AstraDBLoader
API Reference:AstraDBLoader

API Reference:AstraDBLoader

from getpassimport 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?"}')

Related


[8]ページ先頭

©2009-2025 Movatter.jp