langchain_astradb.document_loaders
.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.
A lazy loader for Documents.
aload
()Load data into Document objects.
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
- lazy_load() Iterator[Document] [source]¶
A lazy loader for Documents.
- Return type
Iterator[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]