> ## 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.

# Context tree and concept graph

> Concepts are equal, contexts nest, and typed relations link concepts across the tree.

## Concepts are equal, contexts are hierarchical

* A concept has no parent and no children. It sits in exactly one context (`Concept.context`).
* A context has a `parent`. Contexts form a tree.
* Links between concepts are typed relations from the ontology. They are never tree edges.

```text theme={null}
TREE (parent to child)                        GRAPH (typed relations between concepts, may cross contexts)

Context A                                     c1 -- APPLIES_TO ----> c3     A1 to A2
|-- Context A1                                c2 -- EXCEPTION_OF --> c5     A1 to B
|   |-- Concept c1                            c4 -- CONTAINS ------> c1     A to A1
|   `-- Concept c2
|-- Context A2
|   `-- Concept c3
`-- Concept c4   (a concept may sit in a context that also has child contexts)

Context B
`-- Concept c5
```

A relation never changes where a concept sits.

## Containment is a relation

If concept A includes concept B, the ontology holds `CONTAINS(A, B)`, in one direction only so a fact is stored once. It follows the same rules as any relation: evidence is required, and search follows it in both directions.

| Situation | Expressed as |
| - | - |
| A and B belong to the same subject area | Both are placed in one context. |
| The text says A includes B | `CONTAINS(A, B)` with evidence. |

## Layers are depth

A node's level is its depth from the root, not its height above the leaves. Height changes when another branch grows. Depth is fixed once a context exists.

```text theme={null}
depth 1   broad contexts
depth 2   topics
depth n   the context that holds concepts
leaf      concepts: one fact each (level = context depth + 1)
```

Branches differ in depth, so "coarse" means "depth at most N", not "the top layer". The tree deepens only when a person decides, or when a quoted split supports it.

## Placing a concept

The extractor places a word one level at a time:

1. The candidates are the children of the chosen parent. The scope is the only hard filter.
2. The candidates are ranked by vector similarity, plus a boost when the document's metadata matches and a larger one when the section matches.
3. The top 3 of each level are kept, so a near miss can still win further down.
4. A model chooses one, or proposes a new draft context.
5. The choice is pinned, so a rebuild repeats it.

Lesson 1 runs this with a small registry of contexts and 3-number vectors that stand in for embeddings. The ranking only narrows the options. The extractor chooses.

## Vectors

| Node | Text embedded | Vector |
| - | - | - |
| Concept | `title + ". " + description` | `embed(text)`, stored with `embedding_model` |
| Context | `description`, falling back to `label` | `embed(description)` |

Vectors are derived. They are never exported, they are recomputed when the model changes, and search ignores one that comes from another model. Cosines of different node kinds are not comparable, so cosine is used only to choose entry points within one depth.

A context is never a search answer. Only concepts carry evidence, so a context hit always resolves to the concepts below it.

> [card] [Context summaries](https://ladygraph.io.vn/concepts/status-and-limits.md#context-summaries)
>
> One part of this design is described but not built yet.


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