semantica.kg transforms extracted entities and relationships into structured, queryable knowledge graphs:
  • Temporal nodes and edges with valid_from / valid_until windows and all 13 Allen interval relations
  • Full graph analytics suite: centrality, community detection, path finding, link prediction
  • Node2Vec structural embeddings for downstream ML and similarity scoring
  • OWL-Time export and versioned snapshots via TemporalVersionManager
  • Schema and constraint validation before persistence

Exported Classes

For conflict detection and advanced entity resolution, use semantica.conflicts and semantica.deduplication alongside this module.
Knowledge graph entity and relation structure: Person, Organization, Location, Date nodes with typed labeled edges

GraphBuilder

GraphBuilder constructs knowledge graphs from extracted entities and relationships. merge_entities defaults to False: pass True to enable entity deduplication during construction:

Optional content screening

GraphBuilder can screen raw text before NER, relation, or triplet extraction. Screening is off by default and never changes, blocks, or quarantines text. Enable it on the builder (including its nested config mapping) or per build() call; per-call values take precedence.
The dependency-free baseline scanner flags a small set of English instruction overrides and credential-disclosure requests, plus HTML comments containing those patterns. The comment then has one hidden_html_instruction finding spanning the whole comment, plus one finding for each baseline pattern that matched inside it. Those are separate findings for the same region. These are heuristic review signals: quoted or negated examples can match, and obfuscated or other-language attacks can be missed. No findings does not certify safe content. Extraction still receives the original text, including when an LLM extractor is selected.
  • screening_mode="annotate" adds a report for each screened text to the returned graph’s metadata.content_screening. A report contains text_index, method, status ("ok" or "error"), and findings.
  • text_index is the zero-based order of raw texts screened during that build, including texts inside nested source lists; it is not an entity ID or a top-level source index. Spans refer to the corresponding original text.
  • Each finding has an id, severity (info, low, medium, high, or critical), and a half-open [start, end] span in Python string characters. Reports do not copy source text or excerpts.
  • screening_mode="log" only logs finding counts and scanner failures; it adds no graph annotations. Annotation mode also logs those summaries.
  • Backend exceptions and invalid findings log a generic warning and allow extraction to continue. In annotation mode they produce status="error", so a failed scan is distinguishable from a successful scan with no findings. Unknown backends and invalid configuration raise ValueError.
Register a custom scanner through the existing ingestion registry:
Custom scanners accept exactly one string and return an iterable of ScreeningFinding objects. They are trusted application code; any dependencies, network access, or side effects belong to that backend. The baseline uses only the standard library. Coverage is limited to raw strings and text dictionaries that reach GraphBuilder._extract_from_text. extract=False and pre-extracted entities or relationships bypass screening. Direct extraction through MCP, Explorer enrich, and integration adapters is outside this feature’s scope. Annotations are returned graph metadata, not provenance records or node properties; the existing GraphStore persistence path does not persist these graph-level reports. ATR integration and blocking/quarantine policies are deferred.

Temporal Knowledge Graphs (v0.4.0+)

Full temporal reference including BiTemporalFact, TemporalReasoningEngine, Allen interval algebra, and TemporalNormalizer is covered in the dedicated Temporal Intelligence page. This section documents the KG-layer temporal API.
The temporal stack — see the Temporal Intelligence page for the full reference.

Building a Temporal Graph

Point-in-Time Queries

TemporalGraphQuery accepts optional constructor args; pass the graph into each query call:

Bi-Temporal Facts

BiTemporalFact is a dataclass — use the from_relationship() factory, not a positional constructor:

Allen Interval Algebra

TemporalReasoningEngine implements all 13 Allen relations deterministically — no LLM, no probability. It operates on TemporalInterval objects (not plain dicts):

Natural Language Temporal Parsing

Versioned Snapshots

See the Temporal Intelligence reference for the full class API, domain examples (personnel changes, policy evolution, financial timelines), and configuration options.

Similarity Scoring

SimilarityCalculator computes cosine, Euclidean, Manhattan, and correlation similarity between node embeddings:

Graph Analytics

Measure node importance across five algorithms. Use calculate_all_centrality() to run them all at once.

Algorithm Summary

GraphValidator

Validates graph structure: checks required fields, duplicate IDs, dangling edges, and optionally detects cycles and orphan nodes:
Pass strict=True to treat warnings as errors. Pass a schema dict with "entity_types" and "relationship_types" keys to validate against a known type vocabulary.

Configuration

  • Graph Store — Persist graphs in Neo4j, FalkorDB, or Apache AGE.
  • Semantic Extract — Source of entities and relationships fed to GraphBuilder.
  • Visualization — Visualize knowledge graphs interactively.
  • Conflicts — Conflict detection and resolution.

Cookbooks