semantica.kg transforms extracted entities and relationships into structured, queryable knowledge graphs:
- Temporal nodes and edges with
valid_from/valid_untilwindows 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
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.
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’smetadata.content_screening. A report containstext_index,method,status("ok"or"error"), andfindings.text_indexis 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, orcritical), 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 raiseValueError.
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.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
Similarity Scoring
SimilarityCalculator computes cosine, Euclidean, Manhattan, and correlation similarity between node embeddings:
Graph Analytics
- Centrality
- Community Detection
- Path Finding
- Link Prediction
- Node Embeddings
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: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
- Building Knowledge Graphs: fundamentals of KG construction · Beginner
- Your First Knowledge Graph: entity extraction to visualization · Beginner
- Graph Analytics: centrality and community detection · Intermediate
- Advanced Graph Analytics: PageRank, Louvain, shortest path · Advanced
- Temporal Knowledge Graphs: temporal logic and graph evolution · Advanced
