AstraDBLoader#

class langchain_astradb.document_loaders.AstraDBLoader(collection_name: str, *, token: str | TokenProvider | None = None, api_endpoint: str | None = None, environment: str | None = None, astra_db_client: AstraDB | None = None, async_astra_db_client: AsyncAstraDB | None = None, namespace: str | None = None, filter_criteria: dict[str, Any] | None = None, projection: dict[str, Any] | None = <object object>, find_options: dict[str, Any] | None = None, limit: int | None = None, nb_prefetched: int = <object object>, page_content_mapper: Callable[[dict], str] = <function dumps>, metadata_mapper: Callable[[dict], dict[str, Any]] | None = None)[source]#

Load DataStax Astra DB documents.

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

  • token (str | TokenProvider | None) – API token for Astra DB usage, either in the form of a string or a subclass of astrapy.authentication.TokenProvider. If not provided, the environment variable ASTRA_DB_APPLICATION_TOKEN is inspected.

  • api_endpoint (str | None) – full URL to the API endpoint, such as https://<DB-ID>-us-east1.apps.astra.datastax.com. If not provided, the environment variable ASTRA_DB_API_ENDPOINT is inspected.

  • environment (str | None) – a string specifying the environment of the target Data API. If omitted, defaults to “prod” (Astra DB production). Other values are in astrapy.constants.Environment enum class.

  • astra_db_client (AstraDB | None) – DEPRECATED starting from version 0.3.5. Please use ‘token’, ‘api_endpoint’ and optionally ‘environment’. you can pass an already-created ‘astrapy.db.AstraDB’ instance (alternatively to ‘token’, ‘api_endpoint’ and ‘environment’).

  • async_astra_db_client (AsyncAstraDB | None) – DEPRECATED starting from version 0.3.5. Please use ‘token’, ‘api_endpoint’ and optionally ‘environment’. you can pass an already-created ‘astrapy.db.AsyncAstraDB’ instance (alternatively to ‘token’, ‘api_endpoint’ and ‘environment’).

  • namespace (str | None) – namespace (aka keyspace) where the collection resides. If not provided, the environment variable ASTRA_DB_KEYSPACE is inspected. Defaults to the database’s “default namespace”.

  • filter_criteria (dict[str, Any] | None) – Criteria to filter documents.

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

  • find_options (dict[str, Any] | None) – Additional options for the query. DEPRECATED starting from version 0.3.5. For limiting, please use `limit`. Other options are ignored.

  • limit (int | None) – a maximum number of documents to return in the read query.

  • nb_prefetched (int) – Max number of documents to pre-fetch. IGNORED starting from v. 0.3.5: astrapy v1.0+ does not support it.

  • 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 (Callable[[dict], dict[str, Any]] | None) –

    Function applied to collection documents to create the metadata of the LangChain Document. Defaults to returning the

    namespace, API endpoint and collection name.

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: str | TokenProvider | None = None, api_endpoint: str | None = None, environment: str | None = None, astra_db_client: AstraDB | None = None, async_astra_db_client: AsyncAstraDB | None = None, namespace: str | None = None, filter_criteria: dict[str, Any] | None = None, projection: dict[str, Any] | None = <object object>, find_options: dict[str, Any] | None = None, limit: int | None = None, nb_prefetched: int = <object object>, page_content_mapper: Callable[[dict], str] = <function dumps>, metadata_mapper: Callable[[dict], dict[str, Any]] | None = None) None[source]#

Load DataStax Astra DB documents.

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

  • token (str | TokenProvider | None) – API token for Astra DB usage, either in the form of a string or a subclass of astrapy.authentication.TokenProvider. If not provided, the environment variable ASTRA_DB_APPLICATION_TOKEN is inspected.

  • api_endpoint (str | None) – full URL to the API endpoint, such as https://<DB-ID>-us-east1.apps.astra.datastax.com. If not provided, the environment variable ASTRA_DB_API_ENDPOINT is inspected.

  • environment (str | None) – a string specifying the environment of the target Data API. If omitted, defaults to “prod” (Astra DB production). Other values are in astrapy.constants.Environment enum class.

  • astra_db_client (AstraDB | None) – DEPRECATED starting from version 0.3.5. Please use ‘token’, ‘api_endpoint’ and optionally ‘environment’. you can pass an already-created ‘astrapy.db.AstraDB’ instance (alternatively to ‘token’, ‘api_endpoint’ and ‘environment’).

  • async_astra_db_client (AsyncAstraDB | None) – DEPRECATED starting from version 0.3.5. Please use ‘token’, ‘api_endpoint’ and optionally ‘environment’. you can pass an already-created ‘astrapy.db.AsyncAstraDB’ instance (alternatively to ‘token’, ‘api_endpoint’ and ‘environment’).

  • namespace (str | None) – namespace (aka keyspace) where the collection resides. If not provided, the environment variable ASTRA_DB_KEYSPACE is inspected. Defaults to the database’s “default namespace”.

  • filter_criteria (dict[str, Any] | None) – Criteria to filter documents.

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

  • find_options (dict[str, Any] | None) – Additional options for the query. DEPRECATED starting from version 0.3.5. For limiting, please use `limit`. Other options are ignored.

  • limit (int | None) – a maximum number of documents to return in the read query.

  • nb_prefetched (int) – Max number of documents to pre-fetch. IGNORED starting from v. 0.3.5: astrapy v1.0+ does not support it.

  • 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 (Callable[[dict], dict[str, Any]] | None) –

    Function applied to collection documents to create the metadata of the LangChain Document. Defaults to returning the

    namespace, API endpoint and collection name.

Return type:

None

async alazy_load() AsyncIterator[Document][source]#

A lazy loader for Documents.

Return type:

AsyncIterator[Document]

async aload() list[langchain_core.documents.base.Document][source]#

Load data into Document objects.

Return type:

list[langchain_core.documents.base.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: TextSplitter | None = 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