> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/curator/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/curator/_mcp/server.

# nemo_curator.stages.text.modules.joiner

## Module Contents

### Classes

| Name                                                                        | Description                                                        |
| --------------------------------------------------------------------------- | ------------------------------------------------------------------ |
| [`DocumentJoiner`](#nemo_curator-stages-text-modules-joiner-DocumentJoiner) | Joins documents that have a common id back into a single document. |

### API

```python
class nemo_curator.stages.text.modules.joiner.DocumentJoiner(
    separator: str = '\n\n',
    text_field: str = 'text',
    segment_id_field: str = 'segment_id',
    document_id_field: str = 'id',
    drop_segment_id_field: bool = True,
    max_length: int | None = None,
    length_field: str | None = None,
    name: str = 'document_joiner'
)
```

Dataclass

**Bases:** [ProcessingStage\[DocumentBatch, DocumentBatch\]](/nemo-curator/nemo_curator/stages/base#nemo_curator-stages-base-ProcessingStage)

Joins documents that have a common id back into a single document.
The order of the documents is dictated by an additional segment\_id column.
A maximum length can be specified to limit the size of the joined documents.

The joined documents are joined by a separator.

This stage performs the inverse operation of DocumentSplitter, allowing you
to reconstruct documents from their segments.

**Parameters:**

**`separator`** `str` — default: '\n\n'

The separator to join the documents on.

---

**`text_field`** `str` — default: 'text'

The name of the column containing the text to join.
Defaults to "text".

---

**`segment_id_field`** `str` — default: 'segment\_id'

The name of the column containing the segment id.
Defaults to "segment\_id".

---

**`document_id_field`** `str` — default: 'id'

The name of the column containing the document id.
Defaults to "id".

---

**`drop_segment_id_field`** `bool` — default: True

Whether to drop the segment\_id\_field after joining.
Defaults to True.

---

**`max_length`** `int` — default: None

The maximum length of the joined documents.
Both max\_length and length\_field must be specified or neither can be specified.

---

**`length_field`** `str` — default: None

The name of the column containing the length of the documents.
Both max\_length and length\_field must be specified or neither can be specified.

---

**`document_id_field`** `str = 'id'`

---

**`drop_segment_id_field`** `bool = True`

---

**`length_field`** `str | None = None`

---

**`max_length`** `int | None = None`

---

**`name`** `str = 'document_joiner'`

---

**`segment_id_field`** `str = 'segment_id'`

---

**`separator`** `str = '\n\n'`

---

**`text_field`** `str = 'text'`

---

```python
nemo_curator.stages.text.modules.joiner.DocumentJoiner.__post_init__()
```

```python
nemo_curator.stages.text.modules.joiner.DocumentJoiner._join_segments(
    group: pandas.DataFrame
) -> pandas.DataFrame
```

Join segments with max\_length constraint.

```python
nemo_curator.stages.text.modules.joiner.DocumentJoiner.inputs() -> tuple[list[str], list[str]]
```

Define stage input requirements.

```python
nemo_curator.stages.text.modules.joiner.DocumentJoiner.outputs() -> tuple[list[str], list[str]]
```

Define stage output specification.

```python
nemo_curator.stages.text.modules.joiner.DocumentJoiner.process(
    batch: nemo_curator.tasks.DocumentBatch
) -> nemo_curator.tasks.DocumentBatch
```

Joins the documents back into a single document while preserving all the original fields.

**Parameters:**

**`batch`** `DocumentBatch`

Input batch to process

---

**Returns:** `DocumentBatch`

Batch with documents joined by document\_id