Graph Reasoning and Analytics (recipes)
This page collects runnable patterns for graph-based analytics and reasoning. For the conceptual overview ("graph for computation, LLM for communication"), see Graph Reasoning (concepts).
Graph reasoning combines the structural power of the knowledge graph with the query interface and LLMs to derive insights from your data.
Graph-Based Analytics with Custom Code
Complex analytics — such as computing centrality, finding clusters, or detecting patterns — can be implemented as Custom Endpoints or Scheduled Tasks using the full query interface and standard C# libraries.
For example, an endpoint can compute how many incidents are connected to each device, group results by manufacturer, or find which entities appear across the most support cases. Because endpoints run within the workspace and have direct access to the graph, they can iterate over nodes and edges efficiently for analytical workloads.
Connectivity-based Sorting
The query interface includes SortByConnectivity(), which orders nodes by the number of edges they have. This is useful for surfacing the most-referenced or most-connected entities in a collection.
// Surface the most-referenced manufacturers
return Q().StartAt("Manufacturer").SortByConnectivity(mostConnectedFirst: true).Take(10).Emit("N");
AI-Driven Graph Reasoning
Graph queries combined with LLMs can answer complex questions:
- Retrieve: Run a graph query to produce a small, structured dataset (nodes, counts, neighbor sets).
- Ground: Pass the structured result to an LLM along with the original question.
- Synthesize: The LLM explains relationships, identifies patterns, or summarizes findings.
The key principle: use the graph for deterministic computation and the LLM for natural language synthesis.
Analytic Queries via the Shell
The admin Shell is useful for ad-hoc analytics during development:
// Count support cases per device
return Q().StartAt(N.Device.Type).AsEnumerable()
.ToDictionary(
n => n.GetString(N.Device.Name),
n => Q().StartAt(n.UID).Out(N.SupportCase.Type).Count()
);
Next Steps
- Learn about LLM Agents
- Explore Custom Endpoints