ontology_grounding: true, remember does two things with the graph the LLM extracts. It tags every entity and edge with what it matched (see ontologies.md), and it enriches the graph: the immediate ontology neighborhood of what matched is written into it, as entities and edges. This page is about the second part. The tags are never replaced by it, and the two work in both modes (annotate and strict).
The point: a graph of facts about Rex and Pip ends up connected to the concepts (Dog, Animal) the ontology defines, so that the hierarchy and the relations of the ontology can be followed in the graph itself.
What is added
Let M be the classes that the entities of the extraction matched, with no violation (a match through an alias counts). The neighborhood is:
Example, with an ontology where
Dog and Puppy are kinds of Animal/Dog, and Keeper keeps Animal. The text “Sam keeps Rex” extracts Sam (Keeper), Rex (Dog) and the edge Sam keeps Rex. The graph stored is that, plus:
What is not added
- The rest of the ontology. Only the classes that were matched in the call, and their ancestors, are brought in. Classes nobody mentioned, and relations with an end outside the subgraph, are not.
- Relations without fixed ends. A relation with no
domainor norangeis skipped. - Inferred facts. There is no reasoning: no transitive closure (an entity of
Puppygetsis_a Puppy, not alsois_a Dogandis_a Animal; followsubclass_offor that), and no inverse or inferred relations. - Write-backs. Nothing is written to the stored ontology; the call only writes to the graph.
- Entities that did not match. An entity with an unknown class or a violation is kept as in the grounding (tagged, or dropped in strict mode), but brings no neighborhood.
How the added rows behave
- Nodes are tagged like the matched ones. They are ordinary entities (embedded, found by
query), named after the class. An extracted entity with the same name as a class is the same entity (entities are unique by normalized name in a dataset). - Edges are tagged too:
origin_type=ontology,ontology_valid= true,ontology_class= the relation (is_a,subclass_of, or the ontology relation) andontology_versionof the ontology that defines it. Their description is the synthesized statement (Rex is a Dog.), andvalid_atis the reference time of the artifact, like any fact the text does not date. - No duplicates. An entity or an edge that the extraction already has (same name; same source, relation and target) is not added again. The edges then go through the usual reconciliation, so the same neighborhood from a later
rememberis a confirmation of the stored edges, not a new row. - Strict mode. The neighborhood is built from what was kept, so it never points to a dropped node.
- Origin.
origin_typeongb_entitiesandgb_edgessays where a row comes from:extracted(the LLM made it; the tags of the grounding) orontology(added by the enrichment);NULLfor rows never grounded.WHERE origin_type = 'ontology'isolates the enrichment, which can be filtered out of a query or deleted without touching the extracted facts. For an entity shared between artifacts, the origin of the latest grounded mention is kept. - Not counted as grounding. The summary in the response and
gb_ontology_eventsdescribe what the extraction made; the added entities and edges are not items of either. They show inres.entitiesandres.edges, and in the graph.
Where it is in the code
internal/memory/memory_ontology/ontospec/neighborhood.go:CompiledOntology.Neighborhood(classes), a pure function that returns the classes (ClassNode) and the edges (ClassEdge) of the subgraph, sorted. Tests:t_neighborhood_test.go.internal/memory/memory_remember/remember_ontology.go:addNeighborhoodturns it into entities and edges. It runs in theground_graphstage, right after the grounding is applied, so that the reconcile and store stages treat the new rows as part of the extraction. The constantsTypeOntologyClass(ontology_class) andRelationIsA(is_a) are there too; the hierarchy relation isontospec.RelationSubClassOf(subclass_of).