How to build a knowledge graph from the SQL database you already have

You don't need a rip-and-replace graph database migration or a team of semantic theorists. You need a 3-step mapping layer that turns relational foreign keys into semantic edges. Here is how we did it in production.

9 October 2026 · 6 min read

When engineering teams realize vector search can't handle multi-hop enterprise logic, the standard response is expensive panic. Vendor playbooks say you must hire graph consultants, license a dedicated graph database, and migrate transactional tables into Neo4j or Amazon Neptune. Months pass, budget burns, and core operational data stays locked in PostgreSQL, MySQL, or SQL Server.

Here's the operational reality: the graph you need is already latent in your schema. Foreign keys, primary keys, and junction tables aren't database artifacts. They're semantic entities and directed edges designed years ago. You don't need a rip-and-replace overhaul. You need an automated mapping layer that projects your SQL schema into a semantic graph.

Diagram: the projection pipeline from SQL tables through foreign key scan, entity nodes, and semantic edges to an agent query that walks multi-hop paths with provenance attached
No migration: the vocabulary is read off the schema you already run, and agents query the projection.

The relational trap: why Text-to-SQL fails AI agents

Many enterprise architecture teams attempt to solve graph reasoning by feeding database schemas to LLMs and executing generated SQL via Text-to-SQL. In production, this approach collapses under real-world schema complexity.

Relational tables store raw facts efficiently, but obscure relationship semantics. When an AI agent answers a multi-hop query, such as 'Which accounts with open high-severity support tickets have key stakeholders who changed companies in the last 90 days?', Text-to-SQL requires five-table JOINs across ambiguous keys. The LLM loses context, hallucinates join conditions, or generates queries that trigger catastrophic table scans.

A graph representation exposes these connections natively. Instead of joining five tables at query time, the system traverses pre-indexed semantic edges without runtime JOIN planning.

The 3-step RDB-to-graph mapping protocol

Start from information_schema: list every table, then every foreign key constraint. That catalog query is the honest first move, and it tells you the size of the projection before you write a line of graph code. This approach has a standards lineage too: the W3C called the direct mapping R2RML, and the vendor tools of the last decade wrapped it. The difference now is why you are doing it: not reporting, but agents that need edges they can walk and cite.

Translating relational schemas into a semantic knowledge graph follows three deterministic rules. You can run this transformation dynamically or as a lightweight background sync.

In Relmint, the lab's signal-based sales intelligence platform, we used this protocol to map complex executive movement across corporate accounts without touching the core relational write-path.

Production implementation: Pydantic and Cypher projection

Below is a practical Python pattern showing how relational rows project into Cypher graph assertions using structured Pydantic models:

This mapping engine converts relational change data capture (CDC) events into graph updates without touching the transactional workload.

Querying the dual system: SQL for accounting, graph for AI

The goal isn't replacing SQL. SQL stays the system of record: exact aggregations, core reporting, and the compliance trail. The knowledge graph serves as an intelligence index sitting alongside your primary operational store.

In modern Postgres environments, extensions like Apache AGE let you query graph structures directly inside your database instance using openCypher syntax. Alternatively, streaming relational CDC events via Debezium into a lightweight graph index gives AI agents zero-latency multi-hop reasoning capabilities.

We deployed this dual-architecture in FundHouse to reconcile complex corporate hierarchies and in Alfred to give GTM agents instant access to account relationship histories.

Architectural summary and next steps

Before signing off on a costly graph database migration, audit your existing relational schemas. Most of the semantic graph structure required to power your enterprise AI strategy is already sitting in those schemas.

  1. W3C, "R2RML: RDB to RDF Mapping Language" — the standards lineage of the direct mapping this protocol follows
  2. Microsoft Research, "GraphRAG: From Local to Global" (arXiv:2404.16130, 2024) — the retrieval-side evidence that graph structure improves agent reasoning
  3. Apache AGE, graph extension for PostgreSQL (accessed October 2026) — query graph structures with openCypher inside the database you already run
  4. Palantir Foundry documentation, "Ontology" (accessed October 2026) — the commercial proof that the semantic layer is the product

Ready to transform your SQL database into an AI Knowledge Graph?

I work with GCC AI leaders, CXOs, and Enterprise Architects to design high-performance graph projection layers and ontology-grounded agent architectures. Let's evaluate your relational schema and build an actionable roadmap.

Schedule an AI Architecture Review on LinkedIn ↗
Essay 01 · Money, math, and machines that agreeThe dashboard that lied to me