<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jason Xu on Medium]]></title>
        <description><![CDATA[Stories by Jason Xu on Medium]]></description>
        <link>https://medium.com/@jasonxu625?source=rss-c2d6ae9aac7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JTtSK18kkfkdxJUEHEt7jg.png</url>
            <title>Stories by Jason Xu on Medium</title>
            <link>https://medium.com/@jasonxu625?source=rss-c2d6ae9aac7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 18:40:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jasonxu625/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Embedding-Based Retrieval: Our Journey and Learnings around Semantic Search at Faire]]></title>
            <link>https://craft.faire.com/embedding-based-retrieval-our-journey-and-learnings-around-semantic-search-at-faire-2aa44f969994?source=rss-c2d6ae9aac7------2</link>
            <guid isPermaLink="false">https://medium.com/p/2aa44f969994</guid>
            <category><![CDATA[embedding-based-retrieval]]></category>
            <category><![CDATA[search]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[faire]]></category>
            <category><![CDATA[semantic-search]]></category>
            <dc:creator><![CDATA[Jason Xu]]></dc:creator>
            <pubDate>Mon, 17 Jun 2024 23:53:19 GMT</pubDate>
            <atom:updated>2026-06-03T14:02:55.744Z</atom:updated>
            <content:encoded><![CDATA[<h3>Embedding-based retrieval: Our journey and learnings around semantic search at Faire</h3><figure><img alt="Title image: “Embedding-Based Retrieval: Our Journey and Learnings Around Semantic Search" src="https://cdn-images-1.medium.com/max/1024/0*Gvx9t8NN8OJwkev2" /></figure><p>Search is an indispensable tool for <a href="https://www.faire.com/">Faire</a>. It functions as the heart of our online wholesale marketplace, empowering retailers to find products that are both relevant and desirable. However, from an engineering perspective, finding our ideal approach to search has required, well, a bit of searching.</p><p>In order to <a href="https://news.faire.com/2021/11/04/what-defines-faire/">help our customers succeed</a>, we need a search system that enables them to find exactly what they’re looking for, quickly and reliably. Today, that system is built around embedding-based retrieval, among other search technologies. In this post, we’ll share an overview of the different components of Faire’s search system and provide a detailed account of our journey towards establishing a robust semantic search system through embedding-based retrieval.</p><h3>Where we started with our search tech stack</h3><p>Starting a few years ago, we began with a traditional tech stack consisting of <a href="https://www.elastic.co/elasticsearch">Elasticsearch</a> followed by a <a href="https://craft.faire.com/building-faires-new-marketplace-ranking-infrastructure-a53bf938aba0">real-time ranking</a> layer. Elasticsearch is primarily known for its text matching capabilities, often referred to as keyword-matching or sparse retrieval. It functions by matching a query to a document, ranking results primarily based on the BM25 algorithm. This algorithm is then augmented with a document quality score, allowing us to adjust the influence of BM25 and the document quality score through weighted parameters.</p><p>While this approach served us well initially, we reached a point where retrieval became the system’s bottleneck. The ranking system’s effectiveness had begun to wane since it couldn’t present the most pertinent candidates to users if we failed to retrieve a sufficient number of relevant ones. For instance, a user searching for “comfortable furniture” may not find relevant results if the product metadata only uses terms like “couch” or “sofa”. Semantic retrieval can learn the relationships between query and product fields, enabling it to surface relevant products even when the key words don’t align exactly. We needed to provide more robust search results to help our customers find the products they were looking for.</p><h3>The benefits of embedding-based retrieval</h3><p>In addition to the keyword matching, we decided augment our tech stack by incorporating <strong>embedding-based retrieval</strong> because it offered us several significant advantages:</p><ul><li><strong>Semantic understanding</strong>: By using models trained on extensive text data from the web and our own platform, embedding-based retrieval enables us to grasp the underlying meaning of a query and the content of our products, going beyond mere keyword matching. This allows for a more nuanced understanding of user intent.</li><li><strong>Query expansion</strong>: Embedding-based retrieval naturally expands the search set by considering synonyms and related terms without them being explicitly mentioned in the query. This capability significantly improves search flexibility and inclusivity.</li><li><strong>Improved relevance</strong>: By capturing the semantic similarities between queries and documents, embedding-based retrieval can surface more relevant results, even when the exact keywords are not present in the product descriptions.</li><li><strong>Handling nuances and misspellings</strong>: Thanks to the robust nature of embeddings, our search can effectively deal with nuanced queries and common spelling mistakes, ensuring that minor errors don’t derail the search experience.</li><li><strong>Scalability and efficiency</strong>: Despite the initial complexity of implementing such a system, once in place, it offers scalable and efficient retrieval performance, capable of handling large volumes of queries and documents.</li></ul><h3>System components</h3><p>It’s helpful to step back and grasp the entire architecture and how the introduction of embedding-based retrieval has improved the overall performance of our search.</p><p>Our journey began with a traditional search engine design, evolving over time to incorporate more sophisticated technologies to better meet our users’ needs. Here’s a closer look at each component of our system:</p><ul><li><strong>Query understanding and query parsing:</strong> First, we normalize the query to streamline downstream operations. Then we focus on trying to understand the underlying intent of a query, which could relate to a specific category or be associated with a particular brand.</li><li><strong>Retrieval:</strong> This component is where we implemented embedding-based retrieval (highlighted in green in the figure below), building upon the foundation laid by our existing Elasticsearch engine. Our previous system here was a classic keyword-matching engine with BM25. Text-match based retrieval (BM25) serves as our principal means for sparse retrieval, we mainly rank products for a given query via BM25. We also factor in geographical preferences through additional queries that focus on aspects like matching products from the same country or continent, as well as the product quality score represented by a variety of factors including clicks, return rate, conversion rate, and more. The final retrieval results are a blend of multiple sources including embedding-based retrieval and keyword-matching retrieval.</li><li><strong>Ranking</strong>: This component relies on signals including user profile, query understanding, product features, and affinity features (relationships between the user and products, as well as between the query and products), and context information (e.g., geo, device type etc). The eventual model that we used for ranking is a blend of signals, fine-tuned either through XGBoost or Deep Learning models. Our ranking goal is pairwise and leverages labels such as clicks, add-to-cart actions, and orders.</li><li><strong>Re-ranking:</strong> This is responsible for optimizing the entire page (e.g, diversification), which also integrates several business logic elements. For instance, it ensures that the products from the same brand don’t appear repeatedly in search results, and it also demotes potentially fraudulent or subpar brands.</li><li><strong>Presentation</strong>: This is the step where we incorporate badging, image selection to compile the final search results page to the users.</li></ul><figure><img alt="Figure: high level components of our search system and the new embedding-based retrieval model that includes deep-text retrieval and multimodal retrieval." src="https://cdn-images-1.medium.com/max/1024/0*fCpe5dNu12DH1_Pp" /><figcaption>An overview of our system, showing existing components in yellow and the new embedding-based retrieval model in green.</figcaption></figure><h3>System requirements</h3><p>Before incorporating embedding-based retrieval, we needed to specify the requirements for our new system and consider multiple goals we needed to balance to achieve optimal results. To ensure our platform remained responsive and user-friendly, we considered two key factors:</p><ul><li><strong>Latency:</strong> One of our chief challenges was integrating embedding-based retrieval without adversely affecting latency.</li><li><strong>Feasibility for MVP:</strong> Recognizing the initial uncertainties around the benefits of embedding-based retrieval, we prioritized the development of a Minimum Viable Product (MVP). This MVP had to balance potential model performance against developmental speed and resource allocation. We planned to measure the impact of our MVP before investing in a full launch.</li></ul><p>In the next two sections, we will cover how we trained our first few versions of embedding models, and how we served the model online with short- and long-term solutions.</p><h3>Developing a scalable two-tower model</h3><p>To craft a model suitable for our production environment, we adopted the <a href="https://medium.com/tech-p7s1/video-recommendations-at-joyn-two-tower-or-not-to-tower-that-was-never-a-question-6c6f182ade7c#:~:text=The%20idea%20behind%20the%20two,known%20as%20the%20candidate%20tower.">two-tower model</a> framework. This approach is structured to facilitate the development and iteration of our embedding-based retrieval system:</p><ul><li><strong>Two-Tower Model Foundation (Deep Text V0):</strong> We began with a foundational model utilizing a transformer-based encoder. This “vanilla” approach allowed us to establish a baseline by generating robust text embeddings that capture the essence of the query and product.</li><li><strong>Multimodal Embedding Enhancement (Multimodal Embedding):</strong> The next phase involved incorporating multimodal embeddings, which included image signals. This step was critical in creating embeddings that account for both textual and visual aspects of our products.</li><li><strong>Hybrid Model Evolution (Deep Text V1):</strong> We integrated the strengths of both the initial text-based embeddings and the multimodal approach. This hybrid model aimed to capitalize on the combined power of textual and visual signals, offering a more comprehensive understanding of user queries and product offerings.</li></ul><p>In the following sections, we’ll go over each of the stages in detail, each of which achieved better search conversion and user experience based on online A/B testing experiments.</p><h4>Deep Text V0</h4><p>Our model architecture features a two-tower approach. For queries, we utilized a deep-text encoder paired with multilayer perceptrons (MLPs), employing a pre-trained <a href="https://www.tensorflow.org/hub/tutorials/semantic_similarity_with_tf_hub_universal_encoder">Universal Sentence Encoder</a> (USE). We also explored other encoders (e.g., <a href="https://huggingface.co/docs/transformers/en/model_doc/bert">BERT</a> encoder) in this iteration and did not observe significant differences based on offline evaluation (recall@k). We fine-tuned the pre-trained encoder while training additional MLPs on top for further specialization. On the product side, we concatenated embeddings derived from detailed product information (e.g., product name, description, brand names, taxonomies etc.), enhancing the representation of each product.</p><p>For the vanilla v0 model, we defined positive query-product pairs based on engagement history, such as add-to-cart actions, and utilized <a href="https://towardsdatascience.com/two-tower-networks-and-negative-sampling-in-recommender-systems-fdc88411601b">negative sampling</a> with cross-entropy loss for training.</p><p>To capture the popularity and relevance of both queries and products based on past engagement histories, we incorporated their respective IDs directly into the model. This integration helps to tailor the search results more closely to user interests and behaviors. The embeddings for query and product IDs were randomly initialized. This approach allows these embeddings to adapt during training, optimizing their contribution to the model’s overall performance.</p><figure><img alt="Illustration: Architecture of deep-text v0 model." src="https://cdn-images-1.medium.com/max/1024/0*d92EZ_GKjaK3SQ8z" /><figcaption><em>The architecture of deep-text v0 model.</em></figcaption></figure><h4>Multimodal Embedding (MME)</h4><p>Recognizing the value of integrating text and image data in search queries, we next adopted a multimodal pre-training framework to develop a joint image-text embedding. This approach maps both image and text embeddings to a common latent space, allowing for seamless integration into our ranking systems. We selected the <a href="https://github.com/openai/CLIP">Contrastive Language-Image Pretraining</a> (CLIP) model as our base due to its effectiveness in learning underlying linguistic and visual concepts from vast amounts of high-quality data. While CLIP is not the latest in multimodal learning, its widespread adoption and straightforward structure make it ideally suited for adaptation to various applications at Faire.</p><p>By leveraging millions of training instances, CLIP facilitates the transfer of learned concepts to our specific applications, enhancing our ability to accurately interpret and connect search queries with relevant images and text.</p><p>Unlike our initial deep text version 0, we adopted a content-based training approach for this model, eschewing reliance on query-product engagement data such as add-to-cart interactions. Instead, we used textual information from the product, such as the product name, on the query side, and the product image on the product side. This strategy enables the model to absorb and integrate the essential content information at Faire, aligning text and image data within the same embedding space, thereby improving the relevance and accuracy of our search results.</p><figure><img alt="Illustration: Architecture of the multimodal embedding model." src="https://cdn-images-1.medium.com/max/729/0*psXrp7UpaeJS2qaX" /><figcaption><em>The architecture of the multimodal embedding model.</em></figcaption></figure><h4>Deep Text V1</h4><p>The demonstrated success of deep learning (DL) based text encoders and multimodal representations had prompted continued investment into two-tower semantic retrieval. The Deep Text V1 integrated multimodal embeddings with sophisticated 100 million parameter transformer encoders. These encoders were finely tuned end-to-end on search logs, enabling a more nuanced capture of user preferences.</p><p>The training of the Deep Text V1 model followed a similar methodology to its predecessor, Deep Text V0, where it utilized query-product engagement signals such as add-to-cart actions as positive instances. The learning objective was structured in a way where the model discriminated between these positive instances and in-batch negative samples.</p><figure><img alt="Illustration: Architecture of Deep Text V1." src="https://cdn-images-1.medium.com/max/1024/0*qpxDIbBd0oB3FMh1" /><figcaption><em>The architecture of Deep Text V1 model where we incorporate both text and image embedding.</em></figcaption></figure><h3>Serving the model</h3><p>Serving an embedding-based retrieval model online is the culminating step in deploying a semantic search system. This entails using the model to fetch the most relevant search results in response to user queries, effectively in real time. To serve the model, many opt for open-source tools that use approximate nearest neighbor (ANN) techniques, such as <a href="https://github.com/facebookresearch/faiss">Faiss</a> or <a href="https://github.com/google-research/google-research/tree/master/scann">ScaNN</a>.</p><p>In the next two sections, we’ll share a cache-based solution that provides initial embedding-based retrieval capabilities to the users. Subsequently, we’ll outline a real-time solution designed to achieve comprehensive coverage.</p><h3>Cache-based solution</h3><p>At Faire, for our initial deployment, we adopted a more streamlined approach centered around a cache-based solution. This decision was strategic, owing to:</p><ul><li><strong>Simplicity</strong>: Utilizing a key-value (KV) store is straightforward and doesn’t require complex infrastructure.</li><li><strong>Query coverage</strong>: Leveraging a cache of historical queries, we could efficiently cover a significant portion of user searches without immediate computation.</li><li><strong>Evaluation period</strong>: This method provided us with a valuable evaluation phase to ascertain the embedding-based retrieval model’s long-term worth before committing resources to develop a comprehensive ANN serving system.</li></ul><p>This strategy allowed us to verify the efficacy of embedding-based retrieval while keeping system complexity and initial costs in check.</p><p>In exploring the realm of embedding-based retrieval, our goal was to determine its value proposition in comparison to traditional keyword-matching methods. To do this effectively without committing extensive resources, we employed a Minimum Viable Product (MVP) strategy. This approach allowed us to test the waters of this new retrieval method and gather data on its impact with minimal infrastructure overhaul.</p><h4>Caching mechanism</h4><p>Our method involved a calculated approach to cache optimization, focusing on:</p><ul><li><strong>Historical query analysis</strong>: We analyzed queries from the past six months to ensure we covered the spectrum of user searches. This historical insight anticipated covering approximately 75% of future queries.</li><li><strong>Offline indexing</strong>: Daily offline indexing was performed for these queries, ensuring that our cache was up-to-date and reflective of our users’ search behavior.</li><li><strong>DynamoDB storage</strong>: The top product results for each query were stored in DynamoDB. For instance, for a frequently searched term like “candle,” we would store the top products (e.g., p1, p2, p3) associated with it.</li><li><strong>ES for filtering &amp; hydration</strong>: Elasticsearch (ES) is utilized for filtering and enriching search results, a process often referred to as “hydration.” After consuming the initial retrieval product tokens from DynamoDB, we will filter the results based on the tokens and enrich the product metadata like product name, price and availability. The enriched information is useful for subsequent processing steps in the search stack.</li></ul><figure><img alt="Illustration: Model serving flow for the cache-based solution" src="https://cdn-images-1.medium.com/max/1024/0*_H267MLVA7g-WMAa" /><figcaption>An overview on how we serve the model with a key-value (KV) store by leveraging the historical queries and cache the results for online serving.</figcaption></figure><h4>Serving blended results</h4><p>When serving search results in real-time, our system checks the cache for the query. If present, it blends the cached embedding-based retrieval results with those from the keyword-matching engine. This strategy ensures quick response times and relevant, comprehensive search results for our users.</p><h3>Achieving full coverage real-time serving</h3><p>Following the demonstration of embedding-based retrieval’s effectiveness through successful online A/B testing experiments, our team united to develop a solution for real-time Approximate Nearest Neighbor (ANN) searching that extends beyond the caching-based approach, ensuring coverage for 100% of queries.</p><p>One of the key elements in our real-time serving strategy is prefiltering. This technique allows us to provide highly relevant search results by applying geographical or other filters at the time of query execution. For example, when a user searches for “sunglasses in France” we apply a “geo::France” filter during the ANN process. This approach is more efficient than post-filtering, where global results are retrieved and then filtered, potentially resulting in no relevant products.</p><p>With the advent of Elasticsearch 8, which supports prefiltering for ANN, we decided to upgrade our system given we were operating on Elasticsearch for keyword-matching. This upgrade was instrumental in enabling real-time serving, powering our embedding-based retrieval system with improved performance and accuracy.</p><p>Another key element is to enable real-time inference on query encoding. We have implemented real-time inference for encoding unseen queries using a <a href="https://docs.aws.amazon.com/sagemaker/latest/dg/deploy-model.html">Sagemaker-backed</a> service. This process generates query embeddings on the fly, which are then used to retrieve corresponding products from our index.</p><h3>Conclusion</h3><p>The adoption of embedding-based retrieval has been a watershed moment for our retailer experience, contributing to a significant uplift in search conversion and customer success on Faire.</p><p>Due to the limited space of this post, <strong><em>we will talk about how we incorporate personalization signals as part of the semantic retrieval by leveraging graph learning in future blog posts</em></strong>. Stay tuned for more updates about how we’re improving search at Faire!</p><p><em>See past articles on </em><a href="https://craft.faire.com/fine-tuning-llama3-to-measure-semantic-relevance-in-search-86a7b13c24ea"><em>Large Language Models (LLMs) tuning</em></a><em> and </em><a href="https://craft.faire.com/how-we-use-engagement-based-embeddings-to-improve-search-and-recommendation-on-faire-912277de4e6d"><em>embeddings</em></a><em> to learn more about how search works at Faire.</em></p><p><em>Special thanks to our talented team of scientists, engineers, and managers for their exceptional contributions and support: </em><a href="https://www.linkedin.com/in/qinyuwang/"><em>Qinyu Wang</em></a><em>, </em><a href="https://www.linkedin.com/in/sam-kenny/"><em>Sam Kenny</em></a><em>, </em><a href="https://www.linkedin.com/in/jeffmooooo/"><em>Jeff Mo</em></a><em>, </em><a href="https://www.linkedin.com/in/wei-jiang-16891480/"><em>Wei Jiang</em></a><em>, </em><a href="https://www.linkedin.com/in/ehacke/"><em>Eric Hack</em></a><em>, </em><a href="https://www.linkedin.com/in/boning1996/"><em>Bo Ning Wang</em></a><em>, </em><a href="https://www.linkedin.com/in/eason6wang/"><em>Eason Wang</em></a><em>, </em><a href="https://www.linkedin.com/in/xiaomeng-hu-381a78170/"><em>Xiaomeng Hu</em></a><em>, among others.</em></p><p>If you want to join a world-class Data Team working on innovative challenges to help entrepreneurs around the world chase their dreams — join us! <a href="http://www.faire.com/careers">www.faire.com/careers</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2aa44f969994" width="1" height="1" alt=""><hr><p><a href="https://craft.faire.com/embedding-based-retrieval-our-journey-and-learnings-around-semantic-search-at-faire-2aa44f969994">Embedding-Based Retrieval: Our Journey and Learnings around Semantic Search at Faire</a> was originally published in <a href="https://craft.faire.com/">The Craft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>