<!-- Sema documentation — std.provenance
     Sema is a new AI-native, neurosymbolic programming language most models
     have not been trained on. Full corpus: https://sema.49.12.246.95.sslip.io/llms-full.txt
     Install language support: https://sema.49.12.246.95.sslip.io/install-skill/ -->

# std.provenance

> Reflected API reference for the Sema standard-library module std.provenance.

> Generated by `sema doc` from `stdlib/sema/provenance.sema`. Import with `from std.provenance import …`. For a narrative introduction see [std.provenance](/stdlib/provenance/).

# `provenance`

std.provenance — citation id mapping + rewrite (design ⑥).

Assign each unique source URL a stable global id (first-seen order) and rewrite a
result's local `[n]` citation markers to those global ids. Replaces eai-search's
`_build_url_to_id_mapping` + `_rewrite_text_with_global_ids`.

# `struct Cit`

**Fields**

| field | type | descriptor |
|---|---|---|
| `url` | `str` |  |
| `start` | `int` |  |
| `end` | `int` |  |

# `struct Doc`

**Fields**

| field | type | descriptor |
|---|---|---|
| `text` | `str` |  |
| `citations` | `list[Cit]` |  |

# `build_url_to_id`

```sema
def build_url_to_id(docs: list[Doc]) -> dict !{}
```

**Parameters**

| name | type |
|---|---|
| `docs` | `list[Doc]` |

**Returns** `dict`

**Effects** `!{}`

# `by_start`

```sema
def by_start(cits: list[Cit]) -> list[Cit] !{}
```

**Parameters**

| name | type |
|---|---|
| `cits` | `list[Cit]` |

**Returns** `list[Cit]`

**Effects** `!{}`

# `rewrite`

```sema
def rewrite(text: str, cits: list[Cit], ids: dict) -> str !{}
```

**Parameters**

| name | type |
|---|---|
| `text` | `str` |
| `cits` | `list[Cit]` |
| `ids` | `dict` |

**Returns** `str`

**Effects** `!{}`
