Egonex Knowledge Graph Schema: 26 Edge Types and Node Structure in Understand Anything
The Understand Anything knowledge graph schema defines 26 canonical edge types and 13 node types in schema.ts, with edges strictly validated by a Zod enumeration to ensure graph integrity.
The Egonex-AI/Understand-Anything repository implements a strict knowledge graph schema for code understanding. While schema.ts defines both node and edge taxonomies—including 13 distinct node types for entities like files, functions, and services—the EdgeTypeSchema enumeration provides the authoritative list of 26 relationship types that govern how these entities connect within the graph.
The 26 Canonical Edge Types
The EdgeTypeSchema in understand-anything-plugin/packages/core/src/schema.ts (lines 4‑14) defines a fixed enumeration of 26 strings. These represent the only valid relationship types accepted by the graph validator:
imports– A file/module imports anotherexports– A file/module exports symbolscontains– One artifact contains another (e.g., a class contains a method)inherits– Classical inheritance relationshipimplements– Interface implementationcalls– A function/method calls anothersubscribes– Event‑based subscriptionpublishes– Event‑based publicationmiddleware– Middleware chaining relationshipreads_from– Reads data from a source (e.g., DB, file)writes_to– Writes data to a targettransforms– Data transformation pipeline stepvalidates– Validation of input/outputdepends_on– General dependencytested_by– Test case covering a unitconfigures– Configuration relationshiprelated– Loose semantic relationsimilar_to– Similarity relationdeploys– Deployment of a service/componentserves– Service serving an endpointmigrates– Migration operation (e.g., DB migration)documents– Documentation linkingprovisions– Resource provisioningroutes– Routing relationship (e.g., API route to handler)defines_schema– Schema definition relationshiptriggers– Event/cron trigger relationship
These types are central to the graph’s semantics and are enforced by Zod validation (z.enum([...])) in the schema. Any unknown value is treated as invalid and the edge is dropped during validation (see the validation logic in validateGraph).
Edge Type Categories
The 26 edge types span six semantic categories that cover code structure, runtime behavior, and infrastructure:
- Structural –
imports,exports,contains,inherits,implementsdescribe code‑level composition. - Behavioral –
calls,subscribes,publishes,middlewarecapture runtime interactions. - Data‑flow –
reads_from,writes_to,transforms,validatesmodel how data moves and is validated. - Dependency –
depends_on,tested_by,configuresexpress auxiliary relationships. - Semantic –
related,similar_toprovide higher‑level knowledge‑graph connections. - Infrastructure –
deploys,serves,migrates,documents,provisions,routes,defines_schema,triggersmap deployment‑time artifacts and operational concerns.
Validation and Aliases
The schema provides strict validation and alias normalization through EdgeTypeSchema and EDGE_TYPE_ALIASES.
Validating Edge Types
When constructing a graph edge programmatically, Zod enforces the enum:
import { EdgeTypeSchema } from "@understand-anything/core/schema";
import { z } from "zod";
// Build an edge object – Zod will enforce the enum
const edge = {
source: "node-123",
target: "node-456",
type: "calls" as const,
direction: "forward" as const,
weight: 0.9,
};
// Validate with Zod (throws if type is not one of the 26)
EdgeTypeSchema.parse(edge.type); // ✅ passes
Full Graph Validation
The validateGraph function drops invalid edges during processing:
import { validateGraph } from "@understand-anything/core/schema";
const result = validateGraph(myGraph);
if (result.success) {
console.log("Graph is valid, edges use only the 26 supported types");
} else {
console.warn("Invalid edges:", result.issues);
}
Alias Normalization
When language models output non‑canonical types like extends, the library maps them to canonical types:
import { EDGE_TYPE_ALIASES } from "@understand-anything/core/schema";
const raw = "extends";
const canonical = EDGE_TYPE_ALIASES[raw] ?? raw; // "inherits"
Key Files
The following files form the single source of truth for edge semantics:
understand-anything-plugin/packages/core/src/schema.ts– DefinesEdgeTypeSchema, the authoritative list of 26 edge types, plus alias tables and validation logic.understand-anything-plugin/packages/core/src/__tests__/schema.test.ts– Contains unit tests that explicitly enumerate the 26 edge types.understand-anything-plugin/packages/core/src/types.ts– Holds theEdgeTypeTypeScript type that mirrors the Zod enum.
Summary
- The Egonex Understand Anything knowledge graph uses exactly 26 edge types defined in
schema.ts. - The
EdgeTypeSchemaZod enum strictly validates all edges; invalid types are rejected duringvalidateGraphexecution. - Edges fall into six categories: Structural, Behavioral, Data‑flow, Dependency, Semantic, and Infrastructure.
- The
EDGE_TYPE_ALIASESmap normalizes variant terms (likeextends→inherits) to canonical values. - Source files in
packages/core/src/provide the complete type definitions and validation logic.
Frequently Asked Questions
What file contains the 26 edge type definitions?
The authoritative definitions reside in understand-anything-plugin/packages/core/src/schema.ts at lines 4‑14. This file exports EdgeTypeSchema, a Zod enumeration that strictly limits valid edge types to the 26 canonical strings.
How does the schema handle invalid edge types?
The validateGraph function parses edge types through EdgeTypeSchema. Any value not in the enumeration of 26 types is flagged as invalid and dropped during validation, preventing malformed relationships from entering the knowledge graph.
Can I use synonyms like "extends" instead of "inherits"?
Yes. The EDGE_TYPE_ALIASES map in schema.ts converts common synonyms to canonical types. For example, extends automatically maps to inherits before validation, ensuring consistency while accepting natural language variations from LLM outputs.
Are the 26 edge types extensible?
No. The schema uses a fixed Zod enum (z.enum([...])) that accepts only the 26 predefined strings. This strict typing ensures graph consistency across the Understand Anything ecosystem. To add new relationship types, the enumeration in schema.ts must be modified directly.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →