Knowledge Graph
Links between beliefs, graph statistics, connected components, and cross-domain bridges.
Beliefs are connected by links that form a knowledge graph. Links are created during dream synthesis, triplet analysis, and reinforcement. The graph provides structural metrics for understanding how knowledge is organized.
Belief Links
Create a Link
engine.add_link(belief_a, belief_b, link_type, inference, similarity?) → str
Creates a link between two beliefs. Returns the link UUID.
link_id = engine.add_link(
belief_a="id-1",
belief_b="id-2",
link_type="dream", # dream | triplet | reinforcement
inference="Both relate to compound defense mechanisms",
similarity=0.72,
)
Link Types
| Type | Description |
|---|---|
dream | Created during pair-wise dream synthesis |
triplet | Created during triplet dream synthesis (A+B+C) |
reinforcement | Existing link strengthened by repeated discovery |
Query Links
engine.get_belief_links(belief_id) → list[dict]
Returns all active links involving this belief, in both directions.
links = engine.get_belief_links("belief-id")
for link in links:
print(f"{link['link_type']}: {link['inference']}")
print(f" similarity: {link['similarity']}, reinforced: {link['reinforced_count']}")
Check Link Existence
engine.link_exists(id_a, id_b) → bool
Checks both orderings (A→B and B→A).
if engine.link_exists("id-1", "id-2"):
print("Already connected")
Reinforce a Link
engine.reinforce_link(id_a, id_b, similarity) → (str, bool) | None
Increments
reinforced_count. Returns (link_id, hit_cap) or None if not found.result = engine.reinforce_link("id-1", "id-2", similarity=0.75)
if result:
link_id, at_cap = result
if at_cap:
print("Link has reached reinforcement cap")
Link Count
engine.get_link_count() → int
Returns total active links in the graph.
Graph Statistics
engine.get_graph_stats() → dict
Returns structural metrics for the entire knowledge graph.
stats = engine.get_graph_stats()
# Returns:
# {
# "beliefs": 512, # total non-deprecated beliefs
# "edges": 650, # total active links
# "integration_pct": 74.4, # edges / beliefs * 100
# "components": 12, # connected components in graph
# "largest_component": 340, # beliefs in largest component
# "domain_diversity": 15, # distinct domains
# "topic_entropy": 1.29, # Shannon entropy of domain distribution
# }
Key Metrics
| Metric | Description |
|---|---|
integration_pct | How connected the graph is. Higher = more cross-linked beliefs. |
components | Number of disconnected subgraphs. Fewer = better integrated knowledge. |
largest_component | Size of the biggest connected subgraph. |
domain_diversity | Number of distinct knowledge domains represented. |
topic_entropy | Shannon entropy across domains. Higher = more balanced domain coverage. |
Connected Components
engine.get_connected_component(belief_id) → list[str]
Returns all belief IDs reachable from the given belief via BFS traversal.
component = engine.get_connected_component("belief-id")
print(f"This belief is in a cluster of {len(component)} beliefs")
Node Degree
engine.get_degree(belief_id) → int
Returns the number of active links for a belief.
degree = engine.get_degree("belief-id")
print(f"This belief has {degree} connections")
Cross-Domain Bridges
engine.get_bridges() → list[dict]
Returns edges that connect beliefs across different knowledge domains. These are the cross-domain insights discovered during dream synthesis.
bridges = engine.get_bridges()
for bridge in bridges:
print(f"{bridge['domain_a']} ↔ {bridge['domain_b']}")
print(f" {bridge['inference']}")
Bridge Dict
| Field | Type | Description |
|---|---|---|
belief_a | str | Belief ID on one side |
belief_b | str | Belief ID on the other side |
domain_a | str | Domain of belief A |
domain_b | str | Domain of belief B |
inference | str | The connection the dream engine discovered |
Core Similarity
engine.compute_core_similarity(belief_id) → float
Cosine similarity between this belief and the core question/topic. Useful for relevance ranking.
Rust Core Methods Rust
| Method | Returns | Notes |
|---|---|---|
add_link(a, b, type, inference, similarity?) | str | Link UUID |
get_belief_links(id) | list[dict] | Both directions, active only |
link_exists(a, b) | bool | Bidirectional check |
reinforce_link(a, b, similarity) | (str, bool) | None | (link_id, hit_cap) |
get_graph_stats() | dict | beliefs, edges, integration, components, entropy |
get_degree(id) | int | Active link count |
get_connected_component(id) | list[str] | BFS reachable IDs |
get_link_count() | int | Active links total |