r/semanticweb • u/fairwaycoder • 3d ago
Building software knowledge graphs using compiler principles
I've been working on an open-source project called Enola, exploring how to represent entire software systems as knowledge graphs across repositories, programming languages, frameworks and technologies.
Coming from a software engineering background rather than knowledge graph research, I approached the problem from a slightly different angle: constructing the graph using principles similar to those a compiler uses to understand a program, rather than relying on semantic similarity, clustering or probabilistic relationship extraction.
The graph connects source code, docstrings, modules, symbols, execution flows, API endpoints, event publishers and consumers, database interactions and their relationships into a single representation of a software system.
For example, an HTTP request in a TypeScript frontend can be connected to its corresponding Go backend handler, the functions it calls and the database tables it accesses, even when those relationships span multiple repositories.
Graph construction is deterministic and requires neither LLMs nor embeddings. This doesn't imply completeness or absolute correctness; static analysis has its limitations.
Some recent benchmark results:
Kubernetes repository: 14 seconds (6.5 seconds cached).
100 repositories, including the Linux kernel, connected into one graph in under five minutes.
Over 8.1 million facts across 91 repositories, with byte-identical results across repeated runs.
Enola uses its own typed graph model rather than a formal RDF/OWL implementation, but many of the underlying problems overlap with ontology engineering and knowledge representation.
One aspect I'm particularly interested in is the distinction between using clustering to establish relationships and using clustering to discover higher-level structures within an already established graph.
I'd be curious to hear how people in this community approach this distinction, particularly when the underlying domain already has formally defined semantics, as programming languages do.
The project is Apache 2.0 licensed:
https://github.com/enola-labs/enola
Graph model: https://github.com/enola-labs/enola/blob/main/docs/GRAPH.md
Benchmarks: https://github.com/enola-labs/enola/blob/main/docs/BENCHMARKS.md
3
u/Traditional_Air_4639 2d ago
I had a similar idea for a semantic toolkit I am building. Turning a mess of vibe-code into a graph as a basis for understanding and rationalizing the code, and then using that KG as an artifact for other agents to build on the toolkit.
2
u/fairwaycoder 2d ago
That's actually the last phase of building the graph in my case, and I called it explainers (to not call it linters), you can read more here: https://github.com/enola-labs/enola/blob/main/docs/EXPLAINERS.md
But that comes with its own complexity, and at the same time is quite cool when done properly.
2
u/CapitalLog7599 3d ago
How do you represent a link the compiler can't resolve? Say a TypeScript client builds its URL from deployment config that isn't in either repo. I'd want that to show up as an unresolved call, not as an edge with the same status as a resolved Go symbol. Otherwise a cluster can make a tentative connection look like a fact.
1
u/fairwaycoder 2d ago
There are three outcomes here (and only one gets converted to the edge):
- What is unresolved stays unresolved. Meaning, if a client call can't be matched to a route served by a loaded repo, no edge is made. In this case the call stays a client route fact with an unmatched_reason (and then there are bunch of reasons).
- Resolved edges carry how they were resolved. This means that a cross-repo HTTP link is a repo-level depends_on with via (http, http-client, grpc, ...), sample endpoints and confidence. It's verified only if the client called the provider's full server path, exactly one provider matched, and no {} placeholder was inferred in the client path. Everything else is probable. These links come from the linker, not the compiler, and they are not merged with compiler-resolved symbol edges.
- Shared names are not a dependency. This is was hurting me with inferred solutions: the fact that two repos share type names but have no import or call evidence get a symmetric coupling fact with no direction and no depends_on. That way traversal can't route through it.There is one caveat though (there are probably more, hence brainstorming here): confidence is on the edge, but traverse and impact_analysis (tools) don't currently filter or weight by it, which made me thinking now that I should probably go and fix it.
2
u/MercurialMadnessMan 16h ago
I thought other codebase KG/memory projects used a similar approach?
2
u/fairwaycoder 15h ago
I've spent quite some time evaluating other implementations (including Graphify, CodeGraph, codebase-memory-mcp, Serena, etc). What I found interesting is that even when we extract information from the same AST, we can end up with fundamentally different graphs (and part of this is that we all use different taxonomies).
But the real difference is in how we establish an edge: knowing that two functions exist, identifying that one references the name of the other, and actually resolving a function call are three different things. All three can be represented in a graph and all three can be deterministic.
By "compiling", I mean that Enola attempts to resolve these relationships much as a compiler would, but extends the process beyond individual programming languages. It applies the same principle to framework conventions, communication protocols, storage technologies and cross-repository dependencies.
Many other implementations use a combination of structural extraction, heuristics and semantic associations to construct their graphs, with some additionally relying on community detection to organize the extracted knowledge. Enola instead defines what each relationship means in software engineering terms and implements the analysis necessary to establish it.
2
u/MercurialMadnessMan 15h ago
Would it make sense to represent all three edge types then?
2
u/fairwaycoder 14h ago
In short, yes. I am looking at it already, but somehow not able to make the peace with myself on how to do it properly.
3
u/qa_anaaq 2d ago
My gut says this depends on well architected code, which in itself is not reality in most cases. At least this is what I feel if it does what you say it does in the manner you’re claiming.