The Semantic Layer, From ScratchContents
A hands-on book

The Semantic Layer, From Scratch

Building a federated knowledge graph over Aurora and Redshift with Stardog, and putting an AI agent on top

Vinodh Thiagarajan

About this book. Fifteen short chapters that take a database engineer from "what is a triple?" to a working AI agent answering questions live across Aurora PostgreSQL and Amazon Redshift through Stardog. Each chapter is a self-contained page with hands-on steps in Stardog Studio. Inspired by the AWS Machine Learning blog post on building a semantic layer with Stardog and Amazon Bedrock AgentCore.

Question plain English Agent OpenAI / OpenRouter Stardog ontology, rules, virtual graphs Aurora customers Redshift purchases live SQL, joined on shared names, no ETL
The system you will build, one chapter at a time. The preface shows the full diagram.

Who this is for

You are an engineer who knows databases very well: SQL, joins, schemas, Postgres, Redshift, ETL. You have never worked with RDF, triples, SPARQL, OWL, ontologies, reasoning rules, SHACL, Stardog, Voicebox or MCP, and you would like to understand them properly rather than copy a demo. This book takes you from "what is a triple?" to a working AI agent that answers business questions live across two AWS databases, explaining every new idea in terms of the SQL you already know and saying plainly where the comparison breaks.

How to read it

Contents

Time to finish: about 13 hours in total: roughly 4.6 hours of reading and 8.1 hours hands-on in Studio and DBeaver. One or two chapters per sitting works well. The build chapters take longer because you create something real.

#ChapterTime
Preface: What we are building
The goal, the finished architecture, the build track, what's already done, and how to read the book.
~15 min
15 read
1One question, five systems
Why data fragments, what a semantic layer is (and isn't), the blog's three layers, and our Aurora/Redshift split.
~30 min
15 read · 15 hands-on
2The triple: the atom of knowledge
RDF's one shape, subject → predicate → object; a SQL row becomes triples; following arrows instead of joining.
~30 min
15 read · 15 hands-on
3Names, values and files
IRIs, literals and datatypes, prefixes, Turtle files, and named graphs as folders.
~45 min
15 read · 30 hands-on
4SPARQL for people who know SQL
Triple patterns, the shared variable as a join, FILTER, OPTIONAL, GROUP BY, and updates, side by side with SQL.
~45 min
15 read · 30 hands-on
5The T-Box, part 1: classes (RDFS)
Schema vs data, classes and subclasses, and the open-world assumption. You create the c360 classes.
~45 min
15 read · 30 hands-on
Build step 1
6The T-Box, part 2: properties and the c360 ontology (OWL)
Object vs datatype properties, domain and range, inverses, and loading the full kit ontology.
~60 min
18 read · 42 hands-on
Build step 2
7Where the data lives: materialized vs virtual
Copying triples in vs virtual graphs over SQL, data sources, and the trade-offs.
~30 min
15 read · 15 hands-on
8Mappings: teaching Stardog to read your tables
SMS2 mappings and IRI templates; you create the Aurora virtual graphs, safe and PII.
~45 min
15 read · 30 hands-on
Build step 3
9Federation: where the magic happens
The Redshift mapping, the IRI trick, what happens inside a federated query, and the top-spenders answer.
~60 min
18 read · 42 hands-on
Build step 4
10Reasoning: teaching the graph to conclude
Inference at query time, Stardog rules, and the kit's five rules, including "big spender".
~45 min
15 read · 30 hands-on
Build step 5
11SHACL: when you do want rules to reject data
Closed-world validation with shapes: the NOT NULL and CHECK constraints of the graph world.
~45 min
15 read · 30 hands-on
12Governance: same question, different answers
Users, roles and named-graph security; HR sees SSNs, Marketing doesn't.
~45 min
12 read · 33 hands-on
Build step 6
13The Stardog toolbox
Cloud portal vs endpoint, Studio, Designer, Explorer, Voicebox, the MCP server, and knowledge kits.
~30 min
15 read · 15 hands-on
14The agent: from question to answer
An OpenAI/OpenRouter model with a SPARQL tool, end to end, and how it maps to Bedrock AgentCore.
~60 min
20 read · 40 hands-on
Build step 7
15Build your own Voicebox
The Chapter 14 agent as a chat app: Stardog login, chat history, visible SPARQL, a model picker, and what each question costs.
~60 min
20 read · 40 hands-on
Build step 8
16At scale: huge ontologies and answers you can trust
Schema retrieval for ontologies too big for a prompt, and a source registry plus completeness checks so the agent says "partial" instead of a confident wrong total.
~75 min
28 read · 47 hands-on
Build step 9
Glossary
Every term in the book, A to Z, with the chapter that introduces it.
reference
Key ideas at a glance
The fifteen ideas worth remembering, each linked to where it is taught.
~5 min
5 read
Corrections log
What a reader flagged while working through the build steps, and what changed, chapter by chapter.
reference