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:
- 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
.kgraphbundle withgraph_import, or - Project your codebase structure via
kompile code-index.
- Crawl a file, folder, URL, or text snippet with
- Discover the vocabulary:
- Call
knowledge_graph action=list_predicatesorgraph_reasoning_query operation=SCHEMAto see exact relation names and entity types with counts.
- Call
- Verify a claim before stating it:
- Call
ask_graph_verify atom="worksFor(Alice, Acme)"→ returnsSUPPORTED,REFUTED, orUNKNOWN, a confidence score in[0, 1], and the supporting/counter evidence. - Supports point-in-time verification via
asOf(server) orvalidAt(local valid-time filter).
- Call
- Query patterns, paths & explanations:
- Pattern query:
ask_graph_query conjuncts=[{"predicate":"worksFor","args":["?x","Acme"]}](prefix variables with?). - One-call entity/fact explanation:
graph_reason target="worksFor(Alice, Acme)"(verifies a fact) orgraph_reason target="Alice"(describes an entity with evidence, learned scores, and trace). - Deep derivation tree:
ask_graph_explain atom="worksFor(Alice, Acme)"shows which rules fired and which observed facts produced the verdict.
- Pattern query:
- Run unified structural, counterfactual, or formula queries:
- Call
graph_reasoning_querywith one of its 21 typed operations (discoverable viaoperation=CAPABILITIES):
- Call
| Category | graph_reasoning_query Operations |
|---|---|
| Discovery & Search | CAPABILITIES, OVERVIEW, SCHEMA, SEARCH, RELATIONS, DESCRIBE, NEIGHBORS, FACTS, SIMILAR, RANK |
| Traversal & Time | PATH (shortest path between two entities), TIMELINE (time-ordered events) |
| Verification & Trace | VERIFY, WHY (why a relation holds), WHY_NOT (why it fails and what would change it) |
| Quantitative Models | MODELS (discover executable formulas), CALCULATE, SCENARIO (apply counterfactual interventions), SOLVE_TARGET (goal-seek an input to hit a target measure) |
| Graph Bundle Assets | ASSETS (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 / Layer | What It Does | Primary Tool(s) |
|---|---|---|
| Ontologies & Fuzzy Types | Imports/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 Opinions | Stores 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 Formulas | Evaluates 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 Mining | Computes 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):
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 artifactStorage is not execution (full contract):
- Copying a
.kgraphmoves facts, provenance, opinions, and learned reasoning artifacts (export viaPORTABLE_V2when moving to another machine or Android; folder-local saves useCOMPACT_V3). - Every loaded artifact is explicitly reported as
ACTIVE,INSPECTION_ONLY, orINVALID(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
| Aspect | Folder-Local (local-runtime, no server) | Connected Kompile Server (:8080 / :8082 / :8094) |
|---|---|---|
| Storage | .kompile/graph.kgraph in the project directory | Isolated GraphMatrixSubprocessMain (:8094) and/or Neo4j |
| Learning timing | Runs during crawls (crawl_source) or explicit knowledge_graph action=learn | Runs during crawl enrichment (LearningSubprocessMain) and server-managed maintenance |
| Query & verification | graph_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 Java | Full live inference, remote causal:<event> attribution, multi-user fact sheets, WebSocket change tracking, and .kproject archive export |
| Predicate matching | Local ask_graph_verify matches relation types case- and style-insensitively (worksFor = works_for = WORKS_FOR) | Uses exact predicate names from list_predicates |
Next steps
- Ontologies, Type Schemas & Fuzzy Types —
GraphSchema,SchemaHierarchyVocabulary, OWL-RL (ontology.ttl),GraphSchemaOntologyBridge,FuzzyTypeMembership, and conformance/reasoning parity - Reasoning Traces & Explainability — unified
ReasoningTracestep trees, PSL KKT rule forces, QBAF rebuttals, gap analysis (ReasoningTraceGapAnalyzer),.kgraphtrace artifacts, and W3C PROV export - Knowledge Graphs: Schema, Extraction & Neo4j — node/edge schema, LLM extraction config, entity resolution, and named graph hierarchies
- Fact Sheets — scoping crawls, graphs, and RAG queries by domain
- Portable Knowledge Bases — packaging full
.kprojectsnapshots with SHA-256 verification - KGraph Portability Contract — exact v2/v3 container entries and activation rules
- Graph CLI Commands —
kompile graph ...terminal commands