Class CortexBuilder
Cortex knowledge graph from ontology, shapes, and rules, without booting Spring.
This is the only supported way to assemble a Cortex outside of the Spring
auto-configuration: it loads the ontology, shapes, and rules; opens the assertions store and the
in-memory text index; and wires up the same eleven core services
ai.chatur.cortex.spring.CortexAutoConfiguration does. By default everything is held in memory,
which makes it well suited to tests that want a fresh, isolated graph without a Spring context.
Cortex cortex = CortexBuilder.create()
.ontologies(List.of(ontologyTurtle))
.shapes(List.of(shapesTurtle))
.rules(List.of(rulesText))
.build();
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DurationThe default half-life of a view's contribution to search ranking. -
Method Summary
Modifier and TypeMethodDescriptionai.chatur.cortex.Cortexbuild()Assembles the knowledge graph.static CortexBuildercreate()Creates a new builder, defaulting to an empty ontology, no shapes, no rules, and a fully in-memory graph.ontologies(List<String> turtle) Sets the ontology documents the knowledge graph is built on.persistent(String assertionsLocation) Makes the assertions persist to a TDB2 store on disk instead of in memory.Sets the Jena rules used for rule-based inference.Sets the SHACL shapes ingested assertions are validated against.viewHalfLife(Duration viewHalfLife) Sets how long it takes a view's contribution to search ranking to halve.
-
Field Details
-
DEFAULT_VIEW_HALF_LIFE
The default half-life of a view's contribution to search ranking.Mirrors
cortex.search.view-half-life, whose default must match: the two assembly paths are required to produce identical graphs.
-
-
Method Details
-
create
Creates a new builder, defaulting to an empty ontology, no shapes, no rules, and a fully in-memory graph.- Returns:
- the new builder
-
ontologies
Sets the ontology documents the knowledge graph is built on.- Parameters:
turtle- the ontology documents, in Turtle syntax, merged in order- Returns:
- this builder, for chaining
-
shapes
Sets the SHACL shapes ingested assertions are validated against.- Parameters:
turtle- the shapes documents, in Turtle syntax, merged in order- Returns:
- this builder, for chaining
-
rules
Sets the Jena rules used for rule-based inference.- Parameters:
rules- the rules documents, in Jena rules syntax, concatenated in order- Returns:
- this builder, for chaining
-
persistent
Makes the assertions persist to a TDB2 store on disk instead of in memory.The inference closure and text index are always an in-memory cache rebuilt from the assertions, regardless of this setting — see
TextIndexFactory.- Parameters:
assertionsLocation- the directory of the TDB2 store for assertions- Returns:
- this builder, for chaining
-
viewHalfLife
Sets how long it takes a view's contribution to search ranking to halve.Search results are weighted by how often each resource is deliberately opened; this controls how quickly that interest fades, so recent attention counts for more than attention that has since moved on. Pass
Duration.ZEROto disable decay and weight by the raw lifetime count instead.- Parameters:
viewHalfLife- the half-life, orDuration.ZEROto disable decay- Returns:
- this builder, for chaining
-
build
public ai.chatur.cortex.Cortex build()Assembles the knowledge graph.- Returns:
- the assembled
Cortex
-