# Prepare multimodal RAG data in batches with a workflow

MOI provides workflow templates for RAG data preparation that can read documents, parse layouts, split text into chunks, generate embeddings, and build text and image indexes in a single batch run. You can apply the same processing rules repeatedly to a collection of files, making these templates suitable for continuously building a knowledge base containing text, tables, and images.

This tutorial uses 3 illustrated Landsat reports published by the U.S. Geological Survey (USGS), covering Landsat applications in Alaska, California, and Florida. Each PDF contains text, maps, satellite imagery, or thematic maps, allowing you to validate text parsing, image descriptions, and image indexing together. You will use the **Document Knowledge Base Preparation (with Image Indexing)** template to prepare multimodal RAG data in a batch, then verify cross-document Q&A and image retrieval. The tutorial takes approximately 30 minutes; actual processing time depends on the number of files, page counts, and model speed.

Screenshots use the Chinese interface. The downloadable sample documents and their filenames are unchanged from the Chinese tutorial.

## What You Will Accomplish

- Upload multiple PDFs containing text and images to Catalog in a batch.
- Create a multimodal RAG data preparation workflow from a system template.
- Configure document parsing, text indexing, and image indexing.
- Run the workflow once to process all sample files.
- Verify cross-document Q&A and figure retrieval results in the knowledge base.

## Before You Begin

- Have an MOI account. You can [sign in or register for MOI Cloud](https://moi.matrixorigin.cn/).
- Confirm that you can create and run workflows in the current workspace.
- Download and extract the [multimodal RAG tutorial sample package](../assets/downloads/moi-multimodal-rag-demo.zip).

The sample package contains the following public materials:

| File | Text and Visual Content | Official Source |
| --- | --- | --- |
| `USGS.Alaska-and-Landsat.pdf` | Text, a near-surface permafrost distribution map, satellite imagery of flooding, and false-color wildfire imagery | [Alaska and Landsat](https://doi.org/10.3133/fs20203068) |
| `USGS.California-and-Landsat.pdf` | Text, false-color wildfire imagery, and a vegetation ecoregion map | [California and Landsat](https://doi.org/10.3133/fs20213034) |
| `USGS.Florida-and-Landsat.pdf` | Text, a map showing fire years, mangrove photographs, and satellite imagery of Miami Beach | [Florida and Landsat](https://doi.org/10.3133/fs20223019) |

These files are provided for convenience when following the tutorial. For your own use, you can replace them with your PDF, Word, PowerPoint, web page, spreadsheet, or image materials.

## Steps

### 1. Upload the Sample Files to Catalog in a Batch

1. Sign in to MOI and select **Import Tasks** under **Data Connect** in the left navigation.
2. Click **New Import Task** and select **Unstructured**.
3. Select **Local Upload** as the data source, then select the extracted `USGS.Alaska-and-Landsat.pdf`, `USGS.California-and-Landsat.pdf`, and `USGS.Florida-and-Landsat.pdf` files together.
4. Select the current workspace's Catalog as the target and save the files to:

   ```text
   <Current workspace Catalog> / tutorial_data / multimodal_rag / source
   ```

   Here, `tutorial_data` is the catalog, `multimodal_rag` is the database, and `source` is the data volume. If they do not exist, create each one while selecting the target location.

5. Keep the remaining settings at their defaults and confirm that all 3 PDFs appear in the import file list.

   ```{image} ../assets/images/tutorials/workflow-text-image-rag-import-files.png
   :alt: Configure Local Upload and select three USGS Landsat PDFs containing text and images at once
   ```

6. Click **Create and Start Import**.
7. Wait until the import task status changes to **Completed** and confirm that all 3 PDFs are available at the following location:

   ```{image} ../assets/images/tutorials/workflow-text-image-rag-import-completed.png
   :alt: The import task for the three USGS Landsat PDFs containing text and images has a Completed status
   ```

   ```text
   Resource Center > Catalog > tutorial_data > multimodal_rag > source
   ```

### 2. Create a Multimodal RAG Workflow

1. Select **Workflow** under **Data Processing** in the left navigation.
2. Click **Create Workflow**.
3. Find the **Document Knowledge Base Preparation (with Image Indexing)** template and click **Use Template**.

   ```{image} ../assets/images/tutorials/workflow-text-image-rag-select-template.png
   :alt: Select the Document Knowledge Base Preparation (with Image Indexing) template when creating a workflow
   ```

4. Enter `landsat_visual_rag` as the workflow name.

The template already includes nodes for reading files, parsing documents, splitting text, building text and image indexes, saving parsing results, and registering data lineage. You do not need to add these nodes individually.

### 3. Configure the Workflow

#### Select the Source Files for Batch Processing

1. Open the workflow's run configuration and select **Catalog Data Source** on the left.
2. Under **Source Files**, select the `tutorial_data / multimodal_rag / source` data volume.
3. Set **File Scope** to **By File** and select `USGS.Alaska-and-Landsat.pdf`, `USGS.California-and-Landsat.pdf`, and `USGS.Florida-and-Landsat.pdf`.

   ```{image} ../assets/images/tutorials/workflow-text-image-rag-select-source.png
   :alt: Select three PDFs containing text and images from the source data volume in Catalog
   ```

Selecting all files at once lets the workflow process them in a batch during the same run.

#### Create a Knowledge Base

1. Select **Build Knowledge Base Index** on the left.
2. Enter `landsat_environment_knowledge` under **Knowledge Base** and click **Create Knowledge Base**.
3. Keep the default text Embedding model, turn on **Enable Image Indexing**, and keep the default image Embedding model.
4. Keep the three-level index and remaining parameters at their defaults.

   ```{image} ../assets/images/tutorials/workflow-text-image-rag-create-knowledge-base.png
   :alt: Create a multimodal RAG knowledge base and enable image indexing
   ```

#### Save to Catalog

1. Select **Save to Catalog** on the left.
2. Set **Output Location** to `tutorial_data / multimodal_rag / source`.
3. Click **Confirm** to save the run configuration.

   ```{image} ../assets/images/tutorials/workflow-text-image-rag-save-catalog.png
   :alt: Save workflow processing results to the source data volume in Catalog
   ```

Keep the template's default configuration for the remaining steps, including **Document Parsing**, **Split Documents by Length**, **Engineering Drawing Parsing**, **Build Drawing Knowledge Base Index**, and **Write Document Files**. You do not need to modify each step individually.

### 4. Save and Run the Workflow in a Batch

1. Return to the workflow canvas and click **Save and Enable**.
2. Click **Run** on the workflow page.
3. Confirm that both the source and output locations are `source` and that all 3 PDFs are selected.
4. After the run starts, click **Jobs** on the right side of the workflow page.
5. Find this run in the job list and wait until the job statuses for all 3 files change to **Completed**.

   ```{image} ../assets/images/tutorials/workflow-text-image-rag-run-completed.png
   :alt: The job list shows a Completed run status for landsat_visual_rag
   ```

Only one run is needed. The workflow processes all input files using the same parsing and indexing rules.

### 5. Start a Conversation in the Knowledge Base

1. Select **Knowledge Base** in the left navigation and open `landsat_environment_knowledge`.

   ```{image} ../assets/images/tutorials/workflow-text-image-rag-knowledge-base-chat.png
   :alt: Select landsat_environment_knowledge in the knowledge base list and click Chat
   ```

2. Click **Chat** on the knowledge base card and send a cross-document question:

   ```text
   What environmental issues are monitored using Landsat in Alaska, California, and Florida? Summarize them by region.
   ```

   ```{image} ../assets/images/tutorials/workflow-text-image-rag-answer-cross-document.png
   :alt: The knowledge base answers a cross-document question about Landsat environmental monitoring and provides references
   ```

3. Click the sources in the answer to view the cited materials and the original passages.
4. Send another question about the figures:

   ```text
   Find the false-color satellite image of California's August Complex wildfire and explain what yellow and dark brown represent in the image.
   ```

   ```{image} ../assets/images/tutorials/workflow-text-image-rag-answer-image.png
   :alt: The knowledge base answers a question about Landsat false-color satellite imagery
   ```

5. Click the page or image sources in the answer to view the captions and source information.

## Tutorial Complete

You have used a system template to prepare multimodal RAG data in a batch. All 3 public documents were parsed, chunked, and indexed for both text and images by the same workflow. The parsing results are saved to Catalog and can be used in the knowledge base for cross-document Q&A and figure retrieval.
