The Problem

Enterprise AI pipelines need more than fuzzy text similarity; they must expose why a decision was made, trace every transformation, and enforce domain constraints. Without a dedicated semantic layer, provenance is lost, conflicts go unnoticed, and audits become manual and error‑prone.

What This Does

semantica provides a reusable knowledge‑engineering stack that extracts entities, builds ontologies, and stores provenance‑rich graphs. Core code lives in semantica/ (304 files, 282 Python modules). The CLI (semantica/cli.py) and HTTP server (semantica/server.py) expose the same engine, while semantica/utils/* supply cross‑cutting services such as logging, exception types, and progress tracking. The cookbook supplies 47 notebooks that demonstrate end‑to‑end use‑cases (e.g., cookbook/advanced/09_Semantic_Layer_Construction.ipynb).

Key modules:

  • semantica/semantic_extract/ner_extractor.py – NER pipeline.
  • semantica/semantic_extract/triplet_extractor.py – relation extraction.
  • semantica/graph_store/graph_store.py – abstract graph‑store API (Neptune, SQLite, etc.).

How It Is Wired

Execution starts at semantica/cli.py:main (line 20). The CLI parses sub‑commands (build, run, etc.) and then invokes up to 308 functions across the codebase.

  • Bootstrap – __init__ of many modules immediately calls utils.logging.get_logger (used by 206 other modules) and utils.progress_tracker.get_progress_tracker (used by 115 modules). These two utilities form the hub whose stability directly affects most of the repository.
  • Provenance flow – run (implemented in semantica/worker.py:run) creates a track_entity call, which eventually reaches semantica/context/agent_context.py:retrieve and opens a SQLite connection (sqlite3.connect). The shortest external‑touch path is: run → track_entity → retrieve → sqlite3.connect (database write).
  • Server path – semantica/server.py:health builds a statistics response that calls stats → get_statistics → retrieve_all → sqlite3.connect, again a single‑hop DB read.
  • Graph store – semantica/graph_store/graph_store.py:execute (line 254) creates a cache key via hashlib.md5, then returns a result after 232 internal calls.
  • Model inference – semantic_extract/providers.py wraps calls to external transformer models (e.g., sentence‑transformers).
  • Blast radius – utils.logging, utils.exceptions, and utils.progress_tracker together receive > 200 import edges each; any API change ripples through most of the 671‑file repo.
  • Cycles – ner_extractor, triplet_extractor, and relation_extractor participate in a circular import, raising the risk of subtle import‑time failures.
  • External effects – 78 functions read/write files, 23 make network calls (e.g., Neptune), 34 touch a database, 9 invoke LLM inference, and 16 perform cryptographic hashes.

How To Use It

# Install the package (the README shows this)
pip install semantica

Run the CLI

python -m semantica.cli build --method ml --model en_core_web_sm "sample.txt"

cli.py will load the NER extractor, build a graph, and persist provenance in the default SQLite store.

Run the server

python -m semantica.server

The HTTP service exposes /health (calls server.py:health) and graph query endpoints that ultimately hit graph_store/graph_store.py.

Docker – the repo ships docker-compose.yml; building the stack with docker compose up reproduces the same environment, including the Neo4j/Neptune connectors defined under semantica/graph_store/.

Configuration files are not explicit; the code expects environment variables for external stores (e.g., NEPTUNE_ENDPOINT) and reads semantica/conflicts/config.py for runtime flags.

Real‑World Use

A financial‑compliance team can ingest transaction logs, run NERExtractor to tag parties, feed the results to GraphBuilder, and store the graph in Neo4j. The provenance manager records each ingestion step, allowing auditors to query “which document created this relationship?” via the server’s /graph endpoint, while the built‑in conflict detector flags contradictory entity attributes.

Code Health & Issues

Measured static findings (279 total)

  • High cognitive load – deep nesting (max depth 8) and oversized files (> 1 200 LOC) in utils/progress_tracker.py, semantic_extract/methods.py, semantic_extract/triplet_extractor.py.
  • Broad exception handling – generic except: blocks in the same modules.
  • Hub modules – utils/logging.py, utils/exceptions.py, utils/progress_tracker.py each imported by > 180 modules.
  • Import cycles – semantic_extract/ner_extractor.py, triplet_extractor.py, relation_extractor.py.
  • High branching density – 578 branches in semantic_extract/methods.py.

Repository‑level health audit (9 findings)

  • HIGH Pin GitHub Actions to commit SHAs (.github/workflows/*).
  • HIGH Add a lockfile (poetry.lock / requirements.txt) beside pyproject.toml.
  • HIGH Run the test suite in CI (no test step present).
  • HIGH Remove continue-on-error from correctness steps (security.yml).
  • MEDIUM Declare least‑privilege GITHUB_TOKEN permissions (ci.yml).
  • MEDIUM Split massive notebook cells (cookbook/advanced/06_Multi_Source_Data_Integration.ipynb).
  • MEDIUM Move large binaries (> 5 MB) to Git LFS (cookbook/use_cases/blockchain/transaction_network.html).
  • MEDIUM Set persist-credentials: false on actions/checkout.
  • LOW Add explicit timeout-minutes to workflow jobs.

The Bottom Line

semantica delivers a concrete, extensible semantic layer with built‑in provenance and conflict detection, suitable for regulated domains that need audit trails. The codebase is functional but suffers from heavy centralisation, deep nesting, and a few CI hygiene gaps; addressing the high‑impact hub modules and CI fixes will markedly improve maintainability and reliability. Engineers ready to embed traceable knowledge graphs will find it usable, provided they allocate effort to refactor the identified hot spots.