AstraDBLoader#

class langchain_astradb.document_loaders.AstraDBLoader(collection_name: str, *, token: str | ~astrapy.authentication.TokenProvider | None = None, api_endpoint: str | None = None, environment: str | None = None, astra_db_client: ~astrapy.core.db.AstraDB | None = None, async_astra_db_client: ~astrapy.core.db.AsyncAstraDB | None = None, namespace: str | None = None, filter_criteria: ~typing.Dict[str, ~typing.Any] | None = None, projection: ~typing.Dict[str, ~typing.Any] | None = <object object>, find_options: ~typing.Dict[str, ~typing.Any] | None = None, limit: int | None = None, nb_prefetched: int = <object object>, page_content_mapper: ~typing.Callable[[~typing.Dict], str] = <function dumps>, metadata_mapper: ~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[Union[str, TokenProvider]]) – 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 (Optional[str]) – 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 (Optional[str]) – 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 (Optional[AstraDB]) – 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 (Optional[AsyncAstraDB]) – 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 (Optional[str]) – 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 (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. DEPRECATED starting from version 0.3.5. For limiting, please use `limit`. Other options are ignored.

  • limit (Optional[int]) – 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 (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: str | ~astrapy.authentication.TokenProvider | None = None, api_endpoint: str | None = None, environment: str | None = None, astra_db_client: ~astrapy.core.db.AstraDB | None = None, async_astra_db_client: ~astrapy.core.db.AsyncAstraDB | None = None, namespace: str | None = None, filter_criteria: ~typing.Dict[str, ~typing.Any] | None = None, projection: ~typing.Dict[str, ~typing.Any] | None = <object object>, find_options: ~typing.Dict[str, ~typing.Any] | None = None, limit: int | None = None, nb_prefetched: int = <object object>, page_content_mapper: ~typing.Callable[[~typing.Dict], str] = <function dumps>, metadata_mapper: ~typing.Callable[[~typing.Dict], ~typing.Dict[str, ~typing.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) –

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: 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