[Report] Improving Hybrid Search Results in Aurora PostgreSQL #AWSreInvent #DAT410

[Report] Improving Hybrid Search Results in Aurora PostgreSQL #AWSreInvent #DAT410

I attended a hands-on Builders' Session at AWS re:Invent 2026 on improving hybrid search in Aurora PostgreSQL and connecting it to an agent!
2026.12.03

This page has been translated by machine translation. View original

Introduction

Hello, this is Kanno from the Consulting Department, currently enjoying re:Invent to the fullest.
I bought something like an OREO cake and it was incredibly delicious. I ate it late at night and got to enjoy that guilty feeling.

I attended the AWS re:Invent 2026 Builders' Session "DAT410: Build agentic hybrid retrieval with Amazon Aurora PostgreSQL"!

I was going to attend a Strands Agents session, but it was so popular that registration closed just before it started. While wandering around sadly, I found this session on hybrid search!? It looked interesting, so I joined!

In this article, I'll explain how hybrid search with Aurora works by dividing the flow into four stages!

Session Overview

  • Title: DAT410-R1 | Build agentic hybrid retrieval with Amazon Aurora PostgreSQL
  • Type: Builders' session (60 minutes)
  • Level: 400 – Expert
  • Date and time: December 2, 2026, 13:30–14:30 (PST)
  • Venue: MGM Grand Level 3 Chairman's 363 Content Hub Builders' Session 1
  • Speakers: Shayon Sanyal / Sudhir Amin / Rinisha Marar / Radwan Deeb / Kanishka Chaturvedi
  • Main services: Amazon Aurora PostgreSQL / Amazon Bedrock / Amazon Bedrock AgentCore

What if your agent's most convincing answer rests on the wrong evidence? Build agentic hybrid retrieval with Aurora PostgreSQL across more than 500,000 product listings in three connected hands-on labs. Debug SQL combining full-text search, pg_trgm fuzzy matching, and pgvector semantic search under shared filters. Repair reciprocal rank fusion, inspect Amazon Bedrock reranking, and compare retrieval settings against judged queries. Then build a Strands agent, connect its retrieval tools through Amazon Bedrock AgentCore Gateway, and deploy it to AgentCore Runtime. Trace its searches to cited specifications and reviews, and test what happens when requirements change. Leave with reusable retrieval SQL and working agent code.

On the day, the first 20 minutes or so consisted of an explanation of the mechanism using slides, and then we moved on to the hands-on part. The workshop code is publicly available, so if you're curious, please check it out too!

https://github.com/aws-samples/sample-agentic-hybrid-retrieval-aurora-postgresql

The Subject Is a Fictional E-commerce Store "Mosaic"

The stage for the labs is a fictional e-commerce store called "Mosaic". Aurora PostgreSQL holds 553,911 products built from the Amazon Reviews 2023 data. Cohere Embed v4 embeddings (1,024-dimensional vectors) were already stored for every item. Across the three labs, we respond in order to the requests of "Alex", a shopper who wants to put together a desk setup.

There are three screens.

  • Shop (ordinary product search)
  • Ask Mosaic (consulting with the agent)
  • Playground (checking search rankings and the agent's tool calls)

Mosaic system architecture. Both Shop and SQL tools search Aurora PostgreSQL with the same search SQL

AgentCore Runtime is used twice here.
In the first Runtime, the Strands Agents agent runs and executes the search tools via AgentCore Gateway (MCP).
The search tools run in the second Runtime and send the search SQL to Aurora. Both Shop and Ask Mosaic use the same search SQL, so if you fix the SQL in Labs 1 and 2, the agent's search improves as is.

Looking at the Search Flow in Four Stages

Mosaic's search proceeds in the following four stages.

The four search stages (Retrieve, Rank, Rerank, Reason) and the bug locations in each lab

In the first stage, full-text search, fuzzy search, and semantic search are run under the same filter conditions to find products.
Next, the results of the three are merged and narrowed to the top 50 candidates (the shortlist), and Cohere Rerank 3.5 reorders those 50.
Shop displays the top 12. In the last stage, the agent uses this search as a tool, reads product specifications and reviews, and answers with citations.

It may go without saying, but the reordering model receives only the top 50 products left after fusion. No matter how smart the model is, it cannot reorder products that fell out of the 50.
The agent is also instructed to answer based on the products returned by the search tool and their specifications and reviews. When a product doesn't show up, you need to check step by step from the search: "which search found it" and "did it remain in the top 50".

Only Fuzzy Search Can Find a Mistyped Model Number (Lab 1)

Alex typed the product ID "B0C2WWCFQB" for a headphone (Logitech Zone 900) with two characters swapped: "B0C2WWFCQB". Before the fix, Mosaic did not include this product in the 50 candidates, so it was not even a target for reordering.

In the session explanation, a slide compared which search could find the same headphones when searching for them in three different ways.

Slide comparing the ranks in full-text search, fuzzy search, and semantic search when searching for the same headphones with the exact ID, an ID with two characters swapped, and in one's own words

In the slide's example, when the exact ID was entered, Logitech was ranked first in both full-text and fuzzy search.
Only fuzzy search can find the ID with two characters swapped. For a query in one's own words like "headphones for focusing at home", semantic search ranked it first and full-text search ranked it 30th. Each search is good at a different way of asking, which is why the three are combined. This bug corresponds to the second case.

It's easy to see the difference by checking one by one in psql how the three searches handle this ID.

Results of running each of the three searches individually (excerpt)
      search      | found | logitech
------------------+-------+----------
 full-text search |     0 |
 fuzzy matching   |     1 |        1
 semantic search  |   150 |

Full-text search registers the ID in the index as a single word. When two characters are swapped, it becomes a different word, so nothing is found. Semantic search returned 150 results, but an ID has no meaning, so Logitech was not included.

Only fuzzy search (pg_trgm) found it in first place. pg_trgm splits a string into three-character fragments (trigrams) and judges similarity by the proportion of shared fragments.
Swapping only changes the fragments around the swap, so 7 of 11 remained in common.

Trigram comparison
typed_id_trigrams    | {"  b"," b0",0c2,2ww,b0c,c2w,cqb,fcq,"qb ",wfc,wwf}
listing_id_trigrams  | {"  b"," b0",0c2,2ww,b0c,c2w,cfq,fqb,"qb ",wcf,wwc}
shared_trigram_score | 0.46666667

The similarity (word_similarity) between the entered ID and the best-matching part of the product text was 0.55, which exceeded the threshold of 0.5 set in Mosaic.

Still, the product didn't make it into the candidates before the fix because the fuzzy search results were not being passed to the fusion step.
The Lab 1 fix was to add the fuzzy search portion to the part that combines the three search results into a single table.

labs/lab1_retrieve/hybrid_search.sql (excerpt)
), channels AS (
    SELECT product_id, 'fts'::text AS channel, fts_rank AS source_rank,
           fts_score AS raw_score,
           mosaic_search.reciprocal_rank_contribution(
               fts_rank, rrf_k
           ) AS contribution
    FROM fts
-- LAB1_EDIT_START
    -- Added: also pass fuzzy search results to the fusion
    UNION ALL
    SELECT product_id, 'fuzzy', fuzzy_rank,
           fuzzy_score,
           mosaic_search.reciprocal_rank_contribution(fuzzy_rank, rrf_k)
    FROM fuzzy
-- LAB1_EDIT_END
    UNION ALL
    SELECT product_id, 'semantic', semantic_rank,
           semantic_score,
           mosaic_search.reciprocal_rank_contribution(semantic_rank, rrf_k)
    FROM semantic

After applying the SQL and rerunning the same search, Logitech went from "outside the candidates" to first place both after fusion and after reordering! You can also see on the Shop screen that only fuzzy search found it.

Shop after the fix. In the mistyped ID, FC and CF are swapped, and only fuzzy search found it

Semantic search is weak with strings that have no linguistic meaning, like model numbers and SKUs.
This was a good example of why you should add full-text search and fuzzy search to a search built only on vector search!

Fuse by Rank, Not by Score (Lab 2)

The next request is "a 27-inch, 4K monitor with 90W USB-C power delivery".

Semantic search found the ViewSonic VG2756-4K at 10th place, but it dropped out of the 50 candidates after fusion.

The scores of the three searches are on different scales, so Mosaic fuses results using ranks. This method is RRF (Reciprocal Rank Fusion), which adds up "1 ÷ (k + rank)" for each list a product appears in. Shop's setting is k = 60, so 1st place is about 0.0164, 10th place is about 0.0143, and 130th place is about 0.0053. The higher the rank, the higher the score, and the more searches a product appears in, the larger its total.

The session slides also had an easy-to-follow example.

RRF calculation example. 3M Quiet Space, 9th in full-text and 3rd in semantic search, gets 0.0304 and ranks 1st after fusion, while Logitech Zone 900, 1st in semantic and 30th in full-text, gets 0.0275 and ranks 4th

Let's calculate the scores using the slide's example here as well.
In the search for "headphones for focusing at home", 3M Quiet Space is 9th in full-text search and 3rd in semantic search. Its score is 0.0304, the sum of 1 ÷ (60 + 9) and 1 ÷ (60 + 3), and it became 1st after fusion. Logitech Zone 900, 1st in semantic search, is 30th in full-text search, so its total is 0.0275, putting it 4th. Being fairly high in two searches can be stronger than being 1st in one.

The Lab 2 bug was that this calculation added a constant 1.0 instead of the rank.
Comparing the scores of the two monitors in psql, the BenQ at 130th and the ViewSonic at 10th in semantic search have the same score.

Scores before the fix (excerpt)
monitor             | position | in_top_50 | should_score | actual_score
BenQ PD2720U        |      130 | t         |       0.0053 |       0.0164
ViewSonic VG2756-4K |       10 | f         |       0.0143 |       0.0164

In a tie, the smaller product ID comes first, so BenQ stayed in the candidates and ViewSonic dropped out.
The fix is simply to replace 1.0 with the rank (source_rank).

labs/lab2_rank/rrf_contribution.sql (excerpt)
-- LAB2_EDIT_START
SELECT
    1.0::double precision
    / (
        rrf_k::double precision
        + source_rank::double precision  -- Before the fix: 1.0::double precision
    )
-- LAB2_EDIT_END

After the fix, ViewSonic entered the candidates at 21st after fusion (10th in semantic search), and after reordering it was 5th, making it into Shop's 12 displayed items!

ViewSonic entered the candidates at 21st after fusion from 10th in semantic search, and is 5th after reordering

What Happens When You Change k and the Number of Candidates

RRF's k is a value that determines how heavily top ranks are weighted.
When k is small, the gap between 1st and 10th becomes large, and when k is large, appearing in multiple lists is emphasized more. In the lab, we could also run comparisons of changed settings using 141 queries where humans had labeled the correct answers.

Change Number of correct products that entered the candidates (difference from current settings)
Increase candidates to 75 (k = 60) +17
k = 120 -1
k = 30 -5

This comparison is counted on the candidates before reordering.
Increasing candidates makes it easier for correct answers to get in, but it doesn't look at whether they reach the 12 displayed items or at the reordering time. If you change settings, you need to measure those as well.

Is Reordering Worth a Model Call Every Time?

We also checked the cost of reordering.
These are the results of running the same monitor search without and with reordering.

Results of labs/lab2_rank/rerank_off_on.py (excerpt)
               | Reranking off | Reranking on
 Status        | disabled      | applied
 Search time   | 328 ms        | 942 ms
 Reranking step| -             | 618 ms

Without reordering, ViewSonic didn't make the 12, and many 15.6-inch portable monitors were mixed in.
With reordering, ViewSonic comes in 5th. However, the 2560×1440 Acer CB273U also rose to 6th. Alex wrote "4K", so if you want to reliably satisfy 4K, you need to filter by resolution rather than leave it to reordering.

The workshop also included results of evaluating the top-10 ordering on 399 queries that were not used for tuning.
In terms of the metric that gets higher when highly relevant products come near the top (nDCG@10), hybrid search was 0.017 higher on average than semantic search alone. Adding reordering improved 56 queries but worsened 65, so an average improvement could not be confirmed, they said.
So reordering is not always helpful. There are cases where it helps, like this monitor search, so I felt the message was to measure quality and latency on your own data before deciding to adopt it!

Checking the Agent's Answers Against Product Specifications and Reviews (Lab 3)

Finally, we connect the search we've fixed so far to the agent!
The core of the agent is Strands Agents, and all that you write in the lab is the part that assembles the Agent from the provided model, tools, instructions, and hooks.

labs/lab3_reason/agent.py (excerpt)
def create_agent(*, model, tools, instructions: str, hooks) -> Agent:
    """Build an agent that can choose tools and return a supported recommendation."""
    # LAB3_EDIT_START
    return Agent(
        model=model,
        tools=tools,
        system_prompt=instructions,
        hooks=hooks,
        callback_handler=None,
    )
    # LAB3_EDIT_END

The hooks limit tool calls to a maximum of 10 per question and stop processing if an error occurs that retries can't fix. Deploying with the provided script took 1 minute 10 seconds from building the container image to updating the Runtime and syncing the Gateway tools.

The agent uses five tools.
Three related to search are executed by the second Runtime via the Gateway, and the remaining two run in the same Runtime as the agent.

Tool Where it runs Role
search_products Second Runtime (via Gateway) Hybrid search
get_product_evidence Second Runtime (via Gateway) Retrieve product specifications and reviews
explain_retrieval Second Runtime (via Gateway) Check the ranks of saved search results
compare_products Agent side Compare products
synthesize_cited_answer Agent side Create and validate an answer with citations

Following Tool Calls in a Setup Consultation

In Ask Mosaic, I sent the question: "I have a Logitech Zone 900 and a ViewSonic VG2756-4K, and next I'm considering a Steelcase Gesture chair. Complete my setup with sources."
The agent searched for the headphones, monitor, and chair once each in parallel. After that, it compared the products, checked the search ranks and sources, and created an answer with citations.

Ask Mosaic tool calls. The three products were searched once each in parallel, and creating the cited answer took about 20 seconds

There were nine tool calls in total, and it took 40.9 seconds to answer.
Each search took about 2.5 seconds, and half of the time was spent creating the cited answer (about 20 seconds). The instructions (service/agent.py) include a rule that "every claim about a product must come from tool results", and also say "in a setup consultation, search for the headphones, monitor, and chair separately", and it behaved exactly that way!

The answer came with six sources (three product pages and three reviews). What caught my attention was that the chair's product page citation only supported the weight capacity (400 pounds). The reviews also included a voice saying the headrest caused neck and shoulder pain. The answer also concluded that it could not be confirmed from the sources that this chair would complete the setup. Good thing it didn't lie!

When Requirements Change, It Doesn't Answer with Numbers Not in the Sources

Next I asked, "I now need 100W power delivery for my laptop. Does the ViewSonic still meet the requirement?", and the agent searched the monitor's record again.

The answer was that the product page says 90W, so it can't be said to meet the 100W requirement. It also listed things to confirm: the wattage the laptop needs, support for USB-C power delivery, and the monitor's model number.

Answer to the 100W question. It judges that the source says 90W so it falls short of 100W, and also shows that the sources have no mention of 100W

Before showing an answer to the user, Mosaic checks each sentence against the cited records.
Checking of numbers and the like is done without using a model, and in the Go deeper script you could try the same check on its own.

Verifying sentences against the cited records
uv run python scripts/check_claim.py 1551237 "The ViewSonic VG2756-4K delivers up to 90W over one USB-C cable [1]."
uv run python scripts/check_claim.py 1551237 "The ViewSonic VG2756-4K delivers 100W over one USB-C cable [1]."
Execution results (excerpt)
PASS: every citation names the listing and every stated figure is in it

BLOCKED: Synthesized sentence contains unsupported numeric claim or availability claim ['100W'] for product 1551237: ...

The 90W sentence passed, and the 100W sentence was blocked.
Rather than leaving everything to the prompt, it's important to have parts that can be checked mechanically, like numbers, verified by code!
Things that must be verified reliably should be verified with code.

If You Search Japanese Product Data

The lab's product data is in English, so full-text search and fuzzy search worked as they were. If you build the same setup for Japanese, you need to rethink the first "find" stage...

This is because PostgreSQL's standard full-text search splits words by spaces and symbols. When I tried it on local PostgreSQL 17, a Japanese sentence was treated as one whole word, and searching for the word "headphones" didn't match.

Results checked on PostgreSQL 17 (local) (excerpt)
to_tsvector('simple', '在宅で集中できるヘッドホン')  → '在宅で集中できるヘッドホン':1
上の文を to_tsquery('simple', 'ヘッドホン') で検索    → f(一致しない)

Fuzzy search with pg_trgm also works in three-character units, so it isn't suited to short Japanese words...
The word_similarity of "chair" against "It's an ergonomic chair" was 0. "Headphones" within a sentence was also 0.5, which doesn't reach the standard threshold of 0.6. When the database locale was C, trigrams themselves weren't even generated from Japanese.

For Japanese, the pg_bigm extension, which builds an index by splitting every two characters, is a candidate. It's an extension you can use on Aurora PostgreSQL too!

On the other hand, RRF, which uses only ranks, works as is even if the contents of the searches change.
In Japanese, different kinds of mistakes from English also occur, such as conversion errors and notation variations, so I'd want to decide what to hit with fuzzy search after checking with Japanese data.

Things That Might Be Useful

The sample repository mentioned earlier has the lab's search SQL, the agent code, and design documents all together!
There are also instructions for running it in your own AWS account. Note that preparing the catalog takes several hours, and the Aurora and Bedrock costs are charged to your own account.

https://github.com/aws-samples/sample-agentic-hybrid-retrieval-aurora-postgresql/blob/main/docs/run-in-your-own-account.md

The optional labs also included an exercise that measures the recall of an HNSW index. HNSW is fast because it searches by traversing likely-near candidates without comparing against all items, but it can overlook products that are actually close, and this exercise measures that.

There was also an exercise to see how it behaves when preferences saved in AgentCore Memory conflict with that day's request, so I'd like to try that next time too!

Conclusion

When I design RAG or agent search myself, I want to first break it down into steps, analyze where the cause of poor accuracy lies, and work on improving it! It was a really good learning experience!
Though you need to be careful around Japanese...

I hope this article was of some help! Thank you for reading to the end!!


AWS re:Invent 2026まとめ情報

クラスメソッドは2026/11/30〜12/4にラスベガスで開催されるAWSカンファレンスイベント「re:Invent」を今年も特集しました。ぜひ一度ご覧ください。 re:Invent 2026ポータルサイトを見るAWS re:Invent公式サイトはこちら

Share this article