A customer support chatbot that queries historical tickets and knowledge base articles stored in Amazon Aurora PostgreSQL-Compatible Edition can deliver fast, context-aware answers. However, it also introduces challenges around privacy, accuracy, safety, and governance, especially when the underlying data contains sensitive customer information. In this post, we map the eight AWS Responsible AI (RAI) dimensions to Aurora PostgreSQL capabilities. We then walk through a design pattern for the Explainability dimension, using a Retrieval Augmented Generation (RAG) based customer support chatbot as the reference use case. This post implements one dimension, Explainability, in depth. Treat it as Part 1 of a series rather than a full build-out of all eight.
Amazon Aurora PostgreSQL-Compatible Edition makes it more straightforward to operationalize responsible AI through its native Aurora Machine Learning (Aurora ML) capabilities. With Aurora ML, you can invoke Amazon SageMaker endpoints and Amazon Bedrock foundation models directly from SQL, without data movement, custom extract, transform, and load (ETL) pipelines, or complex integrations. This post uses Aurora ML to generate vector embeddings from SQL, keeping the embedding pipeline inside the database layer.
AWS defines eight core Responsible AI dimensions, published through the AWS Well-Architected Responsible AI Lens, Amazon Bedrock Guardrails, and the Responsible Use of AI Guide. These dimensions (Fairness, Explainability, Privacy and Security, Safety, Controllability, Veracity and Robustness, Governance, and Transparency) provide a structured framework for evaluating and implementing trustworthy AI systems.
Use case overview
Customer support systems often struggle to provide accurate, context-aware responses while maintaining privacy and compliance. Consider a customer support chatbot built on Amazon Aurora PostgreSQL that uses RAG with pgvector embeddings, Amazon Bedrock model inference, and AWS Responsible AI guardrails to deliver grounded, explainable responses.
A customer can ask questions such as “Why was my last bill high?” or “Where is my last order?” and receive accurate answers with citations, while sensitive data remains obscured through personally identifiable information (PII) redaction and access controls.
Mapping the AWS Responsible AI dimensions to Aurora PostgreSQL
The following table maps the eight AWS Responsible AI dimensions to practical implementation strategies for a customer support chatbot built on Amazon Aurora PostgreSQL-Compatible Edition. It highlights how database features, AWS AI services, and governance controls work together to deliver a trustworthy, secure, and explainable RAG-based chatbot.
| RAI Dimension | What It Means | Implementation Approaches | Key PostgreSQL / Aurora Features | Primary AWS Services / Tools |
| 1. Fairness | Chatbot should provide equal quality responses regardless of language, region, or customer profile | Bias testing using diverse support queries. Decouple demographics from embeddings. Metadata filtering and multilingual testing. | pgvector, JSONB metadata, SQL filtering, views | Amazon Bedrock Model Evaluation, Amazon SageMaker Clarify |
| 2. Explainability | Users and support teams should know why the chatbot gave a specific answer | Log retrieved chunks, similarity scores, and citations. RAG tracing with source attribution. Full interaction logging. | chat_interactions table, array columns, JSONB logs, pgvector similarity | Amazon Bedrock Knowledge Bases, Amazon Bedrock InvokeModel |
| 3. Privacy and Security | Protect customer PII such as name, phone, and order details in tickets | PII redaction before embedding. Row-Level Security (RLS), encryption, IAM auth, RBAC, and anonymization. | Row-Level Security, pgcrypto, roles, policies | Amazon Bedrock Guardrails, AWS KMS, Amazon Comprehend, AWS IAM |
| 4. Safety | Help prevent harmful, toxic, or inappropriate responses | Content filters, denied topics, prompt injection protection, rate limiting, and moderation. | SQL functions, interaction logs | Amazon Bedrock Guardrails |
| 5. Controllability | Ability to steer chatbot behavior and escalate to humans | Human-in-the-loop escalation, feedback table, feature flags, prompt control, and kill switch. | chat_feedback table, escalation tables, triggers | Amazon Bedrock Guardrails, Amazon CloudWatch, AWS CloudTrail |
| 6. Veracity and Robustness | Verify accurate responses grounded in support data and avoid hallucinations | RAG grounding with similarity threshold. Versioned documents and validation checks. | pgvector typed columns, CHECK constraints, triggers | Amazon Bedrock Guardrails, Amazon Bedrock Model Evaluation |
| 7. Governance | Maintain audit trail and accountability for chatbot decisions | Audit logging with retention policy. Model version tracking and Amazon S3 archival. | pgaudit, pg_cron, JSONB model metadata | AWS Audit Manager, AWS CloudTrail |
| 8. Transparency | Clearly inform users they are interacting with AI and show data sources | Powered-by-AI notice, citations, privacy notice, and source explanation. | SQL views, interaction logs | Amazon Bedrock Knowledge Bases, AWS AI Service Cards |
Note: These are example approaches and may vary by use case.
Solution overview
This reference architecture shows how Responsible AI controls map to each component of a RAG-based chatbot on Amazon Aurora PostgreSQL-Compatible Edition.
An ingestion pipeline redacts PII from support tickets, FAQs, and product documents, then converts them into vector embeddings. When a user submits a query, AWS Lambda runs a semantic search over Aurora PostgreSQL, applies Amazon Bedrock Guardrails for privacy and grounding, sends the guarded context to an Amazon Bedrock foundation model (FM), and logs every interaction for explainability and governance.
Lambda grounds responses in enterprise data, redacts PII and applies Row-Level Security (RLS) for privacy, records citations and interaction logs for explainability, and writes audit records for governance.
When to build this versus use a managed service: Amazon Bedrock Knowledge Bases provides built-in RAG with citations and is the simpler choice when default retrieval and citation behavior meets your needs. Build the custom logging design in this post when you need provenance stored in your own schema. That provenance includes retrieved versus cited sources, similarity scores, and guardrail traces that you can query with SQL and retain under your own policies.
The following diagram illustrates the end-to-end architecture of this solution, showing the data ingestion flow (left), the query and response flow (center), and the responsible AI controls applied at each stage (center and right).
Figure 1: Architecture of RAG-based customer support chatbot with Responsible AI controls on Amazon Aurora PostgreSQL
Data ingestion
An ingestion pipeline loads historical support tickets, FAQs, and product documentation into Amazon Aurora PostgreSQL after redacting PII, using the pgvector and aws_ml extensions for vector operations and Aurora ML integration.
The Aurora ML aws_bedrock.invoke_model_get_embeddings function transforms the text into Amazon Titan Text Embeddings V2 vectors (1,024 dimensions), and pgvector stores them.
Aurora PostgreSQL functions as both a relational store for structured customer data and a vector database for semantic search.
Query and response flow
When a user asks a question, the chatbot follows these steps (see Figure 1):
- The user sends a natural language question to Amazon API Gateway over HTTPS.
- API Gateway invokes AWS Lambda.
- Turn the question into a vector. Lambda calls the Aurora ML
aws_bedrock.invoke_model_get_embeddingsfunction with Amazon Titan Text Embeddings V2. This must be the same model used to embed the knowledge base, so the question and documents both produce comparable 1,024-dimension vectors. - Run a similarity search. Aurora PostgreSQL uses the
pgvectorcosine distance operator to compare the question vector with the stored knowledge vectors, and returns the most relevant chunks with their similarity scores. Row-Level Security limits results to the current tenant. - Build the augmented prompt. Lambda combines the user’s question with the retrieved chunks, labeling each one
[Source N]. This gives the model knowledge from your database that it would not otherwise have. - Generate a grounded answer. Lambda sends the prompt to Amazon Bedrock. Guardrails check the input (content filters, denied topics, PII), the foundation model writes an answer based on the retrieved chunks, and a contextual grounding check confirms the answer is supported by those sources.
- Log the interaction for explainability. Lambda writes the complete interaction to the
chat_interactionstable: the question, retrieved chunk IDs, similarity scores, the sources actually cited, the guardrail trace, and the model ID. - Lambda returns the answer, with its source citations, to the user.
Supporting operations run separately from each request:
- Ingestion: document embeddings are created once, when content is loaded (see Data ingestion).
- Retention:
pg_cronarchives older interaction records to Amazon Simple Storage Service (Amazon S3). - Monitoring: Lambda sends logs and metrics to Amazon CloudWatch, and AWS CloudTrail records API activity for audit.
Prerequisites
Before you begin, make sure you have the following in place:
- An Amazon Aurora PostgreSQL cluster with the
pgvectorextension enabled. HNSW indexes and iterative index scans require newerpgvectorversions, and Aurora ML and Amazon Bedrock model support are versioned separately. See the Aurora ML, pgvector, and Bedrock documentation for the current minimum versions rather than pinning to a specific one. - The
aws_mlextension enabled on the cluster (CREATE EXTENSION IF NOT EXISTS aws_ml CASCADE), with an AWS Identity and Access Management (IAM) role attached to the cluster grantingbedrock:InvokeModel. Aurora ML calls Bedrock in the cluster’s own Region. - The
aws_s3extension enabled on the cluster (CREATE EXTENSION IF NOT EXISTS aws_s3 CASCADE), with an IAM role attached for thes3Exportfeature so the retention job can export to Amazon S3. - Amazon Bedrock access with Amazon Titan Text Embeddings V2 (
amazon.titan-embed-text-v2:0) for embeddings and a foundation model that supports the Bedrock Converse API for answer generation. Model availability and recommended versions change over time, so choose a current model from Supported foundation models in Amazon Bedrock. Newer models are invoked through cross-Region inference profile IDs. - Amazon Bedrock Guardrails configured for PII protection, content filtering, and contextual grounding (enable the contextual grounding policy in your Guardrail configuration).
- IAM roles with appropriate permissions for Amazon Bedrock, Lambda, and Aurora PostgreSQL.
- A custom cluster parameter group that adds
pgauditandpg_cronto the existingshared_preload_librariesvalue (append to it rather than replacing it, so defaults such aspg_stat_statementsare preserved. This requires a cluster restart). Setcron.database_nameto your target database. - Basic familiarity with PostgreSQL, SQL, and Python.
Note: The prerequisites listed here focus on the database layer. Your application layer (for example, AWS Lambda, Amazon API Gateway, and a chat UI) is separate and depends on your deployment architecture.
Design patterns for the Explainability dimension
This section presents the database-layer design patterns that make every AI-generated response traceable, from the user query, through retrieval and guardrail evaluation, to the final answer and its citations.
Step 1: Set up the database schema
Create the core tables for customer data, chat sessions, interaction logging, and feedback:
Start by creating the schema and the tables you need. Each table serves a specific Responsible AI dimension:
CREATE SCHEMA IF NOT EXISTS rai_postgresql;
The customers table stores profiles for tenant-aware access control:
CREATE TABLE rai_postgresql.customers (
customer_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
full_name VARCHAR(150) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
phone VARCHAR(20),
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
is_active BOOLEAN DEFAULT TRUE,
metadata JSONB DEFAULT '{}'
);
The chat_interactions table is the core of the Explainability implementation. It logs every query-response cycle with full RAG provenance, including retrieved chunk IDs, similarity scores, cited versus retrieved sources, guardrail traces, and the model used:
CREATE TABLE rai_postgresql.chat_interactions (
interaction_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
session_id UUID NOT NULL,
customer_id UUID NOT NULL REFERENCES rai_postgresql.customers(customer_id),
turn_number INTEGER NOT NULL DEFAULT 1,
request_text TEXT NOT NULL,
request_timestamp TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
response_text TEXT,
response_timestamp TIMESTAMP WITH TIME ZONE,
response_latency_ms INTEGER,
intent VARCHAR(100),
confidence_score NUMERIC(5, 4),
-- Explainability columns
retrieved_chunk_ids UUID[], -- IDs of chunks returned by pgvector
similarity_scores NUMERIC[], -- cosine similarity per chunk
citations JSONB, -- cited vs. all-retrieved sources
guardrail_assessment JSONB, -- full Guardrail trace
model_id VARCHAR(100), -- Bedrock model used
guardrail_version VARCHAR(20) -- Guardrail version applied
);
Because chat_interactions stores raw request_text and response_text, protect it the same way as the source data: redact PII before the INSERT (reusing the ingestion-time guardrail), or encrypt those columns with pgcrypto, and apply Row-Level Security to the log tables so tenants cannot read each other’s interactions. Logging unprotected customer content would undercut the Privacy and Security control this design is meant to demonstrate.
The chat_feedback table captures user ratings and comments on chatbot responses, which supports the Controllability dimension. The ON DELETE CASCADE clause makes sure the 90-day retention purge does not fail with foreign key violations:
CREATE TABLE rai_postgresql.chat_feedback (
feedback_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
interaction_id UUID NOT NULL
REFERENCES rai_postgresql.chat_interactions(interaction_id)
ON DELETE CASCADE,
customer_id UUID NOT NULL REFERENCES rai_postgresql.customers(customer_id),
rating SMALLINT NOT NULL CHECK (rating BETWEEN 1 AND 5),
feedback_text TEXT,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
Step 2: Prepare the knowledge base with pgvector and Aurora ML
Create the retrieval layer with vector embeddings, tenant isolation, and Aurora ML integration:
CREATE EXTENSION IF NOT EXISTS vector;
CREATE EXTENSION IF NOT EXISTS aws_ml CASCADE;
CREATE TABLE rai_postgresql.knowledge_chunks (
chunk_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
ticket_id UUID NOT NULL,
content TEXT NOT NULL,
embedding VECTOR(1024), -- Amazon Titan Text Embeddings V2 (default 1024)
metadata JSONB, -- source, date, category, product
tenant_id UUID,
created_at TIMESTAMP DEFAULT NOW()
);
Create an HNSW index for fast approximate nearest neighbor search:
-- HNSW in