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

# Interfaces

> The interfaces the pipeline connects, and what implements each one.

The update stage connects four interfaces: `Source`, `Extractor`, `GraphStore` and `Resolver`. An `Embedder` and a `Decider` serve indexing and search. Each interface is a `Protocol`, so a test can pass a fake. The pages for each package list every class and function. This page shows the contracts.

## Pipeline interfaces

```python theme={null}
class Source(Protocol):             # ingestion; batch; used only by update
    scheme: str
    shape: Literal["assemble", "decompose", "map"]
    def manifest(self, scope: str, now: datetime) -> dict[str, DocVersion]: ...  # valid units only; cheap
    def read(self, scope: str, unit: str) -> Document: ...
    def next_boundary(self, scope: str, now: datetime) -> datetime | None: ...   # earliest upcoming valid_from or valid_until

class Resolver(Protocol):           # search time; batched; used only by search
    scheme: str
    def resolve_many(self, evidence: list[Evidence], timeout_s: float) -> dict[str, Resolution]: ...

class Resolution(BaseModel):
    status: Literal["confirmed", "moved", "stale", "unconfirmed"]   # unconfirmed = timed out
    start: int | None = None        # new start when moved
    content: str | None = None      # passage text, only when the caller asked for it

class Extractor(Protocol):          # indexing; a document to concepts
    def extract(self, doc: Document, changed: set[str], ontology: Ontology,
                registry: ContextRegistry, pinned: list[ContextChoice],
                context_only: bool) -> Contribution: ...

class GraphStore(Protocol):         # materialization
    def apply(self, contribution: Contribution) -> None: ...   # atomic; follows the ownership rules
    def drop_unit(self, scope: str, unit: str) -> None: ...
    def versions(self, scope: str) -> dict[str, DocVersion]: ...
    def pinned(self, scope: str, unit: str) -> list[ContextChoice]: ...
    def known_types(self, scope: str) -> dict[str, str]: ...   # concept id -> type, for relation checks
    def registry(self, scope: str) -> ContextRegistry: ...
    def search(self, q: Query) -> list[Hit]: ...
    def export(self, scope: str, path: Path) -> None: ...

class Embedder(Protocol):
    model: str                       # names the vector space; vectors of different models are never compared
    dimensions: int | None           # None until the first call, for an endpoint that reports its size then
    def embed(self, texts: Sequence[str], *, kind: EmbedKind = "document") -> list[list[float]]: ...
    async def aembed(self, texts: Sequence[str], *, kind: EmbedKind = "document") -> list[list[float]]: ...
```

For the `Extractor`, `changed` is the fingerprints of the passages to work on, and every other passage is left alone. `context_only` means the text did not change, so the extractor re-chooses contexts without re-extracting.

### The embedder contract

* One vector per text, in order.
* Every vector has `dimensions` values and unit length, so cosine is a dot product. A text with no content may embed to the zero vector.
* `kind` is `"document"` for stored text (concepts and contexts) and `"query"` for a search question. Models with separate query and document prompts use it, and the others ignore it.
* `embedding.check_vectors` verifies a batch against this contract.

## The update stage

Update runs daily, and also at each document's next validity boundary. It does three things:

1. It compares `Source.manifest()` with `GraphStore.versions()`, part by part.
2. For each new or changed unit, it reads the document and decides what to run on and what to replace:

   * **New unit:** every passage, and the whole unit is replaced.
   * **File or passages changed:** the new or changed passages, replacing those plus any passages that disappeared.
   * **Metadata only:** the passages whose pinned choice was made under other metadata, for context only, replacing those.

   It then validates and applies the result. A contribution whose `replaces` does not match is an extractor bug and stops the update.
3. For each unit that is no longer valid, it calls `drop_unit`. Every created, merged, moved, deprecated or deleted concept gets an entry in `log.md`.

## The resolver

The resolver confirms evidence in three steps:

1. Hash the faithfully normalized passage at `start`.
2. If that fails, slide across the passage looking for the fingerprint, and record the new `start`.
3. If the fingerprint is found nowhere, mark the evidence stale.

Faithful normalization means Unicode NFC and runs of whitespace collapsed. Case, diacritics, punctuation, digits and symbols are kept. The lossy normalization used to match user words is never used here.

The resolver has its own connection pool and fails open on timeout. It is never asked about a document the reader has not cleared.

## The query

```python theme={null}
class Query(BaseModel):
    scope: str
    text: str | None = None
    vector: list[float] | None = None
    seeds: int = 5                          # top-k concepts
    hops: int = Field(1, le=2)              # bounded traversal
    fanout: int = 10                        # per hop
    relation_types: list[str] | None = None
    facets: dict[str, list[Any]] = {}       # hard filter, e.g. from a route rule
    access_filter: list[str] | None = None  # labels the reader cleared; applied to concepts before traversal
    resolve: bool = False                   # fetch live content through the resolver
    now: datetime | None = None             # validity is checked against this; default: current time

class Hit(BaseModel):
    address: Address
    score: float
    path: list[str]                         # query -> concept id -> relation type -> address
    evidence_id: str                        # for precise citation
    context_path: list[str] = []            # the labels of the concept's context, top level first
    access_labels: list[str]
    resolution: Literal["confirmed", "moved", "unconfirmed"] | None = None
    content: str | None = None              # only when resolve=True and confirmed or moved
```

The reader decides `access_filter`, and ladyGraph applies it without judging it. Concepts are filtered too, not only passages, because concept text is written from the sources.

Callers use the Python library directly.

## What implements each interface

| Interface | Implementations in the code |
| - | - |
| `Source` | `SqlSource` (assemble, configured in YAML), `JsonSource` and `PydanticSource` (map, with a JSON Pointer per entry), `MarkdownSource` (decompose, with heading anchors), and `CombinedSource` (several sources in one scope). `MarkdownSource` also takes `chunking:`. See [sources](https://ladygraph.io.vn/reference/api/sources.md). |
| `Resolver` | `SourceResolver`, which reads the live text of a piece of evidence. |
| `Extractor` | `LlmOkfExtractor`, `DeclaredExtractor`, `LexiconExtractor`, `ReadingExtractor`, `NerExtractor` (kind `ner`) and `TranslateNerExtractor` (kind `translate_ner`). See [extractors](https://ladygraph.io.vn/reference/api/extractors.md). |
| `GraphStore` | `InMemoryStore`, `LadybugStore` (in-process) and `LadybugFlightStore` (the Flight server). See [stores](https://ladygraph.io.vn/reference/api/stores.md). |
| `Embedder` | `LiteRtEmbedder` (EmbeddingGemma 270M on this machine), `VertexEmbedder` (Google models), and the test doubles `HashEmbedder` and `TableEmbedder`. See [embedding](https://ladygraph.io.vn/reference/api/embedding.md). |

> [card] [core](https://ladygraph.io.vn/reference/api/core.md)
>
> The records and the interfaces.

> [card] [retrieval](https://ladygraph.io.vn/reference/api/retrieval.md)
>
> `Searcher` and `SearchConfig`.


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