Distance Matrices
N×N upper-triangle semantic distance between any node set
Semantic Neighborhoods
BFS ego-graphs with confidence decay and distance band classification
Proximity Blending
Combine semantic similarity with graph proximity in retrieval
10× Cache
Graph revision–based embedding cache avoids redundant re-computation
Distance Bands
Every neighbor result is classified into one of four distance bands based on hop count and semantic similarity:
Distance bands flow through the entire system: retrieval results, path responses, API endpoints, and the Explorer Ego Mode visualization all use the same four-tier classification.
Quick Start
1
Get neighbors with distance metadata
The simplest entry point: call
get_neighbors() with include_distance_metadata=True:2
Compute a semantic distance matrix
3
Blend proximity into retrieval
Set
proximity_weight on AgentContext to blend graph proximity into every semantic retrieval call:ContextGraph Distance API
get_neighbors()
Returns BFS neighbors enriched with distance metadata when include_distance_metadata=True:
get_neighbor_distances()
Returns a sorted list of neighbors ranked by combined confidence-decay distance score:
SimilarityCalculator — Pairwise Similarity
SimilarityCalculator computes similarity between node embeddings using four metrics.
Constructor
Methods
Pairwise Similarity Matrix
pairwise_similarity() returns the upper triangle of the N×N matrix — each key is a (node_id_a, node_id_b) tuple:
The matrix is upper-triangle only —
(a, b) is stored but (b, a) is not. To look up either direction: matrix.get((a, b)) or matrix.get((b, a)).Batch Similarity
Efficiently compare a query vector against all nodes using chunked vectorized ops:Find Most Similar
Individual Metrics
Proximity-Blended Retrieval
AgentContext.retrieve() and find_precedents() both support a proximity_weight parameter that blends graph proximity into the semantic similarity score:
proximity_score is derived from hop count and edge weights from the query anchor node.
Embedding Cache
The embedding cache avoids re-computing embeddings for nodes that haven’t changed since the last call — delivering up to 10× throughput improvement on large graphs.How It Works
EachGraphSession tracks a graph revision hash derived from the current node and edge state. When a distance matrix or neighborhood request arrives:
- The revision hash is compared to the cached hash
- If unchanged: the cached embeddings are returned directly
- If changed (nodes/edges added or modified): the cache is invalidated and embeddings are recomputed
REST API Endpoints
Five new endpoints were added in v0.5.0 for programmatic distance intelligence access:POST /api/graph/distance-matrix
Compute N×N semantic distance matrix for a set of node IDs:
GET /api/graph/node/{id}/semantic-neighborhood
Retrieve the ego-graph (BFS neighborhood) of a node with distance metadata:
GET /api/decisions/causal-distance
Return causal distance (hop count through causal edges) between two decision nodes:
GET /api/temporal/distance-history
Track how the semantic distance between two nodes has evolved over time:
POST /api/export/distance-enriched
Export graph data enriched with distance metadata (CSV or JSONL, capped at 200 nodes):
Explorer Distance Intelligence UI
The Knowledge Explorer embeds Distance Intelligence directly in the browser dashboard:Ego Mode
Ego Mode
Ego Mode centers the visualization on a selected node and renders its semantic neighborhood with BFS depth-of-field fading — nodes further from the anchor become progressively dimmer, revealing the “shape” of conceptual proximity.
- Depth slider (1–8): controls the BFS radius of the neighborhood
- Confidence decay visualization: edge opacity maps to
confidence_decayscore - Distance band color coding: green (direct) → teal (near) → yellow (mid-range) → red (distant)
- Bottleneck highlighting: bridge nodes that connect otherwise separate clusters are highlighted in the path inspector
Distance Heatmap
Distance Heatmap
The heatmap renders an N×N distance matrix as a color-coded grid — instantly revealing which clusters of nodes are semantically cohesive and which are isolated.
- Color scale: green (near, distance → 0) through yellow to red (distant, distance → 1)
- Hover: shows exact distance value and distance band for each cell
- Sort options: sort rows/columns by node type, community membership, or alphabetical
Semantic Overlay
Semantic Overlay
Overlay semantic similarity on the standard force-directed graph layout without switching modes:
- Semantic overlay: edge thickness scaled by semantic similarity score
- Structural overlay: edge thickness scaled by graph centrality
- Both overlays can be toggled independently
Path Inspector
Path Inspector
Click any two nodes to inspect the shortest path between them. The Path Inspector shows:
- Distance band chip: classifies the overall path as direct / near / mid-range / distant
- Metric cards: hop count, mean edge weight, path confidence decay
- Bottleneck node highlight: the single node whose removal would disconnect the path
- Distance history: timeline of how the distance between the two nodes has changed across graph snapshots
Real-World Patterns
- Knowledge Cluster Discovery
- Anomaly Detection
- Decision Consistency Audit
Find semantically cohesive topic clusters in a large knowledge graph without running community detection:
Performance
The 10× cache improvement applies when the graph is unchanged between requests. In write-heavy pipelines where nodes are added continuously, cache hit rates will be lower. Use
force_refresh=False (default) for read-heavy Explorer usage and force_refresh=True for batch pipeline contexts.-
Context Module —
ContextGraph.get_neighbors()and proximity-blended retrieval. -
Knowledge Graph Module —
NodeEmbedder,SimilarityCalculator, and graph analytics. - Visualization — Programmatic distance heatmaps and ego-mode graph renders.
- Explorer — Knowledge Explorer with built-in Distance Intelligence dashboard.
- Distance Intelligence — Semantic neighborhoods and distance matrices · Advanced
