# Audit the Patient Graph

URL: https://docs.clinia.com/docs/trust-and-governance/audit-the-graph

> Walk the graph endpoints to trace a fact back to its extracted facts, read why a pair did or did not merge, and review what a patient said against the chart.

## Trace a fact to the extracted facts behind it [#trace-a-fact-to-the-extracted-facts-behind-it]

A [fact](https://docs.clinia.com/docs/get-started/from-the-names-to-the-data-model#recorded-memory-objects) shows one value. Find out which [extracted facts](https://docs.clinia.com/docs/get-started/from-the-names-to-the-data-model#recorded-memory-objects) it rests on and what each of them stated.

1. Find the fact:

```bash
curl "https://<workspace-id>.w.clinia.cloud/v1/patients/{patientId}/graph/nodes/fact/items?perPage=1000" \
  -H "Authorization: Bearer <access-token>"
```

2. Walk [`resolves_to`](https://docs.clinia.com/docs/get-started/from-the-names-to-the-data-model#recorded-memory-objects) backwards to its members. Each edge runs `extracted_fact → fact`:

```bash
curl "https://<workspace-id>.w.clinia.cloud/v1/patients/{patientId}/graph/edges/resolves_to/items?touching={factId}" \
  -H "Authorization: Bearer <access-token>"
```

3. Open each extracted fact to see what its own source stated:

```bash
curl "https://<workspace-id>.w.clinia.cloud/v1/patients/{patientId}/graph/nodes/extracted_fact/items/{extractedFactId}" \
  -H "Authorization: Bearer <access-token>"
```

The fact carries only the winning value; each extracted fact keeps the dates, status and codes its source stated, so the comparison is between the extracted facts, one request each.

## See why two extracted facts merged [#see-why-two-extracted-facts-merged]

The same walk, one edge further: the pair's verdict.

Pass both extracted fact ids as `touching` to get the single [resolution decision](https://docs.clinia.com/docs/get-started/from-the-names-to-the-data-model#recorded-memory-objects) across that pair:

```bash
curl "https://<workspace-id>.w.clinia.cloud/v1/patients/{patientId}/graph/edges/resolution_decision/items?touching={idA}&touching={idB}" \
  -H "Authorization: Bearer <access-token>"
```

`payload.verdict` is `merge`, `payload.ruleId` names the stop rule that fired (`deterministic-code-exact`), and `payload.evidence` carries what each [cascade](https://docs.clinia.com/docs/get-started/patient-graph#how-the-engine-merges-records-into-facts) layer compared.

## See why two facts did not merge [#see-why-two-facts-did-not-merge]

Two entries that read as the same thing are two facts, so the walk starts from both and meets in the middle.

1. List the facts and pick the pair — two of the same `payload.type` that describe the same thing:

```bash
curl "https://<workspace-id>.w.clinia.cloud/v1/patients/{patientId}/graph/nodes/fact/items?perPage=1000" \
  -H "Authorization: Bearer <access-token>"
```

2. Expand each fact to its extracted facts, one request per fact:

```bash
curl "https://<workspace-id>.w.clinia.cloud/v1/patients/{patientId}/graph/edges/resolves_to/items?touching={factId}" \
  -H "Authorization: Bearer <access-token>"
```

3. Ask for the decision across one extracted fact from each side. This is the leg that crosses between the two facts, so it is the one that refused them:

```bash
curl "https://<workspace-id>.w.clinia.cloud/v1/patients/{patientId}/graph/edges/resolution_decision/items?touching={idA}&touching={idB}" \
  -H "Authorization: Bearer <access-token>"
```

`payload.verdict` is `reject`. `payload.ruleId` names the rule that refused the pair.

The decision can also be fetched on its own if the id is known.

```bash
curl "https://<workspace-id>.w.clinia.cloud/v1/patients/{patientId}/graph/edges/resolution_decision/items/{edgeId}" \
  -H "Authorization: Bearer <access-token>"
```

## See why two narratives did not merge [#see-why-two-narratives-did-not-merge]

[Narratives](https://docs.clinia.com/docs/get-started/from-the-names-to-the-data-model#recorded-memory-objects) resolve at the passage level, so the decision sits between two narrative passages rather than between the extracted narratives they were chunked from.

1. List the extracted narratives — one per block of free-form text the sources carried:

```bash
curl "https://<workspace-id>.w.clinia.cloud/v1/patients/{patientId}/graph/nodes/extracted_narrative/items?perPage=1000" \
  -H "Authorization: Bearer <access-token>"
```

2. Walk [`chunked_into`](https://docs.clinia.com/docs/get-started/from-the-names-to-the-data-model#recorded-memory-objects) from each to its passages. Each edge runs `extracted_narrative → narrative_passage`:

```bash
curl "https://<workspace-id>.w.clinia.cloud/v1/patients/{patientId}/graph/edges/chunked_into/items?touching={extractedNarrativeId}" \
  -H "Authorization: Bearer <access-token>"
```

3. Ask for the decision across one passage from each side:

```bash
curl "https://<workspace-id>.w.clinia.cloud/v1/patients/{patientId}/graph/edges/resolution_decision/items?touching={passageA}&touching={passageB}" \
  -H "Authorization: Bearer <access-token>"
```

A recorded `reject` reads like the fact case with the embedding layer in place of the codes: `payload.ruleId` is `narrative-cosine-reject-at-or-below-low`, and the `narrative-semantic-similarity` evidence carries the cosine `measurement` — the similarity itself, and the `mergeAtOrAbove` / `rejectAtOrBelow` bounds it was read against.

### When no decision was recorded at all [#when-no-decision-was-recorded-at-all]

Often the answer is empty — `data` is `[]` and `meta.total` is `0`. Two different things produce it, and the endpoint cannot tell them apart:

- **The pair was deferred.** Its similarity fell between the two bounds, the system was not confident enough to settle a decision.
- **The pair was never compared.** Each passage is only ranked against a set number of candidates, and a pair outside that set is never evaluated.

<Callout title="Settling the deferred band is on the roadmap">
  A further step that decides the pairs falling between the bounds, rather than leaving them open,
  is planned. Once it lands, a pair that was compared carries a decision either way, and an empty
  answer narrows to the second case.
</Callout>

## Review what the patient said against the chart [#review-what-the-patient-said-against-the-chart]

Contradictions between a [learned memory](https://docs.clinia.com/docs/get-started/from-the-names-to-the-data-model#learned-memory-objects) and a fact are [relationship](https://docs.clinia.com/docs/get-started/from-the-names-to-the-data-model#recorded-memory-objects) edges, so the whole inbox is one query:

```bash
curl -X POST "https://<workspace-id>.w.clinia.cloud/v1/patients/{patientId}/graph/edges/relationship/query" \
  -H "Authorization: Bearer <access-token>" \
  -H "Content-Type: application/json" \
  -d '{ "perPage": 1000, "filter": { "type": { "eq": "conflicts" } } }'
```

Each edge runs `learned_memory → fact` and says why it was drawn without leaving the edge: `payload.source` is `llm_inferred`, and `payload.attributes.fields` names the fields it conflicts on.

Open `from` for what was said — `payload.content` is the speaker's own words, whether the patient's or a caregiver's, `payload.sessionId` the session it was said in, and the node's `createdAt` when:

```bash
curl "https://<workspace-id>.w.clinia.cloud/v1/patients/{patientId}/graph/nodes/learned_memory/items/{memoryId}" \
  -H "Authorization: Bearer <access-token>"
```

Open `to` for the fact it contradicts, which carries the value the chart still holds:

```bash
curl "https://<workspace-id>.w.clinia.cloud/v1/patients/{patientId}/graph/nodes/fact/items/{factId}" \
  -H "Authorization: Bearer <access-token>"
```

To read every link of one memory, including the ones that agree with the record, see [Read Memories and Their Links to Facts](https://docs.clinia.com/docs/learned-memory/read-memories).
