langchain_astradb.document_loaders.AstraDBLoader

class langchain_astradb.document_loaders.AstraDBLoader(collection_name: str, *, token: ~typing.Optional[str] = None, api_endpoint: ~typing.Optional[str] = None, astra_db_client: ~typing.Optional[~astrapy.core.db.AstraDB] = None, async_astra_db_client: ~typing.Optional[~astrapy.core.db.AsyncAstraDB] = None, namespace: ~typing.Optional[str] = None, filter_criteria: ~typing.Optional[~typing.Dict[str, ~typing.Any]] = None, projection: ~typing.Optional[~typing.Dict[str, ~typing.Any]] = <object object>, find_options: ~typing.Optional[~typing.Dict[str, ~typing.Any]] = None, nb_prefetched: int = 1000, page_content_mapper: ~typing.Callable[[~typing.Dict], str] = <function dumps>, metadata_mapper: ~typing.Optional[~typing.Callable[[~typing.Dict], ~typing.Dict[str, ~typing.Any]]] = None)[source]

Load DataStax Astra DB documents.

Parameters
  • collection_name (str) – name of the Astra DB collection to use.

  • token (Optional[str]) – API token for Astra DB usage.

  • api_endpoint (Optional[str]) – full URL to the API endpoint, such as https://<DB-ID>-us-east1.apps.astra.datastax.com.

  • astra_db_client (Optional[AstraDB]) – alternative to token+api_endpoint, you can pass an already-created ‘astrapy.db.AstraDB’ instance.

  • async_astra_db_client (Optional[AsyncAstraDB]) – alternative to token+api_endpoint, you can pass an already-created ‘astrapy.db.AsyncAstraDB’ instance.

  • namespace (Optional[str]) – namespace (aka keyspace) where the collection is. Defaults to the database’s “default namespace”.

  • filter_criteria (Optional[Dict[str, Any]]) – Criteria to filter documents.

  • projection (Optional[Dict[str, Any]]) – Specifies the fields to return. If not provided, reads fall back to the Data API default projection.

  • find_options (Optional[Dict[str, Any]]) – Additional options for the query.

  • nb_prefetched (int) – Max number of documents to pre-fetch. Defaults to 1000.

  • page_content_mapper (Callable[[Dict], str]) – Function applied to collection documents to create the page_content of the LangChain Document. Defaults to json.dumps.

  • metadata_mapper (Optional[Callable[[Dict], Dict[str, Any]]]) –

Methods

__init__(collection_name, *[, token, ...])

Load DataStax Astra DB documents.

alazy_load()

A lazy loader for Documents.

aload()

Load data into Document objects.

lazy_load()

A lazy loader for Documents.

load()

Load data into Document objects.

load_and_split([text_splitter])

Load Documents and split into chunks.

__init__(collection_name: str, *, token: ~typing.Optional[str] = None, api_endpoint: ~typing.Optional[str] = None, astra_db_client: ~typing.Optional[~astrapy.core.db.AstraDB] = None, async_astra_db_client: ~typing.Optional[~astrapy.core.db.AsyncAstraDB] = None, namespace: ~typing.Optional[str] = None, filter_criteria: ~typing.Optional[~typing.Dict[str, ~typing.Any]] = None, projection: ~typing.Optional[~typing.Dict[str, ~typing.Any]] = <object object>, find_options: ~typing.Optional[~typing.Dict[str, ~typing.Any]] = None, nb_prefetched: int = 1000, page_content_mapper: ~typing.Callable[[~typing.Dict], str] = <function dumps>, metadata_mapper: ~typing.Optional[~typing.Callable[[~typing.Dict], ~typing.Dict[str, ~typing.Any]]] = None) None[source]

Load DataStax Astra DB documents.

Parameters
  • collection_name (str) – name of the Astra DB collection to use.

  • token (Optional[str]) – API token for Astra DB usage.

  • api_endpoint (Optional[str]) – full URL to the API endpoint, such as https://<DB-ID>-us-east1.apps.astra.datastax.com.

  • astra_db_client (Optional[AstraDB]) – alternative to token+api_endpoint, you can pass an already-created ‘astrapy.db.AstraDB’ instance.

  • async_astra_db_client (Optional[AsyncAstraDB]) – alternative to token+api_endpoint, you can pass an already-created ‘astrapy.db.AsyncAstraDB’ instance.

  • namespace (Optional[str]) – namespace (aka keyspace) where the collection is. Defaults to the database’s “default namespace”.

  • filter_criteria (Optional[Dict[str, Any]]) – Criteria to filter documents.

  • projection (Optional[Dict[str, Any]]) – Specifies the fields to return. If not provided, reads fall back to the Data API default projection.

  • find_options (Optional[Dict[str, Any]]) – Additional options for the query.

  • nb_prefetched (int) – Max number of documents to pre-fetch. Defaults to 1000.

  • page_content_mapper (Callable[[Dict], str]) – Function applied to collection documents to create the page_content of the LangChain Document. Defaults to json.dumps.

  • metadata_mapper (Optional[Callable[[Dict], Dict[str, Any]]]) –

Return type

None

async alazy_load() AsyncIterator[Document][source]

A lazy loader for Documents.

Return type

AsyncIterator[Document]

async aload() List[Document][source]

Load data into Document objects.

Return type

List[Document]

lazy_load() Iterator[Document][source]

A lazy loader for Documents.

Return type

Iterator[Document]

load() List[Document]

Load data into Document objects.

Return type

List[Document]

load_and_split(text_splitter: Optional[TextSplitter] = None) List[Document]

Load Documents and split into chunks. Chunks are returned as Documents.

Do not override this method. It should be considered to be deprecated!

Parameters

text_splitter (Optional[TextSplitter]) – TextSplitter instance to use for splitting documents. Defaults to RecursiveCharacterTextSplitter.

Returns

List of Documents.

Return type

List[Document]

Examples using AstraDBLoader