This note introduces Semantica, an open source framework for building context graphs and decision layers that can be explained after the fact. It begins with the definition and the install command, then lists the modules that make up the package, from context and knowledge graph work to ontology, reasoning and ingestion. The feature sections give short code samples for decision tracking, temporal queries, provenance and SHACL validation, so you can see the shape of the API. A table covers the data sources it ingests, and there are notes on export formats, the pipeline builder and the integrations with graph databases, vector stores and model providers. Strengths, weaknesses and use cases close the page.
Definition
Semantica is an open-source framework for building context graphs and decision-intelligence layers for AI systems. Its goal is to turn chaos into intelligence, building AI systems that are explainable, traceable, and trustworthy — not "black boxes".
Context graphs record a decision, the reason, and similar past cases. Reasoning covers forward rules, Rete networks, deduction, and SPARQL. Provenance follows W3C PROV-O and can export a JSON or CSV audit log. Ontology tools can emit OWL and check SHACL shapes.
Installation
pip install semantica
Modules
| Module | Purpose |
|---|---|
semantica.context |
Context graphs, decision tracking, causal analysis |
semantica.kg |
Knowledge graph construction, algorithms |
semantica.semantic_extract |
NER, relation extraction, triplet generation |
semantica.reasoning |
Multiple reasoning engines |
semantica.vector_store |
FAISS, Pinecone, Weaviate, Qdrant, Milvus, PgVector |
semantica.ontology |
OWL generation, SHACL validation |
semantica.pipeline |
Pipeline DSL with retry policies |
semantica.graph_store |
Neo4j, FalkorDB, Apache AGE, Neptune |
semantica.ingest |
Files, web crawl, databases, Snowflake |
Feature Details
Context & Decision Intelligence
# Decision tracking
from semantica.context import ContextGraph
graph = ContextGraph()
graph.add_decision("选择PostgreSQL", context="database decision")
graph.record_decision("选择PostgreSQL", reason="scalability needs")
# Causal chains
graph.add_causal_relationship("选择PostgreSQL", "性能提升")
chain = graph.trace_decision_chain("选择PostgreSQL")
# Precedent search
similar = graph.find_similar_decisions("database migration")
# Policy engine
graph.check_decision_rules(decision)
Knowledge Graphs
- Entity & Relationship: Typed edges with 24 relationship types
- Graph Algorithms: PageRank, betweenness centrality, clustering coefficient
- Node2Vec Embeddings:
NodeEmbedderclass - Link Prediction:
LinkPredictorclass - Temporal Graphs: Incremental delta processing
Reasoning Engines
| Engine | Use Case |
|---|---|
| Forward chaining | IF/THEN rules |
| Rete network | High-throughput production rules |
| Deductive | Logical deduction |
| Abductive | Hypothesis generation |
| SPARQL | RDF querying |
from semantica.reasoning import Reasoner, ReteEngine
# Forward chaining
reasoner = Reasoner()
reasoner.add_rule("IF user.is_active AND subscription.is_valid THEN user.can_access")
results = reasoner.forward_chain(facts)
# Rete network for high-throughput
rete = ReteEngine()
rete.load_rules(rules)
rete.fire()
Temporal Intelligence (v0.4.0)
- Temporal GraphRAG: Retrieve knowledge as it existed at any point in the past
- Allen Interval Algebra: 13 deterministic interval relations
- Point-in-time query engine: With consistency validation
- Decision validity windows:
valid_from/valid_until
# Temporal queries
snapshot = graph.get_snapshot(timestamp="2024-01-01")
valid_decisions = graph.get_valid_decisions(as_of=datetime.now())
Provenance & Auditability
- Entity provenance via
ProvenanceTracker.track_entity() - W3C PROV-O compliant lineage tracking
- Full revision history and audit log export (JSON/CSV)
from semantica.provenance import ProvenanceTracker
tracker = ProvenanceTracker()
tracker.track_entity(entity_id, source="user_input", lineage=[])
export = tracker.export_audit_log(format="json")
Ontology & SHACL
from semantica.ontology import OntologyGenerator, OntologyEngine
# Auto-generate OWL
gen = OntologyGenerator()
owl = gen.generate_owl(entities, relationships)
# SHACL validation
shapes = OntologyEngine.to_shacl(graph, tier="standard")
validation = OntologyEngine.validate(graph, shapes)
Data Ingestion
| Source | Support |
|---|---|
| Files | PDF, DOCX, HTML, JSON, CSV, Excel, PPTX, archives |
| Web | WebIngestor class |
| Database | DBIngestor (any SQL) |
| Snowflake | SnowflakeIngestor |
| Advanced | Docling for complex documents |
Export Formats
- RDF: Turtle, JSON-LD, N-Triples
- Parquet
- ArangoDB AQL
- OWL ontologies
- SHACL shapes
Pipeline Builder
from semantica.pipeline import Pipeline
pipeline = (
Pipeline()
.stage("ingest", ingestor.ingest)
.stage("extract", extractor.extract)
.stage("validate", validator.validate)
.stage("store", storer.store)
.with_retry(max_attempts=3, backoff="exponential")
)
Integration
- Graph Databases: AWS Neptune, Apache AGE, FalkorDB
- Vector Stores: FAISS, Pinecone, Weaviate, Qdrant, Milvus, PgVector
- LLM Providers: 100+ models via LiteLLM (OpenAI, Anthropic, Cohere, Mistral, Ollama)
- Frameworks: LangChain, LlamaIndex, AutoGen, CrewAI
Plugins
- Claude Code: 17 domain skills
- Cursor: Specialized agents
- Codex: Integration support
Specialized agents:
decision-advisor: Decision making assistantexplainability: AI decision explanationkg-assistant: Knowledge graph construction
Strengths
| Strength | Description |
|---|---|
| Explainable AI | Full decision provenance; every decision can be explained |
| Complete audit trail | W3C PROV-O compliant |
| Multi-vector store | Flexible choice of storage backend |
| Temporal reasoning | Understands time and events over time |
| Strong integrations | LangChain, LlamaIndex, AutoGen, CrewAI, LiteLLM (100+ models) |
| Open source | MIT License |
Weaknesses
| Weakness | Description |
|---|---|
| High complexity | Many advanced features, steep learning curve |
| Requires KG knowledge | Requires knowledge graph fundamentals |
| Resources | Graph algorithms can be compute-intensive |
When to Use
- Regulated industries: Healthcare, finance, legal, government — where audit trails are required
- Explainable AI: When every AI decision must be explainable
- Enterprise knowledge management: With temporal reasoning
- Multi-agent pipelines: Cross-system context capture
- Complex decision systems: Need causal reasoning and precedent tracking
References:
See also: TrustGraph · Graph Comparison · Neural Memory