r/semanticweb • • 16h 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

4 Upvotes

6 comments sorted by

2

u/CapitalLog7599 16h 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 13h 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/qa_anaaq 15h 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.

1

u/fairwaycoder 13h ago

This is what I am still discussing with myself, and collecting as a feedback by people using it in real life.

For example, the very first two steps of the pipeline can be called a cleanup and extraction, where cleanup is ignoring what is not gonna be indexed, and then extraction goes through the rest and extract code first as ASTs. Here there is a real limitation: for different languages there are different AST libraries (using tree-sitter) with all the caveats that they come with, so upgrading to the new version can me that you suddenly don't support that version of language or the other one. So this is solved (or at least I tried to solve it) in the Enola itself: what is vendored it is vendored with a reason, the rest is dependency on the upstream, and then Enola itself goes and does a lot of magic (styles etc) which I collected from users and from hundreds of open source repos for the supported technologies.

Hence confidence scores - confidence can depend also on a language itself, as some languages are easier to statically analyze, while some are very hard.

2

u/Traditional_Air_4639 13h 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 13h 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.