Skip to main content
Batch process all your records to store structured outputs in an Astra DB account. The requirements are as follows.
  • An IBM Cloud account or DataStax account.
    • For an IBM Cloud account, sign up for an IBMid, and then sign in to DataStax with your IBMid.
    • For a DataStax account, sign up for a DataStax account, and then sign in to DataStax with your DataStax account.
  • An Astra DB database in the DataStax account. To create a database: a. After you sign in to DataStax, click Create database.
    b. Click the Serverless (vector) tile, if it is not already selected.
    c. For Database name, enter some unique name for the database.
    d. Select a Provider and a Region, and then click Create database.
    Learn more.
  • An application token for the database. To create an application token: a. After you sign in to DataStax, in the list of databases, click the name of the target database.
    b. On the Overview tab, under Database Details, in the Application Tokens tile, click Generate Token.
    c. Enter some Token description and select and Expiration time period, and then click Generate token.
    d. Save the application token that is displayed to a secure location, and then click Close.
    Learn more.
  • A keyspace in the database. To create a keyspace: a. After you sign in to DataStax, in the list of databases, click the name of the target database.
    b. On the Data Explorer tab, in the Keyspace list, select Create keyspace.
    c. Enter some Keyspace name, and then click Add keyspace.
    Learn more.
  • A collection in the keyspace. For the Unstructured UI and Unstructured API:
    • An existing collection is not required. At runtime, the collection behavior is as follows:
      • If an existing collection name is specified, and Unstructured generates embeddings, but the number of dimensions that are generated does not match the existing collection’s embedding settings, the run will fail. You must change your Unstructured embedding settings or your existing collection’s embedding settings to match, and try the run again.
      • If a collection name is not specified, Unstructured creates a new collection in your keyspace. If Unstructured generates embeddings, the new collections’s name will be u<short-workflow-id>_<short-embedding-model-name>_<number-of-dimensions>. If Unstructured does not generate embeddings, the new collections’s name will be u<short-workflow-id.
    For Unstructured Ingest:
    • For the source connector only, an existing collection is required.
    • For the destination connector only, an existing collection is not required. At runtime, the collection behavior is as follows:
      • If an existing collection name is specified, and Unstructured generates embeddings, but the number of dimensions that are generated does not match the existing collection’s embedding settings, the run will fail. You must change your Unstructured embedding settings or your existing collections’s embedding settings to match, and try the run again.
      • If a collection name is not specified, Unstructured creates a new collection in your keyspace. The new collection’s name will be unstructuredautocreated.
    To create a collection yourself: a. After you sign in to DataStax, in the list of databases, click the name of the target database.
    b. On the Data Explorer tab, in the Keyspace list, select the name of the target keyspace.
    c. In the Collections list, select Create collection.
    d. Enter some Collection name.
    e. Turn on Vector-enabled collection, if it is not already turned on.
    f. For Embedding generation method, select Bring my own.
    g. For Dimensions, enter the number of dimensions for the embedding model that you plan to use.
    h. For Similarity metric, select Cosine.
    i. Click Create collection.
    Learn more.
The Astra DB connector dependencies:
CLI, Python
pip install "unstructured-ingest[astradb]"
You might also need to install additional dependencies, depending on your needs. Learn more. These environment variables:
  • ASTRA_DB_API_ENDPOINT - The API endpoint for the Astra DB database, represented by --api-endpoint (CLI) or api_endpoint (Python). To get the endpoint, see the Database Details > API Endpoint value on your database’s Overview tab.
  • ASTRA_DB_APPLICATION_TOKEN - The database application token value for the database, represented by --token (CLI) or token (Python). To get the token, see the Database Details > Application Tokens box on your database’s Overview tab.
  • ASTRA_DB_KEYSPACE - The name of the keyspace for the database, represented by --keyspace (CLI) or keyspace (Python).
  • ASTRA_DB_COLLECTION - The name of the collection for the keyspace, represented by --collection-name (CLI) or collection_name (Python). If no value is provided, see the beginning of this article for the behavior at run time.
Additional settings include:
  • For the source connector only, --fields (CLI) or fields (Python): Optionally, a comma-separated list (CLI) or an array of strings (Python) of fields to include in the output. The default is ti include all fields, if not otherwise specified.
  • For the destination connector only, --flatten-metadata (CLI) or flatten_metadata=True (Python): Optionally, whether to “flatten” the metadata. Specifically, the metadata key values are brought to the top level of the element, and the metadata key itself is removed. To not flatten the metadata (the default), specify --no-flatten_metadata (CLI) or flatten_metadata=False (Python). The default is is to not flatten the metadata if not otherwise specified.
Now call the Unstructured CLI or Python. The source connector can be any of the ones supported. This example uses the local source connector. This example sends files to Unstructured for processing by default. To process files locally instead, see the instructions at the end of this page.
#!/usr/bin/env bash

# Chunking and embedding are optional.

unstructured-ingest \
  local \
    --input-path $LOCAL_FILE_INPUT_DIR \
    --partition-by-api \
    --strategy hi_res \
    --chunking-strategy by_title \
    --embedding-provider huggingface \
    --partition-by-api \
    --api-key $UNSTRUCTURED_API_KEY \
    --partition-endpoint $UNSTRUCTURED_API_URL \
    --additional-partition-args="{\"split_pdf_page\":\"true\", \"split_pdf_allow_failed\":\"true\", \"split_pdf_concurrency_level\": 15}" \
  astradb \
    --api-endpoint $ASTRA_DB_API_ENDPOINT \
    --token $ASTRA_DB_APPLICATION_TOKEN \
    --collection-name $ASTRA_DB_COLLECTION \
    --keyspace $ASTRA_DB_KEYSPACE \
    --flatten-metadata
    
For the Unstructured Ingest CLI and the Unstructured Ingest Python library, you can use the --partition-by-api option (CLI) or partition_by_api (Python) parameter to specify where files are processed:
  • To do local file processing, omit --partition-by-api (CLI) or partition_by_api (Python), or explicitly specify partition_by_api=False (Python). Local file processing does not use an Unstructured API key or API URL, so you can also omit the following, if they appear:
    • --api-key $UNSTRUCTURED_API_KEY (CLI) or api_key=os.getenv("UNSTRUCTURED_API_KEY") (Python)
    • --partition-endpoint $UNSTRUCTURED_API_URL (CLI) or partition_endpoint=os.getenv("UNSTRUCTURED_API_URL") (Python)
    • The environment variables UNSTRUCTURED_API_KEY and UNSTRUCTURED_API_URL
  • To send files to the Unstructured Partition Endpoint for processing, specify --partition-by-api (CLI) or partition_by_api=True (Python). Unstructured also requires an Unstructured API key and API URL, by adding the following:
    • --api-key $UNSTRUCTURED_API_KEY (CLI) or api_key=os.getenv("UNSTRUCTURED_API_KEY") (Python)
    • --partition-endpoint $UNSTRUCTURED_API_URL (CLI) or partition_endpoint=os.getenv("UNSTRUCTURED_API_URL") (Python)
    • The environment variables UNSTRUCTURED_API_KEY and UNSTRUCTURED_API_URL, representing your API key and API URL, respectively.
    You must specify the API URL only if you are not using the default API URL for Unstructured Ingest, which applies to Starter and Team accounts.The default API URL for Unstructured Ingest is https://api.unstructuredapp.io/general/v0/general, which is the API URL for the Unstructured Partition Endpoint. However, you should always use the URL that was provided to you when your Unstructured account was created. If you do not have this URL, email Unstructured Support at support@unstructured.io.If you do not have an API key, get one now.If you are using an Enterprise account, the process for generating Unstructured API keys, and the Unstructured API URL that you use, are different. For instructions, see your Unstructured account administrator, or email Unstructured Support at support@unstructured.io.
I