Class CortexBuilder

java.lang.Object
ai.chatur.cortex.CortexBuilder

public final class CortexBuilder extends Object
Builds a 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 Details

    • DEFAULT_VIEW_HALF_LIFE

      public static final Duration 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

      public static CortexBuilder 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

      public CortexBuilder ontologies(List<String> turtle)
      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

      public CortexBuilder shapes(List<String> turtle)
      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

      public CortexBuilder rules(List<String> 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

      public CortexBuilder persistent(String assertionsLocation)
      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

      public CortexBuilder viewHalfLife(Duration 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.ZERO to disable decay and weight by the raw lifetime count instead.

      Parameters:
      viewHalfLife - the half-life, or Duration.ZERO to disable decay
      Returns:
      this builder, for chaining
    • build

      public ai.chatur.cortex.Cortex build()
      Assembles the knowledge graph.
      Returns:
      the assembled Cortex