Semantic Layer for Agentic AI Using EDB Postgres AI and Bedrock AgentCore
· Engineer's Notes · Cem Koyluoglu
Overview of building a Postgres‑based semantic layer for agentic AI, exposing it via Bedrock AgentCore with built‑in governance, access control, and observability.
What happened
The blog post demonstrates how to construct a semantic layer for agentic AI by leveraging EDB Postgres AI as an AIDB extension inside an operational PostgreSQL database. A Strands Agents agent runs on Amazon Bedrock AgentCore and queries the semantic layer to answer Customer 360 (C360) questions. Business meaning is stored in standard PostgreSQL COMMENT statements, join relationships are derived from foreign keys, and governance relies on PostgreSQL GRANT, column‑level grants, and row‑level security enforced through the Model Context Protocol (MCP) endpoint that ships with AIDB. The reference architecture authenticates analysts via Amazon Cognito, routes requests through AgentCore Gateway (which validates JWTs and applies Cedar policies), and forwards tool calls to an Application Load Balancer (ALB) that fronts the MCP server inside the EDB VPC. AgentCore emits traces to Amazon CloudWatch, while AIDB captures OpenTelemetry traces for each SQL execution as rows in the aidb_otel schema. The post details the creation of a semantic knowledge base (SemKB) using aidb.create_semantic_kb, the definition of semantic aliases with aidb.create_semantic_alias, and the use of PostgreSQL roles and row‑level security to produce different query results for different callers.
Why it matters in production
Embedding the semantic layer directly in the operational database eliminates the need for a separate catalog or synchronization process, reducing latency and operational complexity. Because access control is enforced by native PostgreSQL primitives, security policies are consistent with existing data‑governance frameworks and avoid reliance on advisory prompts. The architecture avoids AWS Lambda, lowering compute cost and simplifying the deployment surface. Observability is achieved through two complementary mechanisms: AgentCore traces in CloudWatch provide end‑to‑end visibility of LLM calls and tool invocations, while AIDB’s OpenTelemetry rows enable fine‑grained performance analysis of individual SQL statements without additional instrumentation. The use of a local llama.cpp embedding model (bge-small-en-v1.5-f16) keeps inference costs low, and the ability to swap to a remote model such as Amazon Titan Text Embeddings offers flexibility for scaling or improving embedding quality. Governance through PostgreSQL roles and row‑level security ensures that sensitive columns (e.g., Social Security numbers) are exposed only to authorized callers, mitigating data leakage risk in multi‑tenant environments.
Engineering takeaways
- Define business semantics with
COMMENT ONstatements and view comments; this improves text‑to‑SQL accuracy for agents and reduces downstream maintenance. - Deploy the MCP endpoint behind an ALB with Basic authentication and let AgentCore Identity inject the appropriate PostgreSQL role credentials, ensuring seamless credential management.
- Use
aidb.create_semantic_kbwithauto_processing='Live'to keep the semantic index synchronized with schema changes via PostgreSQL event triggers. - Capture OpenTelemetry traces in the
aidb_otelschema to enable SQL‑level performance monitoring without external tracing agents. - Enforce data access through PostgreSQL GRANT, column‑level privileges, and row‑level security; rely on these primitives rather than LLM prompts for governance.
Related work on this site
- Agentic & LLM Automation — Multi-step LLM pipelines that run unattended: model cascades with fallbacks, validation gates, scheduled automation and alerting when something breaks.
- RAG & Grounded LLM Systems — LLM features that answer from the right source instead of from memory: document-grounded assistants, transcript-grounded chat and quality gates around generated output.
- YouTube AI Summarizer — Open-source Chrome extension on the Chrome Web Store: AI summaries, key points, deep analysis, a two-host AI podcast (Gemini TTS) and transcript-grounded chat for any YouTube video, using Groq or Ollama Cloud with the user’s own key.
- Automated AI News Pipeline (this site) — The pipeline behind this site’s Tech News: scheduled GitHub Actions scrape sources, an LLM cascade on Groq rewrites and enhances articles, and layered quality gates (date integrity, language checks, instruction-leak detection, duplicate detection) decide what gets published, with Telegram alerts.
This note was drafted with AI assistance from the primary source credited on this page, and automatically checked against that source before publishing.