Artificial Intelligence #
Amazon Bedrock Managed Knowledge Base now supports tabular search, so you can get answers from tables through agentic retrieval. When a question needs data from CSV, XLSX, or XLS files, tabular search looks up values and runs calculations across every relevant row in one or more tables or sheets. It then combines the results with facts from related documents to answer analytical questions that take several steps.
A finance team closing the quarter needs to know “Which departments must write variance commentary?” No single file has the answer. It depends on the variance policy’s threshold, the quarter-close memo’s budget revisions, and math over every department in the profit and loss (P&L) workbook.
Like this finance team, most teams keep their narratives and data in the same place. For example, a Microsoft SharePoint site holds workbooks next to policies, and an Amazon Simple Storage Service (Amazon S3) bucket holds CSV exports next to PDFs. Tabular search answers questions across these files through the same AgenticRetrieveStream request you already use for documents. It runs code over the original file in an isolated sandbox, so the answer uses the whole table instead of only the rows that retrieval returns. For the finance team, one request returns the departments that must write commentary. The answer cites the policy and the memo, and the trace names the workbook the code read.
In this post, you learn how tabular search answers questions that need both table data and facts from documents, and when another tool is a better fit. You also build a knowledge base with sample finance files and use the trace to see which file the code read.
Why tables are hard for retrieval #
Retrieval Augmented Generation (RAG) returns a fixed number of passages that best match a question, which works well for prose. Tables lose information when they’re split into passages, in ways that depend on the table’s shape:
- Long tables – A table with thousands of rows spans many passages, and retrieval returns only the few that best match the question. An answer built from them uses a handful of rows, so a total, a comparison, or a threshold check can be incomplete.
- Wide tables – In a table with hundreds of columns, one row can hold more text than a passage or a search model takes in at once. As a result, values in later columns are harder to match. Long passages from wide tables can also match many unrelated questions and push more relevant passages out of the results.
Retrieval also has to match a question to the right table. Questions use business terms, such as “controllable spend,” but tables hold cost center codes, account names, and numbers. A draft and a final workbook look almost the same to search. The rule that gives the numbers meaning is often in a separate document, such as a policy.
Tabular search therefore splits the work. Retrieval only has to return one passage from the right table file, and code then reads the whole table. Because retrieval still has to find that file first, naming the file in your question helps.
Table 1 shows how plain retrieval and tabular search each handle the finance team’s question, “Which departments must write variance commentary?”
| Compared | Retrieve only | Agentic retrieval with tabular search | | What you get back | Passages from the policy, memo, business review, and workbook, but no complete answer | An answer naming Sales, Engineering, and Operations, with each department’s variance against its revised budget | | Revised variance percentages | Not available. No file stores them, so no passage can contain them | Calculated from every department row in the final workbook | | Sources | Each passage links to its own file, but none of them contains the answer | Citations to the finance policy and the close memo. The trace names the workbook the code read |
Table 1: The same question with plain retrieval and with tabular search.
How tabular search works in agentic retrieval #
In agentic retrieval, an agent uses retrieval to decide which documents matter and then writes the answer. Tabular search is part of that flow, so there’s nothing to turn on.
When a question needs the data in a table, the request moves through these stages:
- Retrieve – Passages come back, including passages from a table file.
- Plan – The agent uses the question and table structure to determine whether to run code over one or more retrieved tables.
- Stage – Tabular search copies the original file into an isolated sandbox with no network access.
- Compute – Model-written code runs over the whole table or sheet.
- Return – The agent gets back only what the code prints, such as totals or matching rows.
- Answer – The agent answers from the results and the passages, with citations.
Tabular search starts when retrieved passages come from a CSV, XLSX, or XLS file and the question needs a calculation across rows or a lookup of specific values.
Knowledge bases, connectors, and APIs
An AgenticRetrieveStream request can search one knowledge base or several. The Retrieve API keeps returning passages and doesn’t run code.
Tabular search works the same way whichever connector brings the files into the knowledge base, including Amazon S3, Microsoft SharePoint, Atlassian Confluence, and others.
Scope and trade-offs
Tabular search is built for questions that need calculations or lookups over the table files it retrieves. Running code adds at least one more agent turn, so answers that use table data take longer than text-only answers. Governed metrics, recurring dashboards, warehouse-scale joins, and reporting controls still belong in your business intelligence (BI) tools. Tabular search works on table files stored next to your documents, and you don’t define a schema.
Solution overview #
In this solution, an Amazon Bedrock Managed Knowledge Base stores your CSV and Excel files together with related documents, such as PDF and Word files. Your application sends every question through agentic retrieval. When a question needs table data, the answer combines calculations over your tables with facts from your documents. It cites the passages it used, and the trace names the table files the code read.
In Figure 1, an Amazon S3 data source syncs these files into the knowledge base, which keeps embeddings, text, metadata, and the original files. When your application sends a question with AgenticRetrieveStream, agentic retrieval plans the work and retrieves passages from the knowledge base. If the question needs data from a table file, it sends the files to read to an isolated sandbox with no network access. There, model-written code runs over the original file and returns printed results. The answer, with citations and trace events, streams back to your application.
The worked example uses fictitious AnyCompany Retail finance files:
- Final P&L workbook (
anycompany-pnl-fy2026.xlsx). It has Notes, Actuals, Budget, and Summary sheets, with one row per month, cost center, and account in the Actuals and Budget sheets. - Draft workbook. A preliminary copy with different Q3 numbers.
- Finance variance policy (PDF). Defines controllable spend and approved budget, and sets review thresholds.
- Q3 close memo (Word). Lists approved and rejected budget revisions.
- Business review (Markdown). Explains the main variances.
These files are in the tabular-search folder of the sample-managed-knowledge-base-patterns GitHub repository. The folder also has an AWS Cloud Development Kit (AWS CDK) app that deploys the resources in this post, and Python scripts that ask these questions.
Prerequisites #
You need the following:
- Permissions to create AWS Identity and Access Management (IAM) roles, S3 buckets, and Amazon Bedrock knowledge bases.
- For the identity that calls
AgenticRetrieveStream, thepermissions for agentic retrieval , includingbedrock:GetDocumentContent. The agent reads the original table file with the caller’s credentials. - Amazon Bedrock in an AWS Region where tabular search is available. For Region availability, see Supported AWS Regions .
- Your own CSV, XLSX, or XLS files and related documents.
- To follow the walkthrough: Python 3.10 or later with the AWS SDK for Python (Boto3) version 1.43.123 or later. You can also ask questions from the knowledge base test window in the Amazon Bedrock console or with the AWS Command Line Interface (AWS CLI).
The calling identity needs this policy, from the agentic retrieval documentation:
For costs, see Amazon Bedrock pricing.
Upload your files to Amazon S3 #
Put the table files and related documents under one prefix.
- Open the Amazon S3 console and choose Create bucket .
- Enter a globally unique bucket name (this post uses
amzn-s3-demo-bucket), keepBlock all public access selected, and chooseCreate bucket . - Choose the bucket, choose Create folder , and enter
finance. - Open the
financefolder and chooseUpload . - Choose Add files , select your table files and documents, and chooseUpload .
Create the knowledge base and data source #
The knowledge base needs an IAM role that Amazon Bedrock can assume. This trust policy allows only the bedrock.amazonaws.com service principal, and only for knowledge bases in your account.
Next, set up the remaining resources:
- Create a role named
kb-finance-rolewith the trust policy. - Attach an inline policy that allows
s3:ListBucketon the bucket ands3:GetObjecton its objects. - Create a knowledge base of type
MANAGEDwith the managed embedding model. - Create a
MANAGED_KNOWLEDGE_BASE_CONNECTORdata source for the bucket, limited to thefinance/prefix. - Set
maxFileSizeInMegaBytesabove your largest file.
The inline policy for step 2 allows reads on this bucket only:
This script runs steps 3 to 5 and prints the IDs: