32  Graphs and lineage

Build a k-nearest-neighbour graph over a corpus’s embeddings, smooth the embeddings over it, derive structure embeddings from the graph alone — then ask the engine what produced each table and whether it still holds.

When to use this pattern. You derive tables from tables (a graph from embeddings, smoothed vectors from a graph) and need to know, later, exactly what produced a table, whether its bytes are still the ones recorded, whether it is stale against the definition you run now, and what depends on it.

The program is cookbook/recipes/graph_and_lineage/example.py; its steps run here in order.

A corpus’s embeddings become a k-nearest-neighbour graph; the graph smooths the embeddings (propagation) and, on its own, yields structure embeddings for nodes with no text. Every one of those tables records what produced it, so the engine answers the provenance questions a pipeline asks.

import tempfile

import jammi
from jammi_cookbook import fixtures

MODEL = fixtures.model("tiny_bert")

db = jammi.connect(f"file://{tempfile.mkdtemp()}")
db.add_source("corpus", url=str(fixtures.path("tiny_corpus.parquet")), format="parquet")
emb = db.generate_embeddings(
    source="corpus", model=MODEL, columns=["content"], key="id", modality="text"
)
2026-10-03T07:44:56.917482Z  WARN jammi_kernels::admission: fused-kernel domain check failed; falling back to the eager composition op="attention_block_fused" predicate="head_dim_is_attention_block_fixed_head_dim"

32.1 The neighbour graph

build_neighbor_graph writes the corpus’s k-nearest-neighbour edges as a table: 20 rows with k = 3 is 60 edges. Graph verbs take the source; the embedding table is the source’s current one unless embedding_table= names another. A result table reads in SQL as "jammi.<table>".

graph = db.build_neighbor_graph("corpus", k=3, exact=True)
edges = db.sql(f'SELECT COUNT(*) AS n FROM "jammi.{graph}"').to_pylist()[0]["n"]
print(f"neighbor graph: {edges} edges")
assert edges == 60
neighbor graph: 60 edges

32.2 Propagate over it, and embed its structure

propagate_embeddings mixes each node’s vector with its neighbours’ (one hop; alpha is how much of the node itself is kept), a decoupled GNN layer whose output is a new, searchable embedding table. generate_structure_embeddings makes vectors from the graph’s shape alone, for nodes that carry no content to embed.

propagated = db.propagate_embeddings(
    "corpus", embedding_table=emb, edge_graph_table=graph, hops=1, alpha=0.5
)
print(f"propagated embeddings: {propagated}")

structure = db.generate_structure_embeddings(
    "corpus", key_column="id", edge_graph_table=graph, dimensions=8, seed=0
)
print(f"structure embeddings: {structure}")
propagated embeddings: corpus__model__20261003T074456958326014_ed61a9f1
structure embeddings: corpus__model__20261003T074456988505368_6bf3b0f5

32.3 What produced a table

describe_table returns a table’s record: the producing verb and its parameters, the models that ran (none: propagation runs no model), and the tables it read, each anchored by digest. definition_hash identifies that definition.

described = db.describe_table(propagated)
recorded = described["definition_hash"]
print(f"produced by: {described['descriptor']['producer']}")
print(f"models run: {len(described['env']['models'])}")
for anchor in described["input_anchors"]:
    print(f"  input {anchor['source'][:40]}… anchored by {anchor['kind']}")
assert described["env"]["models"] == []
produced by: graph_propagation
models run: 0
  input corpus__text_embedding_____w_jammi-ai_ja… anchored by result_digest
  input corpus__neighbor_graph__20261003T0744569… anchored by result_digest

32.4 Does it still hold?

verify_materialization checks that the table’s bytes still hash to the recorded digest, and that the definition you expect is the one recorded. staleness asks whether the table is still the output of a definition: the recorded one is fresh (every input is another table, pinned by digest); a different one is stale, and the answer says why.

verdict = db.verify_materialization(propagated, expected_definition=recorded)
print(f"verify against the recorded definition: {verdict['verdict']}")
assert verdict["verdict"] == "match"

fresh = db.staleness(propagated, recorded)
print(f"staleness (recorded definition): {fresh['staleness']}")
assert fresh["staleness"] == "fresh"

stale = db.staleness(propagated, "0" * len(recorded))
reasons = ", ".join(r["reason"] for r in stale["reasons"])
print(f"staleness (another definition): {stale['staleness']} ({reasons})")
assert stale["staleness"] == "stale"
verify against the recorded definition: match
staleness (recorded definition): fresh
staleness (another definition): stale (definition_changed)

32.5 What depends on it

derives_from lists the tables built from a table: here, the graph and the propagated embeddings were both built from the base embeddings.

derived = db.derives_from(emb)
for edge in derived:
    print(f"derives_from: {edge['derived'][:48]}… ({edge['kind']})")
assert {graph, propagated} <= {edge["derived"] for edge in derived}
derives_from: corpus__neighbor_graph__20261003T074456934739786… (result_digest)
derives_from: corpus__model__20261003T074456958326014_ed61a9f1… (result_digest)

32.6 Recompute, and reconcile

recompute re-runs a table’s recorded producer; with cascade="report_only" it reports what downstream is now stale without recomputing it. reconcile cross-checks the catalog against the object store; a dry run reclaims nothing.

report = db.recompute(graph, cascade="report_only")
print(
    f"recomputed {len(report['recomputed'])} table(s); "
    f"downstream stale: {len(report['downstream_stale'])}"
)
assert len(report["recomputed"]) == 1

drift = db.reconcile()
print(f"reconcile (dry run): {drift}")
recomputed 1 table(s); downstream stale: 2
reconcile (dry run): {'scope': '_global', 'applied': False, 'rows_failed': [], 'rows_failed_count': 0, 'orphans': [], 'orphan_count': 0, 'pending': [], 'pending_count': 0, 'unattributed': [], 'unattributed_count': 0, 'damaged': [], 'damaged_count': 0, 'referenced': [], 'referenced_count': 0, 'truncated': False, 'bytes_reclaimed': 0}
db.close()