# Corpora

A **corpus** is a collection of documents or tool definitions that serves as the knowledge source for benchmark generation. It provides the factual grounding from which MorganaBench creates questions and expected answers.

The workflow is: you create a **Corpus** (your data), then generate a **Benchmark** from it (a set of test questions with expected answers), then run an **Evaluation** against that benchmark (testing how well an LLM agent performs). The corpus is the starting point; everything downstream depends on its content.

## Corpus Types

| Type | Purpose |
|------|---------|
| :material-file-document-outline: **Documents** | Knowledge base for search benchmarks. Tests whether an agent provides correct answers based on the provided documents. |
| :fontawesome-solid-plug: **Tools** | Function definitions for tool-calling benchmarks. Tests whether an agent picks the right tool with correct parameters. |

---

## Creating a Corpus

1. Navigate to **Corpora** in the sidebar and click **Create Corpus**.
2. Choose your corpus type: **Documents** or **Tools**.
3. Enter a **Name** and optional **Description**. The name is auto-suggested from your filename. If the name already exists, the system suggests an alternative unique name highlighted in amber. Accept the suggestion or type a different name, then submit again.
4. Upload your files (see [Corpus Formats](#corpus-formats) below for each corpus type).
5. For Parquet uploads: configure columns in the panel that appears.
6. Click **Submit for processing**.

A progress display shows the current processing stage. The page auto-redirects to the corpus detail view once processing completes.

For a visual walkthrough with screenshots, see the [Search Benchmarks by Specification](../use-cases/search-bmark-doc-spec.md) use-case guide.

---

## Processing Status

After upload, the corpus moves through a series of stages before it's ready for use:

```
pending → uploaded → preparing → copying → processing → ready
                                                       ↘ failed
```

During processing, the detail page shows per-stage progress bars with percentages. The list page shows "Processing N%" for in-progress corpora.

| Status | Stage description shown | What's happening |
|--------|------------------------|------------------|
| Pending | "Waiting for processing job to start..." | Corpus created, queued for processing |
| Uploaded | "Files ready, starting ingestion..." | Files received, ingestion about to begin |
| Preparing | "Preparing corpus data..." | System is preparing files for processing |
| Copying | "Processing files..." | Files are being copied to internal storage |
| Processing | "Processing and indexing documents..." | Documents are being parsed, converted, and indexed |
| Ready |: | Corpus is ready for benchmark generation |
| Failed |: | An error occurred: see error messages on the detail page |

---

## Troubleshooting Failed Corpora

Common failure causes:

- Archive contains no valid files (only unsupported extensions)
- JSON syntax errors in tools files
- Parquet file is missing the specified content column
- Empty content in all rows

The error messages on the detail page describe what went wrong. To fix: correct your file and create a new corpus.

!!! warning "When to contact your administrator"
    - A corpus is stuck in a processing state and won't progress, or you need to delete a corpus that hasn't finished processing
    - You're hitting organization-level limits (e.g. max number of corpora)

---

## Corpora List

The main Corpora page shows all your corpora with filtering, sorting, and two view modes:

- **List view**: sortable columns
- **Grid view**: same information as cards

Toggle between views using the icon in the filter bar. Your preference is remembered across sessions.

The filter bar provides:

- **Search**: filter by corpus name
- **Status filter**: narrow to specific statuses (e.g. show only Ready or Failed)
- **Sort**: sort by name or creation date

Corpora that are still processing show a progress percentage in their status badge. The list auto-refreshes while any corpus is processing.

---

## Corpus Detail Page

Once created, the detail page shows:

- **Status** with progress bars (during processing)
- **Editable name and description**: click the pencil icon to edit inline
- **Metadata**: Corpus ID, type (Documents/Tools), creation date
- **Ingestion results**: "Ready documents: X/Y" showing how many files were successfully processed out of total
    - If some files were skipped: a warning explains why (unsupported file types)
    - If processing failed: error messages are shown with details
- **Download Raw Data**: download the file you originally uploaded
- **Create Benchmark**: start benchmark generation from this corpus (enabled only when Ready)
- **Linked Benchmarks**: table of all benchmarks generated from this corpus

---

## Deleting a Corpus

To delete a corpus, open its detail page and click **Delete Corpus**.

- **Corpus deletion is immediate and permanent!**
- Non-admin users can delete corpora in **Ready** or **Failed** status.
- Admins can delete corpora in any status, including ones still processing.
- Linked benchmarks are not deleted, but they can no longer reference the source data.
- Example corpora (pre-loaded samples) cannot be deleted, even by an admin.

---

## Corpus Formats

### Documents Corpus

A documents corpus can be uploaded in one of three ways:

1. **Parquet file**: a structured file where each row is one document
2. **Multiple files**: drag-drop individual document files directly
3. **Archive (ZIP / TGZ)**: a bundled archive of document files

!!! note
    A corpus upload accepts exactly one of: a Parquet file, an archive, or a set of individual document files. These cannot be combined in a single upload.

#### Parquet Column Configuration

When uploading a Parquet file, each row becomes one document. You need to specify which columns to use:

| Column | Required? | Notes |
|--------|-----------|-------|
| **content** | Yes: you select which column during upload | Contains the full document text |
| **id** | Optional: auto-generates sequential IDs (1, 2, 3…) if omitted | Unique identifier per document |

A column configuration panel appears automatically. The system detects your file's columns and offers them in dropdowns. If your file uses columns named `content` and `id`, they are pre-selected. Otherwise, select the correct columns from the dropdowns before submitting.

#### Supported File Types

For multiple files and archives, the following file types are supported:

| Format | Handling |
|--------|----------|
| `.txt`, `.md` | Used directly as document text |
| `.pdf`, `.docx`, `.pptx` | Converted to Markdown |

!!! note
    - Each file becomes one document in the corpus.
    - Archives support nested directories.
    - Files with unsupported extensions are skipped (reported in the ingestion results).
    - File names and folder structure do not affect benchmark generation. Only the text content of each document is used.

### Tools Corpus

A tools corpus can be uploaded in one of three ways:

1. **Single JSON file**: one file containing your tool definitions
2. **Multiple JSON files**: drag-drop or browse for multiple `.json` files at once. The system merges all tools into one corpus.
3. **Archive (ZIP / TGZ)**: a single archive containing multiple `.json` files. Same merging behavior as above: useful for combining tool sets from several MCPs.

#### Tool Definition Format

Tools must follow the [MCP tools/list schema](https://modelcontextprotocol.io/specification/2025-11-25/server/tools#listing-tools). Each tool needs three fields:

| Field | Type | Description |
|-------|------|-------------|
| `name` | string | Unique identifier for the tool |
| `description` | string | What the tool does (natural language: this is what the LLM reads to decide whether to call it) |
| `inputSchema` | object | JSON Schema describing the tool's parameters |

**Accepted JSON formats** (any of these work):

=== "MCP tools/list (recommended)"

    ```json
    {
      "tools": [
        {
          "name": "get_weather",
          "description": "Get current weather for a location",
          "inputSchema": {
            "type": "object",
            "required": ["location"],
            "properties": {
              "location": {
                "type": "string",
                "description": "City name or coordinates"
              }
            }
          }
        }
      ]
    }
    ```

=== "Bare array"

    ```json
    [
      {
        "name": "get_weather",
        "description": "Get current weather for a location",
        "inputSchema": {
          "type": "object",
          "required": ["location"],
          "properties": {
            "location": {
              "type": "string",
              "description": "City name or coordinates"
            }
          }
        }
      }
    ]
    ```

=== "Single tool object"

    ```json
    {
      "name": "get_weather",
      "description": "Get current weather for a location",
      "inputSchema": {
        "type": "object",
        "required": ["location"],
        "properties": {
          "location": {
            "type": "string",
            "description": "City name or coordinates"
          }
        }
      }
    }
    ```

=== "JSON-RPC response wrapper"

    ```json
    {
      "result": {
        "tools": [
          {
            "name": "get_weather",
            "description": "Get current weather for a location",
            "inputSchema": {
              "type": "object",
              "required": ["location"],
              "properties": {
                "location": {
                  "type": "string",
                  "description": "City name or coordinates"
                }
              }
            }
          }
        ]
      }
    }
    ```

!!! note
    File names are discarded, and all tools are flattened into a single list regardless of which file they came from. If you need to distinguish tools by origin (e.g., which MCP server they belong to), encode that in the tool name or description. The only exception: when two files define a tool with the same name, the file name is automatically prefixed for disambiguation (e.g., `slack__search` and `github__search`).

---

## Limits

| Limit | Value |
|-------|-------|
| Documents upload size | 350 MB |
| Tools upload size | 10 MB |
| Corpus name | 255 characters max |
| Description | 1,000 characters max |
| Document size (per document) | 100,000 characters (auto-split if longer) |

---

## Next Steps

Once your corpus status is **Ready**, you can generate a benchmark from it: see [Benchmarks](benchmarks.md).

You can also upload corpora programmatically via the [CLI Guide](../cli-guide/index.md).