跳转到主要内容
Chinese, Simplified

category

In Part 1 of this series, we explored how Amazon’s Worldwide Returns & ReCommerce (WWRR) organization built the Returns & ReCommerce Data Assist (RRDA)—a generative AI solution that transforms natural language questions into validated SQL queries using Amazon Bedrock Agents. Although this capability improves data access for technical users, the WWRR organization’s journey toward truly democratized data doesn’t end there.

For many stakeholders across WWRR, visualizing trends and patterns is far more valuable than working with raw data. These users need quick insights to drive decisions without having to interpret SQL results. Although we maintain pre-built Amazon QuickSight dashboards for commonly tracked metrics, business users frequently require support for long-tail analytics—the ability to conduct deep dives into specific problems, anomalies, or regional variations not covered by standard reports.

To bridge this gap, we extended our RRDA solution beyond SQL generation to include visualization capabilities. In this post, we dive into how we integrated Amazon Q in QuickSight to transform natural language requests like “Show me how many items were returned in the US over the past 6 months” into meaningful data visualizations. We demonstrate how combining Amazon Bedrock Agents with Amazon Q in QuickSight creates a comprehensive data assistant that delivers both SQL code and visual insights through a single, intuitive conversational interface—democratizing data access across the enterprise.

Intent and domain classification for visual analytics

The overall architecture diagram of the RRDA system has two parts. In Part 1, we focused on the upper pathway that generates SQL; for Part 2, we explore the lower pathway (highlighted in red in the following diagram) that connects users directly to visual insights through Amazon Q in QuickSight.

RRDA Architecture Overview highlighting the visualization pathway (shown in red) that processes SHOW_METRIC intents through Q topic retrieval and selection to deliver embedded Amazon Q in QuickSight visualizations.

As mentioned in Part 1, RRDA routes user queries through intent and domain classification systems that determine how each request should be processed. When a query is classified as SHOW_METRIC (triggered by phrases like “show me” or “display,” or questions about visualizing trends), the system routes to our Amazon Q in QuickSight integration pathway instead of generating SQL. Simultaneously, our domain classifier identifies business contexts like Returns Processing or Promotions to focus the search scope. This dual classification makes it possible to seamlessly switch the user experience between receiving code and receiving visual insights while maintaining business context.

For example, when a user asks “Show me the trend for how many items were returned for the past quarter,” our system identifies both the visualization intent and the Returns Processing business domain, allowing subsequent LLMs to search within domain-specific Amazon QuickSight Q topics rather than across the entire catalog. After the user intent is classified, RRDA notifies the user that it’s searching for relevant metrics in Amazon Q in QuickSight and initiates the domain-filtered Q topic selection process described in the next section.

Q topic retrieval and selection

After the user intent is classified as SHOW_METRIC and the relevant business domain is identified, RRDA must now determine which specific Q topic can best visualize the requested information. Q topics are specialized configurations that enable business users to ask natural language questions about specific datasets. Each Q topic contains metadata about available metrics, dimensions, time periods, and synonyms—making topic selection a critical step in delivering accurate visual insights. The challenge lies in intelligently mapping user requests to the most appropriate Q topics from our catalog of over 50 specialized configurations. To solve this problem, RRDA employs a two-step approach: first retrieving semantically relevant Q topics using vector search with metadata filtering to narrow down candidates efficiently, then selecting the best matches using an Amazon Bedrock foundation model (FM) to evaluate each candidate’s ability to address the specific metrics and dimensions in the user’s query.

We implemented this retrieval-then-selection approach by building a dedicated Q topic knowledge base using Amazon Bedrock Knowledge Bases, a fully managed service that you can use to store, search, and retrieve organization-specific information for use with large language models (LLMs). The metadata for each Q topic—including name, description, available metrics, dimensions, and sample questions—is converted into a searchable document and embedded using the Amazon Titan Text Embeddings V2 model. When a user asks a question, RRDA extracts the core query intent and specified domain, then performs a vector similarity search against our Q topic knowledge base. The system applies domain filters to the vector search configuration when a specific business domain is identified, making sure that only relevant Q topics are considered. From this retrieved list, a lightweight Amazon Bedrock FM analyzes the candidates and identifies the most relevant Q topic that can address the user’s specific question, considering factors like metric availability, dimension support, and query compatibility.

The following diagram illustrates the Q topic retrieval and selection workflow.

Linear workflow diagram showing Q topic retrieval and selection process with three steps: first step shows retrieval of relevant Q topics using Bedrock Knowledge Base RAG with Retrieve API, second step shows Q topic selection and question rewriting using Bedrock Converse API with structured outputs, third step shows Amazon Q in QuickSight embedded in application frontend.

Q topic retrieval and selection workflow illustrating how RRDA identifies relevant visualization sources through vector search, then optimizes user questions for Amazon Q in QuickSight using Amazon Bedrock.

Continuing our previous example, when a user asks “Show me the trend for how many items were returned for the past quarter,” our system first detects the intent as SHOW_METRIC, then determines whether a domain like Returns Processing or Promotions is specified. The query is then passed to our Q topic retrieval function, which uses the Retrieve API to search for Q topics with relevant metadata. The search returns a ranked list of 10 candidate Q topics, each containing information about its capabilities, supported metrics, and visualization options.

This retrieval mechanism solves a critical problem in enterprise business intelligence (BI) environments—discovering which report or dataset has information to answer the user’s question. Rather than requiring users to know which of our more than 50 Q topics to query, our system automatically identifies the relevant Q topics based on semantic understanding of the request. This intelligent Q topic selection creates a frictionless experience where business users can focus on asking questions in natural language while RRDA handles the complexity of finding the right data sources behind the scenes.

Question rephrasing for optimal Q topic results

After RRDA identifies relevant Q topics, we face another critical challenge: bridging the gap between how users naturally ask questions and the optimal format that Amazon Q in QuickSight expects. Without this crucial step, even with the right Q topic selected, users might receive suboptimal visualizations.

The question rephrasing challenge

Business users express their data needs in countless ways:

  • Imprecise time frames: “How many items were returned lately?”
  • Complex multi-part questions: “Compare how many items were returned between NA & EU for Q1”
  • Follow-up questions: “Write a SQL query for how many returned items are currently being processed in the returns center” and after RRDA responds with the SQL query, then “Great! Now show me this metric for this year”

Although Amazon Q in QuickSight is designed to handle natural language, it is a generative Q&A system rather than a conversational interface, and it performs best with clear, well-structured questions. The right phrasing significantly improves response quality by making sure Amazon Q in QuickSight precisely understands what to visualize.

Structured question generation with the Amazon Bedrock Converse API

To solve this challenge, we implemented a question rephrasing system using the Amazon Bedrock Converse API with structured outputs. This approach makes sure user queries are transformed into optimal formats for Amazon Q in QuickSight while preserving critical filters and parameters.

First, we define Pydantic data models to structure the FM output:

class QTopicQuestionPair(BaseModel):
                                            """A question related to a Q topic."""
                                            topic_id: str = Field(..., description="The ID of the chosen Q topic")
                                            question: str = Field(..., description="The relevant question to ask this Q topic")
                                        class ListOfQTopicQuestionPairs(BaseModel):
                                            """Response containing a list of questions corresponding to Q topics."""
                                            pairs: List[QTopicQuestionPair] = Field(
                                                default_factory=list, description="List of {Q topic Id, Question} pair objects."
                                            )

The Converse API tool use capability makes it possible to structure responses using these defined data models so our code can parse them reliably. Our system passes the user query, conversation history, and retrieved Q topic metadata to the Amazon Bedrock FM, which formulates questions following validated patterns:

  • “Show me the [specific metric(s)] for/over [user filters]”
  • “How has [specific metric] changed from [start time frame] to [end time frame]?”
  • “Compare [metric A] to [metric B] for [time frame]”
  • “What is [specific metric] for [user filters]?”

These formats consistently produce optimal results in Amazon Q in QuickSight across our business domains while preserving critical business context—including domain-specific terminology, time filters, dimensional constraints, and comparative elements. For example, after reviewing SQL results for a resolution index metric, a user might ask the follow-up question “Now show me how this metric trended over the last 6 months,” which our system rephrases to “Show me how the resolution index trended over the last 6 months” while selecting only Amazon Q topics related to the Returns Processing business domain.

Embedding Amazon Q in QuickSight visualizations within the chat interface

When users ask to visualize data in the RRDA chat interface, the system seamlessly embeds Amazon Q in QuickSight directly within the conversation. Using the QuickSight embedding functionality, RRDA generates a secure embedding URL that renders interactive visualizations directly in the chat window. Users can view data visualizations without leaving the conversation flow. The system automatically selects the appropriate Q topic and rephrases the user’s question for optimal results, then passes this information to the embedded QuickSight component, which generates and displays the visualization. The following screenshot shows a view (with sample data) of what this embedded experience looks like. For detailed information about the embedding capabilities used, see Embedding the Amazon Q in QuickSight Generative Q&A experience.

Amazon QuickSight dashboard displaying sales analytics with multiple visualizations including a text summary showing 99 unique customers with $2,752,804 total sales revenue, a horizontal bar chart of total sales by customer name with Anthem at the top, summary metrics showing $2,752,804 sales and 99 customers, a scatter plot chart showing total sales quantity and profit by customer color-coded by company, and a detailed customer data table with order information including dates, contacts, names, regions and countries.

Sample Q Topic showing embedded visualization capabilities within RRDA’s chat interface, demonstrating how users can seamlessly transition from natural language questions to interactive data visualizations.

Direct Q topic suggestions for visualization requests

When users ask visualization-oriented questions with the SHOW_METRIC intent (for example, “Show me how many items were returned over the past 3 months”), RRDA presents relevant Q topics as interactive suggestion cards within the conversation flow. Each suggestion includes the topic name (like “Returns Processing – Sample Topic”), along with an optimized question format that the user can choose to immediately generate the visualization.

Screenshot of RRDA interface showing a user query "Show me how many items were returned over the past 3 months?" with the system's response recommending relevant Amazon QuickSight topics. The response suggests "Returns Processing - Sample Topic" with a specific question link "What is the return quantity for the past 3 months?" Thumbs up and thumbs down feedback buttons appear at the bottom of the response.

These suggestions appear with a clear heading: “Here are the most relevant questions and Amazon QuickSight Q topics:” so it’s straightforward for users to identify which data source will best answer their question. The system formats these suggestions as clickable prompts that, when selected, automatically trigger the embedded Amazon QuickSight generative Q&A modal illustrated in the previous section.

Contextual follow-up visualizations in conversations

RRDA proactively suggests relevant visualizations even when users are engaged in regular text conversations with the Amazon Bedrock agent described in Part 1. For example, when a user asks for information about a specific metric (“What is the resolution index metric? Explain it to me in 1-2 sentences”), the system provides a text explanation (which is blurred out in the following screenshot) but also automatically identifies opportunities for visual analysis. These suggestions appear as “Get related insights from Amazon Q in QuickSight:” followed by relevant questions like “What is resolution index for the last 3 months?” This creates a seamless bridge between learning about metrics and visualizing them—users can start with simple queries about metric definitions and quickly transition to data exploration without reformulating their requests. This contextual awareness makes sure users discover valuable visualizations they might not have otherwise known to request, enhancing the overall analytics experience.

Screenshot of a RRDA interface showing a query "Define the RP resolution index metric in 1-2 sentences" with the system's response providing the definition as "The Returns Processing Resolution Index is the percentage of returned items that are successfully processed within 7 business days, tracking how efficiently the returns fulfillment centers handle incoming returns." The interface also displays the calculation formula and suggests related insights from Amazon Q in QuickSight, with feedback buttons at the bottom.

Automating Q topic metadata management

Behind RRDA’s ability to suggest relevant visualizations is a knowledge base of over 50 Q topics and their metadata. To keep this knowledge base up-to-date as our analytics landscape grows, we’ve implemented an automated metadata management workflow using AWS Step Functions that refreshes daily, pictured in the following diagram.

AWS Step Functions workflow diagram showing three sequential Lambda functions: FetchQTopicMetadata (fetch latest Q topic metadata from Amazon QuickSight), BatchSummarizeQTopics (generate compact summaries using Bedrock Converse API for each new Q topic), and SyncQTopicsKnowledgeBase (sync all updated information into Q Topic Metadata knowledge base for RAG).

Automated Q topic metadata management workflow using AWS Step Functions that refreshes daily to keep the knowledge base current with the latest QuickSight Q topic configurations and validated questions.

The workflow begins with our FetchQTopicMetadata AWS Lambda function, which connects to QuickSight and gathers essential information about each Q topic—what metrics it tracks, what filters users can apply, and importantly, what questions it has successfully answered in the past. We specifically use the DescribeTopic and ListTopicReviewedAnswers APIs, and store the resulting metadata in Amazon DynamoDB, a NoSQL key-value database. This creates a powerful feedback loop—when Q topic authors review and validate questions from users, these validated questions are automatically incorporated into our knowledge base, making sure the system continuously learns from user interactions and expert curation.

For the next step in the workflow, the BatchSummarizeQTopics function generates a concise summary of this collected metadata using Amazon Bedrock FMs. This step is necessary because raw Q topic configurations often exceed token limits for context windows in FMs. The function extracts essential information—metrics, measures, dimensions, and example questions—into compact summaries that can be effectively processed during vector retrieval and question formulation.

The final step in our workflow is the SyncQTopicsKnowledgeBase function, which transforms this enriched metadata into vector-searchable documents, one for each Q topic with explicit business domain tags that enable domain-filtered retrieval. The function triggers Amazon Bedrock knowledge base ingestion to rebuild vector embeddings (numerical representations that capture semantic meaning), completing the cycle from Q topic configuration to searchable knowledge assets. This pipeline makes sure RRDA consistently has access to current, comprehensive Q topic metadata without requiring manual updates, significantly reducing operational overhead while improving the quality of Q topic recommendations.

最佳实践

根据我们在QuickSight中通过Amazon Q扩展RRDA可视化功能的经验,以下是在企业中实施生成式BI解决方案的一些最佳实践:

  • 通过智能建议预测分析需求——使用人工智能预测用户可能期望的可视化效果,在关于指标或SQL的对话中自动显示相关图表。这缓解了发现障碍,并为用户提供了他们最初可能没有想到的见解,无缝地弥合了理解数据和可视化趋势之间的差距。
  • 在连接不同的人工智能系统时构建自动翻译层——使用人工智能将自然语言查询自动重新格式化为系统期望的结构化模式,而不是要求用户学习精确的系统特定短语。保留用户的原始意图和上下文,同时确保每个系统都以其首选格式接收输入。
  • 设计反馈循环——创建自动化系统,从用户交互中收集经过验证的内容,并将其反馈到您的知识库中。通过从QuickSight中的Amazon Q等工具中收集人工审查的问题,您的系统可以通过更好的检索数据不断改进,而无需重新训练模型。
  • 在生成之前实现检索——在使用生成式人工智能选择和制定最佳问题之前,使用带有域过滤的向量搜索来缩小相关可视化源的范围,从而显著提高响应质量并减少延迟。
  • 跨模式维护领域上下文——确保业务领域上下文贯穿整个用户旅程,无论用户是接收SQL代码还是可视化,以保持度量定义和数据解释的一致性。

有关构建生产就绪生成AI解决方案的全面指导,请参阅AWS架构良好的框架生成AI透镜,了解安全性、可靠性、性能效率、成本优化、卓越运营和可持续性方面的最佳实践。

结论

在这个由两部分组成的系列中,我们探讨了亚马逊的全球退货和再商务组织如何构建RRDA,这是一个将自然语言转换为SQL查询和数据可视化的会话数据助理。通过将用于编排和SQL生成的Amazon Bedrock Agent与用于可视化分析的QuickSight中的Amazon Q相结合,我们的解决方案使整个组织的数据访问民主化。领域感知架构、智能问题改写和自动化元数据管理缓解了业务问题和数据洞察之间的障碍,大大减少了做出数据驱动决策所需的时间。随着我们根据用户反馈和功能模块的进步继续增强RRDA的附加功能,我们仍然专注于在自然语言问题和可操作的业务见解之间建立无缝桥梁的使命。

本文地址
最后修改
星期一, 九月 22, 2025 - 10:40
Tags
 
Article