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

TypeDescription
dreamCreated during pair-wise dream synthesis
tripletCreated during triplet dream synthesis (A+B+C)
reinforcementExisting 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

MetricDescription
integration_pctHow connected the graph is. Higher = more cross-linked beliefs.
componentsNumber of disconnected subgraphs. Fewer = better integrated knowledge.
largest_componentSize of the biggest connected subgraph.
domain_diversityNumber of distinct knowledge domains represented.
topic_entropyShannon 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

FieldTypeDescription
belief_astrBelief ID on one side
belief_bstrBelief ID on the other side
domain_astrDomain of belief A
domain_bstrDomain of belief B
inferencestrThe 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

MethodReturnsNotes
add_link(a, b, type, inference, similarity?)strLink UUID
get_belief_links(id)list[dict]Both directions, active only
link_exists(a, b)boolBidirectional check
reinforce_link(a, b, similarity)(str, bool) | None(link_id, hit_cap)
get_graph_stats()dictbeliefs, edges, integration, components, entropy
get_degree(id)intActive link count
get_connected_component(id)list[str]BFS reachable IDs
get_link_count()intActive links total