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

# Architecture

> The packages that make up ladyGraph, what each one does, and what it imports.

ladyGraph is one folder of packages. In the component diagram, an arrow means "uses at run time". Separately, every package imports its types from `core`, and `core` imports no other package.

![C4 component diagram with one box per ladyGraph package and arrows showing which package uses which at run time](https://mintcdn.com/daves-tran/kGRmbJt6YCRhXS7k/images/ladygraph-components.png?fit=max\&auto=format\&n=kGRmbJt6YCRhXS7k\&q=85\&s=26af7b8c745dda9242ca72b21bd0b3c6)

Components, one per package

## Packages

| Package | What it does | Imports from |
| - | - | - |
| `core` | The data model (Concept, Evidence, Relation, Context, Contribution), the interfaces other packages implement, the ownership and merge rules, validation, validity periods, and the update loop `run_update`. | none |
| `sources` | Turns systems into Documents. `SqlSource` reads a database. `JsonSource`, `PydanticSource` and `MarkdownSource` read config and notes. Also a factory from a config file, and `SourceResolver`, which reads the live text of a piece of evidence. | `core` |
| `extractors` | `LlmOkfExtractor` prompts the model with one changed Document and returns one Contribution. The wording of its prompts is config. | `core`, `llm` |
| `authoring` | Tools that write config files for a deployment. Today that is the [term-list builder](https://ladygraph.io.vn/guides/term-list-builder.md). Nothing at index or search time imports it. | `core`, `extractors`, `sources`, `llm` |
| `llm` | `LlmClient` gives a structured JSON answer from Gemini (through ADK), a LiteLLM endpoint (Gemma) or a LiteRT-LM model on this machine, with retries and schema repair. Also Vietnamese to English translation, and the Google sign-in shared with the embedder. | none |
| `ner` | `SpanTagger` finds labelled spans in text without generating, for extractors that do not call an LLM per document. Includes `LiteRtGliner`, which runs GLiNER as a LiteRT model on this machine. | none |
| `chunking` | Cuts a long, loosely structured text into passages with a heading path. Rank patterns, stamps and repairs are config. | — |
| `translation` | Aligned translation with offsets, escalation across models with a check, verification by a second model, and term hints. A model is a function or an `LlmClient`. | — |
| `embedding` | `Embedder`, with `LiteRtEmbedder` (EmbeddingGemma on this machine) and `VertexEmbedder` (Google models). Vectors are unit length. | `core`, `llm` |
| `decision` | `Decider` can `pick` one option or none, and `score` texts. Implementations: DecisionLite, Clef, an LLM judge, a lexical decider and a composite. | `core`, `embedding`, `llm` |
| `retrieval` | `Searcher` does entry by vector, routing down the context tree, judging concepts, relation hops and evidence resolution. | `core`, `decision`, `embedding` |
| `stores` | `GraphStore` implementations: `InMemoryStore`, `LadybugStore` (embedded, one writer), `LadybugFlightStore` (a Ladybug server over Arrow Flight), and `open_index`. | `core` |
| `modal_deploy` | Modal apps that serve Gemma and Clef. Nothing else imports them. Use them as a starting point for your own deployment. | none |

## Dependency rules

* `core` defines the interfaces (`Source`, `Extractor`, `GraphStore`, `Embedder` and `Resolver`, in `core/pipeline.py`). The other packages implement them.
* `llm/base.py` defines `LlmClient`, `decision/base.py` defines `Decider`, and `retrieval/searcher.py` defines `ConceptSource`. Each interface is a `Protocol`, so a test can pass a fake.
* Every external service sits behind one adapter: the database in `sources/sql.py`, models in `llm/`, `embedding/` and `decision/`, and the index in `stores/`.
* `ner` imports no other package of ours. Its interface and helpers import no model SDK. `ner/litert_gliner.py` imports numpy, and imports `ai_edge_litert` and `tokenizers` only when a real model is built. It does not import torch or `gliner` unless you ask for that fallback.
* `llm/litert.py` imports `litert_lm` only when it first needs the engine.
* `authoring` is a leaf: nothing imports it, and it imports no model or gateway library. It reaches a model only through the `claude` CLI and a URL you configure. You run that endpoint yourself, outside ladyGraph.
* Each package that talks to a model or a database ships a fake (`llm/fake.py`, `embedding/fake.py`, `decision/fake.py` and `stores/memory.py`). That is how the test suite runs offline.

> [card] [How it works](https://ladygraph.io.vn/concepts/how-it-works.md)
>
> The indexing and search paths that these packages implement.


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