> ## Documentation Index
> Fetch the complete documentation index at: https://ladygraph.io.vn/llms.txt
> Use this file to discover all available pages before exploring further.

# Data model

> The records that feed the index and the records the index keeps.

The index is three structures over one set of nodes: a tree of contexts, a graph of concepts, and a vector per node. Each answers a different question, and one search combines them. None of them holds source text. The index keeps where a fact is written, never the words.

This page names no deployment. It speaks of domain knowledge (the documents, rules and entries an index is built from) and contexts (the topic tree that organizes it).

## The records and where they live

```text theme={null}
Source --manifest--> DocVersion per unit                 what changed? (hashes only)
Source --read------> Document { Passage, Passage, ... } the text, in memory only
                        |
                     Extractor       reads a Document, places and links what it finds
                        |
                     Contribution { Concept, Context, ContextChoice }   what one change unit adds
                        |
                     GraphStore.apply    (one transaction)
                        |
     Concept -in-> Context     Concept -SUPPORTED_BY-> Evidence     Concept -RELATES-> Concept
                        |
                     Searcher --> Hit { address, score, path, evidence }
                        |
                     Resolver    reads the live source to confirm the quote
```

| Record | Lives | Holds |
| - | - | - |
| `Document`, `Passage`, `Declared` | Memory, during extraction | The text. Never written to the index. |
| `Contribution` | Memory, between the extractor and the store | What one change unit adds. |
| `Concept`, `Context`, `Evidence`, `Relation` | The store | The index itself. |
| `ContextChoice` (a pin), `DocVersion` | The store | What makes a rebuild repeat itself, and what makes an update cheap. |

## Records that come from the source

### Document and passage

| `Document` field | Meaning |
| - | - |
| `address`, `scope`, `unit` | Where it is, which partition, which change unit. |
| `shape` | How rows became a document: `assemble` (many rows into one), `decompose` (one file into several) or `map` (one entry into one). |
| `version` | A `DocVersion`, described below. |
| `title`, `metadata` | Guide the choice of context: topics, group and type. The keys are free. |
| `passages` | The ordered text. |
| `access_labels` | Carried onto everything derived from the document. Never enforced here. They are only carried, and filtered at search. |
| `valid_from`, `valid_until` | The period the document is in force. Evidence goes stale after `valid_until`. |
| `declared` | An entry whose meaning a person declared in configuration, so no model is needed. |
| `rewrite`, `reading` | A flattened entry may be re-read once by a model. The reading is context for the extractor and is never evidence. |

A `Passage` has an `address`, its `text` as written (in memory only), a `fingerprint`, and a `section`, a heading or path that guides the choice of context.

### Document version

A `DocVersion` is three hashes, one for each kind of change.

| Hash | Covers | A change means |
| - | - | - |
| `file` | The source's own version marker, such as a version number or a checksum. | The unit changed. |
| `metadata` | Every metadata field, the access labels and the validity. | Placement may change. The text did not. |
| `passages` | The ordered passage fingerprints. | You can compute which passages changed. |

Comparing the stored `DocVersion` with the source's manifest classifies each unit as new, changed, unchanged or removed, without reading any text.

### Declared entries

A routing rule, a glossary term or a taxonomy already says what it is called and what people type for it. A `Declared` entry carries a `word` (the name), `keywords` (the user words: aliases, synonyms and markers) and `facts` (other `label: value` lines). It becomes one concept with no model call. Its passages still carry the text the evidence points at.

## Records the index keeps

### Concept

| Field | Meaning |
| - | - |
| `id`, `scope`, `path` | See [Addresses, ids and fingerprints](https://ladygraph.io.vn/concepts/addresses-and-fingerprints.md). |
| `type` | One of the ontology's concept types. |
| `context` | The one context it sits in. |
| `title`, `description` | The name, and one sentence. This is the text that is embedded. |
| `words` | `Word { text, kind, generated }`. A `document` word is what the text calls it. A `user` word is what people type, and it leads to the document word, never the reverse. |
| `evidence` | The `Evidence` records that say where it is written. |
| `relations` | The `Relation` records: typed links to other concepts. |
| `body` | The index's own writing, citing `[^evidence-id]`. |
| `generated`, `verified` | Actor stamps: `human:<id>`, `process:<id>` or `<agent>/<version>`, with a time. The trust tier is derived: unverified, machine or human. |
| `status` | `draft`, `stable` or `deprecated`. Only `stable` concepts are served. |
| `merged_into` | Set on a redirect left by a merge. |
| `embedding`, `embedding_model` | The vector of `"{title}. {description}"`, and the vector space it belongs to. A vector from another model is ignored at search. |
| `extra` | Free keys, usable as search facets. |

### Evidence

```text theme={null}
Evidence { id, resource, passage, start, length, fingerprint, unit, access_labels, stale_after }
```

Evidence is a position and a fingerprint, never text.

| Field | Meaning |
| - | - |
| `resource` | The passage address. |
| `passage` | The passage's fingerprint. Ownership is per passage. |
| `start`, `length` | Characters, in the faithful passage. |
| `fingerprint` | Of the span at that position. |
| `unit` | The change unit that contributed it. |
| `access_labels`, `stale_after` | Restamped from the document on every update. |

The model forbids extra fields, so a quote cannot be stored by accident. Evidence is made by locating a quote in code. A model only supplies the span it relied on. Code finds it in the passage and computes the position. A quote that cannot be found is dropped, and a concept left with no evidence does not exist.

At search time the resolver reads the live source and returns one status for each piece of evidence:

| Status | Meaning |
| - | - |
| `confirmed` | Found where it was recorded. |
| `moved` | Found elsewhere by fingerprint. The new position is returned. |
| `stale` | Gone or changed. |
| `unconfirmed` | The resolver timed out. |

### Relation

```text theme={null}
Relation { type, target, weight, evidence_ids, unit }
```

A relation is a typed edge from the concept that holds it to `target`, a concept id that may not exist yet. `type` is a relation of the ontology, which says which concept types it may join, its cardinality, and whether a machine may create it. `evidence_ids` point at evidence of the holding concept. A relation without evidence is allowed only if it is structural, meaning it came from the source's own data, and it is re-sent with every update.

### Context

| Field | Meaning |
| - | - |
| `id`, `scope` | See [Addresses, ids and fingerprints](https://ladygraph.io.vn/concepts/addresses-and-fingerprints.md). |
| `parent` | The parent context, or `None` for the top level of the scope. Depth is open and differs between branches. |
| `label` | The editable name. A rename moves the exported directory, not the id. |
| `description` | What the context holds. Read by whoever places or routes into it. |
| `metadata_seen` | Metadata values of the documents placed here. Used to boost candidates. |
| `embedding`, `embedding_model` | As for concepts. |
| `status` | `draft` (created by an extractor) or `stable` (accepted by a person). |
| `created_at` | Ties between equal candidates break on the older context. |

### Pin

A pin is a `ContextChoice { passage_fingerprint, metadata_version, word, context, generated }`. It records where a word of a passage was placed. A rebuild replays it instead of asking a model again, so rebuilding gives the same index. A change to the document's metadata re-opens the choice.

### Ontology

The ontology is configuration, not a record of the index. It is a set of concept types and relation types, each with allowed source and target types, a cardinality, and whether only a human may create it. It is checked in code when a contribution is applied. Changing it re-runs validation, not extraction.

> [card] [Context tree](https://ladygraph.io.vn/concepts/context-tree.md)
>
> How concepts are placed, and how they link.

> [card] [Ownership and merging](https://ladygraph.io.vn/concepts/ownership-and-merging.md)
>
> What happens when a contribution is applied.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.