AWS Builder Center

Beyond RAG: Building a Knowledge Graph Your AI Agents Can Actually Use

Learn how to build a knowledge graph that lets AI agents traverse relationships across your data, resolve governed metrics, and enforce business rules - using the open-source AWS Context Ontology Accelerator and MCP.

The Problem

Here's a question RAG can't handle:
"Our Portland DC just reported delays from FreshProduce Co. Who are the approved alternatives in the same region, same product category, risk rating below 3, with no blocking business rules?"
The answer lives across four tables in three systems. You need to join suppliers to delivery routes to distribution centers, filter by category and region, check risk thresholds, and cross-reference business rules. That's a graph traversal problem, not a document retrieval problem.
Same gap everywhere:
  • Healthcare: "Which in-network providers accept this insurance AND have openings this week for this procedure?"
  • FinServ: "What's our exposure to counterparties in this sector, and what constraints apply to reducing it?"
  • IT Ops: "Service X is down. What depends on it, who owns those, and where's the runbook?"
The pattern: answers that require hopping across relationships, checking rules at each step, and returning something auditable.



What an Ontology Gives You

A database schema = the shape of data (tables, columns, types). An ontology = the meaning: "Supplier delivers_to DC. DC serves Region. Organic substitutions require QA approval."
With an ontology-backed knowledge graph, your agent navigates real relationships instead of guessing at SQL joins. Every answer traces back through the graph, fully explainable.



AWS Context Ontology Accelerator

Open source (Apache 2.0), released July 31, 2026. You deploy it into your own AWS account. Three phases:
Scan: Connect databases (Postgres, Redshift, MySQL) or S3 docs. Bedrock enriches metadata automatically.
Model: Claude proposes an ontology from your tables (classes, relationships, constraints). You review and approve in a web UI. Nothing ships without human sign-off. Stored as W3C OWL in Neptune.
Serve: MCP server on AgentCore Runtime exposes 6 tools to any compatible agent:
Tool
Purpose
query
NL in, resolved answer out (3-tier)
graph_traversal
Walk relationships hop by hop
list_metrics
Pre-defined SQL for key questions
describe_schema
Ontology classes and properties
translate_sparql
NL to SPARQL (debugging)
rag_retrieval
Vector search over docs



3-Tier Query Resolution

Tier 1 (~20ms): Question matches a governed metric. Runs exact SQL. Deterministic.
Tier 2 (~50-800ms): Ontology translates NL to SPARQL to SQL. Correct multi-join queries without LLM guessing.
Tier 3: Graph traversal + document search + LLM synthesis. For relationship exploration.
Tier 1 and 2 produce auditable answers from real data. SQL is generated from formal mappings, validated by a SQL Firewall, and logged.



Before and After

Three tables:  suppliers ,  distribution_centers ,  supplier_dc_routes .
Question: "Portland DC delays from FreshProduce Co. Who are the alternatives?"
Without ontology (plain LLM with tool-use):
Agent guesses at the schema and generates:
SELECT * FROM suppliers WHERE region = 'Pacific Northwest'

Returns all PNW suppliers, including FreshProduce Co. itself. Doesn't join routes (so you don't know who actually delivers to Portland). Doesn't check risk. Doesn't know business rules exist.
With ontology (Tier 2 + graph traversal):
System uses the ontology to generate:
SELECT s.name, s.risk_rating, r.lead_time_days
FROM suppliers s
JOIN supplier_dc_routes r ON s.supplier_id = r.supplier_id
JOIN distribution_centers dc ON r.dc_id = dc.dc_id
WHERE dc.name = 'Portland Distribution Center'
AND s.category = 'Fresh Produce'
AND s.region = 'Pacific Northwest'
AND s.risk_rating < 3.0
AND s.supplier_id != 'SUP001'

Then graph traversal checks business rules at each candidate node.
Result: "GreenValley Foods (risk 1.8, 2-day lead time, preferred per rule BR004). Pacific Harvest (risk 2.1, 3-day). No blocking rules for Fresh Produce substitution."
The difference: correct joins, correct filters, business rule awareness, and a fully auditable SQL trail. Not a hallucination.



Try It With Sample Data (If You Don't Have a Test Database)

In production, you just point the Accelerator at your existing database. But if you want to test with a clean dataset first, spin up any Postgres instance and load this:
CREATE TABLE suppliers (supplier_id VARCHAR(10) PRIMARY KEY, name VARCHAR(100), category VARCHAR(50), region VARCHAR(50), risk_rating DECIMAL(2,1), contract_status VARCHAR(20));
CREATE TABLE distribution_centers (dc_id VARCHAR(10) PRIMARY KEY, name VARCHAR(100), region VARCHAR(50), capacity_pallets INTEGER);
CREATE TABLE supplier_dc_routes (supplier_id VARCHAR(10), dc_id VARCHAR(10), lead_time_days INTEGER, delay_count_30d INTEGER, PRIMARY KEY(supplier_id, dc_id));

INSERT INTO suppliers VALUES ('SUP001','FreshProduce Co.','Fresh Produce','Pacific Northwest',4.2,'Active'),('SUP002','GreenValley Foods','Fresh Produce','Pacific Northwest',1.8,'Active'),('SUP003','Pacific Harvest','Fresh Produce','Pacific Northwest',2.1,'Active'),('SUP004','NorthWest Naturals','Organic Dairy','Pacific Northwest',1.5,'Active');
INSERT INTO distribution_centers VALUES ('DC001','Portland Distribution Center','Pacific Northwest',45000),('DC002','Seattle Distribution Center','Pacific Northwest',62000);
INSERT INTO supplier_dc_routes VALUES ('SUP001','DC001',2,3),('SUP001','DC002',3,2),('SUP002','DC001',2,0),('SUP002','DC002',2,0),('SUP003','DC001',3,0),('SUP004','DC001',1,0);

Then in the web UI: add this database as a source > click Scan > run Induce > review and approve the proposed ontology. The MCP server and all 6 tools are already running (deployed with the platform). Open the Playground and ask: "Which suppliers deliver to Portland DC with zero delays?"



Works Across Industries

Supply chain uses Supplier > Route > DC. Swap for:
Healthcare: Provider > practices_at > Facility > accepts > InsurancePlan. Rule: "Referrals require PCP auth."
FinServ: Account > holds_position_in > Fund > exposed_to > Counterparty. Rule: "Rebalancing above $10M needs compliance review."
IT Ops: Service > depends_on > Service > owned_by > Team > documented_in > Runbook. Rule: "Tier 1 needs incident commander in 15 min."
Same 6 tools, same 3-tier resolution. Different ontology.



Deploy + Connect

The platform deploys once. After that, connecting data and querying is all done through the web UI. No code needed to create the MCP tools or build the graph. Those happen automatically.
One-time setup:
git clone --branch <tag> https://github.com/aws/context-ontology-accelerator.git
cd context-ontology-accelerator
curl https://mise.run | sh && mise install
make setup
npx cdk bootstrap aws://ACCOUNT_ID/us-east-1
make deploy-dev

16 CDK stacks, ~1.5hr provisioning. Neptune, OpenSearch Serverless, ECS, Lambda, Cognito, Bedrock, Athena. Tested in us-east-1. ~$15-30/session.
After deploy, the workflow is:
  1. Open the web UI (CloudFront URL in stack outputs)
  1. Add your database as a source (connection string, credentials)
  1. Click Scan (Bedrock discovers and enriches your schema)
  1. Click Induce (Claude proposes an ontology from your tables)
  1. Review and approve (human sign-off required)
  1. Done. MCP server is live, graph is built, agents can connect.
Connecting your agent (the only code you write):
from strands import Agent
from strands.models import BedrockModel
from strands.tools.mcp import MCPClient

mcp = MCPClient(
transport="streamable-http",
url="https://your-mcp-endpoint.agentcore.us-east-1.amazonaws.com",
headers={"Authorization": f"Bearer {USER_TOKEN}"}
)

agent = Agent(
model=BedrockModel(model_id="us.anthropic.claude-sonnet-4-20250514-v1:0"),
tools=mcp.list_tools(),
system_prompt="You are a supply chain intelligence agent..."
)

response = agent("Who can replace FreshProduce Co. for Portland DC?")




Governance

  • Cedar auth - Namespace/table/column access control
  • SQL Firewall - SELECTs only, per-user allowlists
  • Delegated auth - Agents act on behalf of users via OIDC, no machine credentials
  • Audit - Every decision logged to CloudWatch



Path to AWS Context (Managed)

AWS Context announced June 2026, currently "Coming Soon." The Ontology Accelerator is the on-ramp:
  • Ontologies import directly into the managed service when it ships
  • Same MCP tools, no agent code changes
  • Gain: zero infra, automatic learning loop, Iceberg export, Lake Formation
Build now. Migrate later.



RAG vs. Ontology Accelerator

RAG: Answer is in a document. "What does policy X say?"
Ontology Accelerator: Answer spans tables, needs relationship traversal, or requires governed metrics.
Both: Agent needs relationships + document content.



Resources

Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article