Skip to content

Knowledge Graphs & Grounded Reasoning ​

Vector search finds paragraphs that sound similar to a question, but it cannot verify whether a multi-hop claim is true, weigh conflicting evidence, explain why a conclusion follows (or fails), run a counterfactual scenario, or evaluate a quantitative formula.

Kompile pairs hybrid retrieval with a Unified Knowledge Graph (.kgraph) and a multi-engine reasoning stack — running both folder-locally (offline via local-runtime with zero server) and on a Kompile server — while keeping the agent-facing API in plain English so you never need to know PSL, MEBN, or first-order logic to use it.

TIP

Want a step-by-step hands-on tutorial? Follow Walkthrough: Crawling PDFs & Querying Knowledge Graphs (Local & Remote) to verify out-of-the-box tools, crawl text-native and scanned PDFs in both local and remote modes, and run graph verification and reasoning queries.


1. The golden path (no formal logic required) ​

Most agents and users only need five operations:

  1. Load data into the graph:
    • Crawl a file, folder, URL, or text snippet with crawl_source (automatically extracts entities, relations, provenance chunks, and projects them into the KB), or
    • Import an existing .kgraph bundle with graph_import, or
    • Project your codebase structure via kompile code-index.
  2. Discover the vocabulary:
  3. Verify a claim before stating it:
    • Call ask_graph_verify atom="worksFor(Alice, Acme)" → returns SUPPORTED, REFUTED, or UNKNOWN, a confidence score in [0, 1], and the supporting/counter evidence.
    • Supports point-in-time verification via asOf (server) or validAt (local valid-time filter).
  4. Query patterns, paths & explanations:
  5. Run unified structural, counterfactual, or formula queries:
    • Call graph_reasoning_query with one of its 21 typed operations (discoverable via operation=CAPABILITIES):
Categorygraph_reasoning_query Operations
Discovery & SearchCAPABILITIES, OVERVIEW, SCHEMA, SEARCH, RELATIONS, DESCRIBE, NEIGHBORS, FACTS, SIMILAR, RANK
Traversal & TimePATH (shortest path between two entities), TIMELINE (time-ordered events)
Verification & TraceVERIFY, WHY (why a relation holds), WHY_NOT (why it fails and what would change it)
Quantitative ModelsMODELS (discover executable formulas), CALCULATE, SCENARIO (apply counterfactual interventions), SOLVE_TARGET (goal-seek an input to hit a target measure)
Graph Bundle AssetsASSETS (vector layers & weight maps), ARTIFACT (inspect named attached artifacts)

2. How the reasoning stack works under the hood ​

Kompile combines symbolic logic, ontologies, probabilistic graphical models, neural graph embeddings, and quantitative formulas over one shared graph representation:

Engine / LayerWhat It DoesPrimary Tool(s)
Ontologies & Fuzzy TypesImports/exports OWL/Turtle (.ttl), bridges GraphSchema to TypeRegistry, runs OWL-RL entailment (OwlRlReasoner), and carries first-class fuzzy type memberships (FuzzyTypeMembership) across FOL, Datalog, PSL, and TMS.knowledge_graph, graph_reasoning_query
Crisp Logic & Truth Maintenance (Datalog + FOL + TMS)Materializes derived facts from datalog_rules, maintains derivation trees, tracks negative evidence (NOT_ relations), and updates dependent conclusions when facts are explicitly asserted or retracted.ask_graph_query, ask_graph_verify, ask_graph_explain, ask_graph_assert, ask_graph_retract
Probabilistic Soft Logic (PSL / ADMM)Runs bounded Java ADMM MAP inference over the portable PSL/HL-MRF program (reasoning/fol-psl-program.v1.json) to produce continuous truth values in [0, 1] and counterfactual soft-logic updates with explicit evidence clamping.graph_psl
Probabilistic & Causal Networks (MEBN + Bayes)MEBN / SSBN (ask_graph_mebn) evaluates learned Multi-Entity Bayesian Network models (reasoning/mebn-theory.v1.json) around an anchor node with optional evidence conditioning. graph_bayes builds structural Bayesian networks from topology and adds mpe, sensitivity, and whatif queries. Remote servers also support causal:<event> attribution in graph_reason.ask_graph_mebn, graph_bayes, graph_reason
Subjective Logic OpinionsStores belief, disbelief, uncertainty, and base-rate (opinions.jsonl) instead of collapsing conflicting evidence into a single opaque float — rendered to agents as plain-English support, counter-evidence, and uncertainty.ask_graph_verify, ask_graph_explain_fused, ask_graph_claim
Knowledge Graph Embeddings (KGE)Trains TransE / RotatE triple-scoring vectors (models/kge.json) during crawl learning (LearningSubprocessMain) for link prediction and entity similarity alongside dense vector layers (vectors/*.kvec).graph_embeddings, graph_reasoning_query (SIMILAR/RANK)
Quantitative FormulasEvaluates graph-resident mathematical models with baseline vs intervention comparisons (SCENARIO) and bounded goal-seeking (SOLVE_TARGET) — deterministic formula execution, never arbitrary code execution.graph_reasoning_query (MODELS/CALCULATE/SCENARIO/SOLVE_TARGET)
Graph Analytics & Process MiningComputes PageRank, betweenness, Louvain communities, temporal forecasts, graph simulations, aggregations, and event-log process mining.graph_centrality, graph_forecast, graph_simulate, graph_aggregate, process_mining

3. Portable .kgraph containers: storage vs execution ​

Every Kompile knowledge graph can be stored and moved as a self-contained .kgraph ZIP container (UnifiedGraph):

text
project.kgraph
├── manifest.json                                # Format version, counts, ontology metadata & inventory
├── entities.jsonl / relations.jsonl             # Portable-v2 entities (incl. additionalTypes & fuzzyTypes) & edges (or Compact-v3 binary topology)
├── schemas/index.json                           # Portable-v2 container schema inventory
├── weights.json & opinions.jsonl                # Named rule weights & subjective-logic opinions
├── vectors/*.kvec                               # Dense / KGE vector layers
└── models/
    ├── ontology.ttl                             # Declared OWL/Turtle TBox (via bind_ontology)
    ├── schema/canonical-graph-schema.json       # Crawl-derived GraphSchema (bridged to OWL)
    ├── reasoning/
    │   ├── fol-psl-program.v1.json              # Portable PSL/HL-MRF program
    │   ├── graph-psl-weights.v1.json            # Learned graph-PSL rule weights
    │   └── mebn-theory.v1.json                  # Learned MEBN theory
    └── kge.json                                 # Trained TransE/RotatE KGE artifact

Storage is not execution (full contract):

  • Copying a .kgraph moves facts, provenance, opinions, and learned reasoning artifacts (export via PORTABLE_V2 when moving to another machine or Android; folder-local saves use COMPACT_V3).
  • Every loaded artifact is explicitly reported as ACTIVE, INSPECTION_ONLY, or INVALID (e.g., stale or missing a matching code-index generation receipt) — Kompile never silently substitutes cosine similarity for a missing KGE model or fabricates a missing MEBN theory.

4. Folder-local (offline) vs Kompile server ​

AspectFolder-Local (local-runtime, no server)Connected Kompile Server (:8080 / :8082 / :8094)
Storage.kompile/graph.kgraph in the project directoryIsolated GraphMatrixSubprocessMain (:8094) and/or Neo4j
Learning timingRuns during crawls (crawl_source) or explicit knowledge_graph action=learnRuns during crawl enrichment (LearningSubprocessMain) and server-managed maintenance
Query & verificationgraph_reason and ask_graph_verify are read-only lookups over the stored graph and last learning pass; graph_psl and ask_graph_mebn execute archived models locally in JavaFull live inference, remote causal:<event> attribution, multi-user fact sheets, WebSocket change tracking, and .kproject archive export
Predicate matchingLocal ask_graph_verify matches relation types case- and style-insensitively (worksFor = works_for = WORKS_FOR)Uses exact predicate names from list_predicates

Next steps ​

Released under the Apache-2.0 License.