19.5 C
Canberra
Monday, March 2, 2026

Bettering order historical past search utilizing semantic search with Amazon OpenSearch Service


If you happen to’ve ever shopped on Amazon, you’ve used Your Orders. This characteristic maintains your full order historical past courting again to 1995, so you possibly can observe and handle each buy you’ve made. The order historical past search characteristic allows you to discover your previous purchases by getting into key phrases within the search bar. Past simply discovering objects, it offers an easy technique to repurchase the identical or comparable objects, saving you effort and time.

Varied options throughout Amazon’s buying expertise, equivalent to Rufus and Alexa, use order historical past search that can assist you discover your previous purchases. Subsequently, it’s necessary that order historical past search can find your previous bought objects as precisely and shortly as potential.

On this put up, we present you the way the Your Orders crew improved order historical past search by introducing semantic search capabilities on high of our current lexical search system, utilizing Amazon OpenSearch Service and Amazon SageMaker.

Limitations of lexical search

Order historical past search makes use of lexical matching to seek out objects from your complete order historical past of a buyer that match a minimum of one phrase of the search key phrases. For instance, if a buyer searches for “orange juice,” the system retrieves all orange juice objects in addition to recent oranges and different fruit juices the shopper had beforehand ordered. Though lexical matching can present a excessive recall of things with phrases matching the search key phrases exactly, it doesn’t work properly for associated or generic search key phrases, like “well being drinks” on this instance.

Because the launch of Rufus, Amazon’s AI-enabled buying assistant, a rising variety of prospects are experiencing a streamlined and richer buying journey, together with looking for their earlier purchases with Rufus. Prospects can now ask “Present me wholesome drinks” with out worrying about utilizing prolonged, extra exact phrases like “kombucha”, “inexperienced tea”, and “protein shakes”. This makes the search expertise extra conversational and intent-based, presenting a chance to make merchandise discovery extra intuitive. For Rufus to reply order historical past searches with the identical intuitive expertise equivalent to “Present me the wholesome drinks I purchased final 12 months”, the underlying order historical past knowledge retailer (“Your Orders”) wants semantic search functionality to grasp the underlying semantics of search key phrases past the standard lexical matching.

Challenges implementing semantic search

Implementing semantic search at our scale introduced a number of technical challenges:

  • Scale – We would have liked to allow semantic search throughout billions of data comparable to prospects’ order historical past globally.
  • Zero downtime – We would have liked to maintain the system 100% accessible whereas making modifications on the backend to introduce semantic search.
  • Stopping search high quality degradation – Semantic search is meant to enhance the standard of search outcomes. Nevertheless, in some circumstances, it might scale back search high quality. For instance, if a buyer remembers their merchandise title precisely and desires to seek out solely objects matching that title, surfacing comparable objects along with the precisely matching objects will improve crowding in outcomes and make it more durable to seek out the related merchandise. Equally, semantic search won’t work for circumstances the place the shopper intends to look by identifier values, like order ID, which lack an inherent semantic that means. For these eventualities, we use lexical search solely.

Resolution overview

Semantic search is powered by giant language fashions (LLMs), that are largely educated on human languages. These fashions may be tailored to take a chunk of textual content in any language they have been educated in and emit an embedding vector of a hard and fast size, regardless of the enter textual content size. By design, embedding vectors seize the semantic that means of enter textual content such that two semantically comparable textual content strings have excessive cosine similarity computed on their respective embedding vectors. For semantic search on order historical past, the enter textual content topic to embedding technology and similarity computation are the shopper search phrases and the product textual content of bought objects.

We divide our resolution into two components:

  • Bettering system scalability and resiliency for dealing with requests at scale – Earlier than implementing semantic search, we would have liked to make sure our infrastructure may deal with the elevated computational load, main us to undertake a cell-based structure. This step just isn’t wanted for each use case, however methods with very excessive scale when it comes to request or knowledge quantity can profit quite a bit from its use earlier than implementing a resource-intensive use case like semantic search.
  • Implementing semantic search – We started by evaluating the accessible embedding fashions, utilizing the offline analysis capabilities of Amazon Bedrock to check completely different fashions. After we chosen our mannequin, we may set up the infrastructure for producing embedding vectors.

Bettering system scalability and resiliency

We used the cell-based structure design sample for enhancing our scalability and resiliency. A cell-based design entails partitioning the system into equivalent, smaller, self-contained chunks, or cells, which deal with solely part of the general visitors acquired by the system. The next diagram reveals a high-level illustration of a cell-based design for order historical past search.

Cell-based architecture diagram showing customer request routing to Amazon OpenSearch Service domains via hash-based partitioning

Every cell serves an outlined subset of our prospects. Cells don’t want to speak with each other to serve a buyer request. Every buyer is assigned to a cell and every request from that buyer is routed to that cell. The OpenSearch Service area in every cell holds knowledge just for the subset prospects that it’s purported to serve. The variety of cells (N) and distribution of knowledge amongst these cells is determined by the enterprise use case, however the objective is to attain as even a distribution of knowledge and visitors as potential.

The routing logic may be stored as easy or as subtle because the use case requires it to be. The cell project values can both be computed at runtime for every request, or they are often computed one time and written to a cache or persistent knowledge retailer like Amazon DynamoDB, from the place cell project values may be fetched for subsequent requests. For order historical past search, the logic was easy and fast sufficient to be executed at runtime for every request. Wanting up cell project from a persistent knowledge retailer is particularly helpful for circumstances the place there’s a danger of some cells turning into “heavier” than others over time. In such circumstances, it turns into simpler to redistribute the heavy cell’s knowledge by merely overriding cell project values for particular keys within the knowledge retailer, as a substitute of getting to alter the partitioning logic instantly, which could have an effect on knowledge distribution throughout all of the cells.

Because the system’s load grows, the variety of cells within the system may be elevated to deal with the extra visitors. Even with out rising the variety of cells within the system, we will redistribute present knowledge among the many current N cells by reassigning some keys from a number of closely populated cells to completely different frivolously populated cells to unfold out the load extra evenly throughout all of the cells and make extra environment friendly use of the infrastructure.

A cell-based structure additionally helps make the system extra resilient. For instance, if we lose one cell, our capability is diminished solely by 1/N, as a substitute of 100%. This association will also be improved to scale back the capability loss even additional by assigning partitioning keys to 2 or extra cells such that they get written to 2 or extra cells. In such circumstances, lack of a single cell doesn’t end in knowledge loss.

Implementing semantic search

Implementing semantic seek for our order historical past search required a number of key selections and technical steps. We started by evaluating the accessible embedding fashions, utilizing the offline analysis capabilities of Amazon Bedrock to check completely different fashions towards our particular enterprise area necessities. This analysis course of helped us determine which mannequin would ship one of the best efficiency for our use case. After we chosen our mannequin, we would have liked to determine the infrastructure for producing embedding vectors. We containerized our embedding mannequin and registered it in Amazon Elastic Container Registry (Amazon ECR), then deployed it utilizing SageMaker inference endpoints to deal with the precise vector computation at scale.

For the search infrastructure itself, we selected OpenSearch Service to implement our semantic search capabilities. OpenSearch Service supplied each the vector storage we would have liked and the search algorithms required to ship related outcomes to our customers.

One among our largest challenges was updating our historic knowledge to assist semantic search on current orders. We constructed a knowledge processing pipeline utilizing AWS Step Capabilities to orchestrate the workflow and AWS Lambda capabilities to deal with the precise vector technology for our legacy knowledge, so we may present semantic seek for all of the data we wished to.

The next diagram illustrates the high-level structure.

Architecture diagram showing read-flow and write-flow for semantic search using Amazon OpenSearch Service and Amazon SageMaker embedding vectors

Mannequin analysis and choice

Order historical past search makes use of an embedding mannequin educated on Amazon-specific knowledge. Area-specific coaching is important as a result of the generated embedding vectors should work properly for the enterprise context to return high quality outcomes.

We used an LLM-as-a-judge methodology with Anthropic’s Claude on Amazon Bedrock to judge candidate fashions. Anthropic’s Claude acquired prompts containing anonymized merchandise textual content and search phrases from buyer order historical past, then filtered and ranked objects by relevance. These outcomes served as floor fact for comparability.

We evaluated fashions utilizing normal rating metrics:

  • Normalized Discounted Cumulative Acquire (NDCG) – Measures rating high quality towards preferrred order
  • Imply Reciprocal Rank (MRR) – Considers place of first related merchandise
  • Precision – Charges accuracy of retrieved outcomes
  • Recall – Charges means to retrieve all related objects

This course of helped us decide one of the best mannequin.

Retrieval technique: Buyer-scoped complete search

Order historical past search has two key necessities:

  • Search solely by means of the requesting buyer’s order historical past – We don’t need objects from one buyer’s order historical past exhibiting up in search outcomes for one more buyer
  • Search all of that buyer’s historical past – We don’t wish to miss exhibiting an merchandise that may have been related for the shopper’s search phrase simply because the search algorithm missed evaluating it for some motive

Our method entails utilizing OpenSearch Service to retrieve all objects for the shopper who issued the search question, calculating relevance scores for every of them towards the search phrase, sorting by rating, and returning high Ok outcomes. This offers complete outcomes protection for every buyer.

Vector storage with OpenSearch Service

We used two OpenSearch Service options for environment friendly vector storage and search:

  • knn_vector datatype – Constructed-in assist for storing embedding vectors. Current domains can add this subject kind with out reindexing, enabling actual kNN search throughout all data. We didn’t want approximate kNN as a result of the variety of data for many prospects was sufficiently small for actual kNN to scale.
  • Scripted scoring – Painless scripts compute vector similarity server-side, lowering shopper complexity and sustaining low latency.

Hybrid search

Hybrid search refers to combining the outcomes of lexical and semantic search to profit from the strengths of every. The hybrid question capabilities of OpenSearch Service simplify implementing hybrid search by letting purchasers specify each varieties of queries in a single request. OpenSearch Service runs each queries in parallel, merges their outcomes, normalizes the relevance scores of the sub-queries, and types outcomes by the supplied kind order (relevance rating by default) earlier than returning them to purchasers.

This provides purchasers one of the best of each varieties of searches. For instance, there are particular eventualities the place the search phrase doesn’t make a lot sense semantically, like when prospects search by their orderId values. Semantic search just isn’t designed for such circumstances; these are finest served utilizing key phrase matching.

The hybrid search performance helped save implementation effort and potential latency improve for order historical past search.

Updating historic knowledge

After the infrastructure has been arrange, newly ingested data are continued with the related embedding vectors and assist semantic search on these data. Nevertheless, when prospects search, they sometimes seek for merchandise that they had bought earlier. Subsequently, the system may not assist enhance buyer expertise a lot except the older data are up to date to incorporate the related embeddings. The method to populate this knowledge is determined by the dimensions of the issue at hand.

Releasing the change to reduce potential buyer impression

Our last step was to launch the change to purchasers in a fashion such that the impression of any potential issues is as small as potential. There are a number of methods to do this, together with:

  • Implementing semantic search in a fashion such that any transient points within the semantic search circulate make the logic fall again to lexical-only search, as a substitute of failing the request fully. Even when semantic search doesn’t execute, the system ought to nonetheless have the ability to return outcomes of lexical search to the shopper, as a substitute of empty outcomes.
  • Gating the change such that the default conduct stays lexical-only search and purchasers who want the semantic search characteristic should go a further flag within the request, for instance, which executes the semantic or hybrid circulate just for these requests.
  • Holding the brand new circulate behind a characteristic flag in the course of the preliminary interval such that it might be turned off fully if some important drawback is detected.

Examples of improved buyer expertise

The next are some examples of buyer interactions with Rufus that required Rufus to question the respective buyer’s order historical past to reply their query and provides them the required items of data.

The next screenshots present how semantic search picks up wood spoons for a “sustainable utensils” question and completely different sorts of chargers regardless of not having the key phrase “charger” within the title description, within the case of the wall connector.

Two side-by-side screenshots demonstrating semantic search results for sustainable utensils and chargers in an e-commerce interface.

The next screenshots present how semantic search picks up related outcomes though the title description doesn’t embody the queried key phrases.

Two side-by-side screenshots demonstrating semantic search results for healthy snacks and kids educational items in an e-commerce order interface.

The semantic search characteristic of order historical past search helped Rufus fetch them and present to the shoppers. Earlier than semantic search, Rufus wasn’t capable of present any outcomes to prospects for such queries.

Enterprise impression

Our resolution resulted within the following key enterprise impacts:

  • Buyer expertise enhancements – The answer achieved 10% enchancment in question recall, rising the proportion of searches that return related outcomes. It additionally decreased customer support contacts for points associated to finding previous orders.
  • Accomplice integration success – The answer strengthened pure language processing capabilities for Alexa and Rufus, enhancing their means to interpret order historical past queries. It additionally decreased the necessity for reranking and postprocessing by accomplice groups. We improved question success fee by 20%, that means extra buyer searches now return a minimum of one related merchandise. We additionally noticed enhanced end result protection by 48%, with semantic search constantly surfacing extra related matches that lexical search would have missed.

Conclusion

On this put up, we confirmed you the way we developed Amazon order historical past search to assist semantic search capabilities. This transition concerned utilizing cutting-edge AI expertise whereas working inside current infrastructure limitations to develop options that averted disruption and maintained SLAs in the course of the characteristic improve. The implementation additionally concerned backfilling, the place billions of paperwork have been processed at charges a number of instances greater than regular ingestion to compute embedding vectors for beforehand bought objects. This operation required cautious engineering and took benefit of the resilience OpenSearch Service presents even underneath excessive load.

Past the instant implementation, this basis allows continued innovation in search expertise. The embedding vectors framework can incorporate improved fashions as they develop into accessible, and the structure helps enlargement into new capabilities equivalent to personalization and multi-modal search.

You may get began with actual k-NN search as we speak following the directions in Actual k-NN search. If you happen to’re searching for a managed resolution to your OpenSearch cluster, take a look at Amazon OpenSearch Service.


Concerning the authors

Shwetabh

Shwetabh

Shwetabh is a Senior Software program Engineer at Amazon with pursuits in distributed methods and machine studying. Outdoors of labor, he’s an avid reader with a specific love for technical deep-dives and thought-provoking non-fiction.

Harshavardhan Miryala

Harshavardhan Miryala

Harshavardhan is a Software program Engineer at Amazon. He’s obsessed with machine studying, with specific curiosity in data retrieval and distributed computing. Outdoors of labor, he enjoys enjoying racquet sports activities and watching soccer.

Ayush Kumar

Ayush Kumar

Ayush is a Tech Chief at Amazon. He’s a passionate builder with an expertise of over 14 years and leads the Your Orders Search product. In his spare time, he enjoys watching cricket and enjoying together with his toddler.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles