Stop Showing Irrelevant Results: Build Truly Personalized Search

Search is often a user's first interaction with your platform, but traditional keyword search delivers the same results to everyone, ignoring user preferences and intent. Building a truly personalized search experience typically requires complex infrastructure, from indexing and data pipelines to ML models and real-time ranking systems. Shaped radically simplifies this by combining fast keyword retrieval with AI-powered, user-specific ranking in a single platform. By using the same models and data that power recommendations, Shaped lets teams deliver highly personalized search results, without the engineering overhead.

Search: The Gateway to Discovery (If Done Right)

Search bars are often the first place users turn to find what they need, whether it's a specific product on an e-commerce site, an article on a news site, or a video on a streaming service. A good search experience feels effortless, quickly connecting users with relevant results. However, traditional keyword search often falls short. It treats every user the same, relying solely on matching terms in a query to terms in item descriptions. This "one-size-fits-all" approach ignores valuable context about the individual user's preferences, past behavior, and overall intent, frequently leading to generic, irrelevant, or overwhelming results.

Imagine two users searching for "python" on a technical learning platform. One is a data science beginner interested in introductory courses, while the other is an experienced web developer looking for advanced Django frameworks. Standard keyword search might show them the exact same results, forcing both to sift through irrelevant content. Personalized search, on the other hand, understands the individual behind the query. It leverages user history and preferences alongside the search terms to deliver results tailored specifically to each person, dramatically improving relevance, engagement, and task completion. Building this sophisticated capability from scratch, however, is a significant engineering undertaking. 

The Standard Approach: Engineering Personalized Search

Creating a search experience that intelligently blends keyword relevance with user personalization requires building and integrating multiple complex systems:

Step 1: Implementing a Foundational Keyword Search Engine

First, you need a robust system just to handle basic text matching and retrieval.

  • Choose & Deploy Search Tech: Select and set up a search engine like Elasticsearch, OpenSearch, Solr, or utilize a cloud service. This involves defining schemas, indexing item/content data (titles, descriptions, tags, etc.).
  • Configure Text Analysis & Ranking: Define how text is processed (tokenization, stemming) and implement standard relevance scoring algorithms like BM25 or TF-IDF to rank results based on keyword matches.
  • Build Indexing Pipelines: Create reliable pipelines to keep the search index up-to-date as your item catalog changes.

The Challenge: Setting up, managing, and scaling a performant search index requires specialized expertise and ongoing operational effort, and this only covers keyword relevance.

Step 2: Gathering User Interaction Data in Search Context

To personalize, you need data linking user behavior specifically to their search activities.

  • Identify & Integrate Data Sources: Collect search queries, result clicks, add-to-carts from search, purchases following search, session information, along with general user interaction data (views, purchases) and item metadata.
  • Build Contextual Data Pipelines: Requires robust pipelines to ingest this data, accurately link interactions back to specific search queries and sessions, and join it with user/item information.

The Challenge: Reliably capturing the context of search behavior (which query led to which click/conversion) and integrating it with broader user profiles is non-trivial.

Step 3: Modeling User Preference and Query Intent

This is the core machine learning challenge: understanding what a user is likely interested in, given their search query and their history.

  • Algorithm Selection & Training: Develop ML models (e.g., using embeddings, collaborative filtering, sequence models, or learning-to-rank techniques) that learn user affinities and can predict item relevance based on both the query terms and user features.
  • Feature Engineering: Create features that capture user preferences, item popularity, query characteristics, and the interaction between them.
  • Training Infrastructure & MLOps: Requires significant compute resources, ML frameworks (like TensorFlow, PyTorch), experiment tracking, versioning, and automated retraining pipelines.

The Challenge: Building models that effectively combine textual query signals with behavioral user signals is complex, requiring deep ML expertise and substantial infrastructure.

Step 4: Real-Time Blending of Keyword and Personalization Scores

When a user performs a search, the system must dynamically combine the two relevance signals.

  • Candidate Generation: Fetch initial results from the keyword search engine (Step 1) based on the text query.
  • Personalization Scoring: For each candidate item, get a personalization score from the ML model (Step 3) based on the user's profile and potentially the query context.
  • Score Blending: Implement logic to combine the keyword relevance score (e.g., BM25) and the personalization score into a final ranking score for each item. This often involves tuning weights and potentially complex formulas.
  • Sorting & Serving: Sort the candidate items based on the blended score and return the results to the user with low latency.

The Challenge: Performing candidate generation, ML inference, and score blending in real-time for every search query is computationally expensive and latency-sensitive, requiring highly optimized services.

Step 5: Managing Complex Infrastructure

You now have multiple complex systems to operate and maintain.

  • Search Index Cluster: Needs monitoring, scaling, updates.
  • ML Model Serving Infrastructure: Needs resources, monitoring, scaling for low-latency inference.
  • Data Pipelines: Require ongoing maintenance and monitoring.
  • Blending Service: Another component to build, deploy, and manage.

The Challenge: High operational overhead managing disparate systems, ensuring they work together reliably and scale effectively.

Step 6: Monitoring, A/B Testing, and Iteration

Continuously improving the personalized search experience.

  • Key Metrics: Track search click-through rate (CTR), conversion rate from search, zero-result rate, average rank of clicked items, latency.
  • A/B Testing Framework: Essential for comparing different personalization models, blending strategies, or keyword ranking tunings against baseline non-personalized search.
  • Analysis & Refinement: Ongoing analysis to understand performance drivers and iterate on models and blending logic.

The Challenge: Requires sophisticated analytics and experimentation infrastructure dedicated to search performance.

The Shaped Approach: Unified, Personalized Search with rank + text_query

Building personalized search from the ground up involves stitching together search engines, ML models, and complex real-time services. Shaped simplifies this dramatically by providing both high-performance keyword search and deeply personalized search ranking within a single, AI-native platform.

Shaped leverages its core personalization engine, trained on user interactions and item metadata, and applies it directly to search ranking using the rank endpoint combined with the text_query parameter.

How Shaped Streamlines Personalized Search:

  • Data Integration: Easily connect your user interaction data and item metadata using Shaped's connectors. The same data used for recommendations powers search personalization.
  • High-Performance Keyword Search (retrieve): Shaped offers a dedicated retrieve endpoint powered by Tantivy (a fast Rust-based search library using BM25 scoring) for efficient, standard keyword search when needed.
  • Automated Personalization Modeling: Shaped automatically trains state-of-the-art models (like Transformers) that learn deep user and item representations based on behavior. These models inherently understand user affinities.
  • Unified Personalized Ranking (rank with text_query):
    1. Your application sends the user_id and the text_query to Shaped's rank API.
    2. Shaped internally performs efficient candidate retrieval based on the text_query (leveraging its performant index).
    3. It then uses the trained personalization model to re-rank these candidates based both on keyword relevance and the specific user's learned preferences.
    4. Shaped returns a single list of items, optimally sorted according to this blend of query relevance and personalization.
  • Managed Infrastructure & MLOps: Shaped handles the underlying search index, model training, low-latency model serving, scaling, and retraining, removing significant operational burden.
  • Unified Platform: Manage recommendations and search through the same platform, using the same models and data, simplifying your overall architecture.

Implementing Search with Shaped

Let's illustrate how to use Shaped for both standard keyword and personalized search.

Goal: Implement search functionality, offering both basic keyword matching and a personalized experience.

1. Ensure Data is Connected: Assume user_interactions and item_metadata (with searchable text fields like title, description) are connected to Shaped.

2. Define Your Shaped Model (YAML): A standard model definition works. Ensure text fields intended for search are included as item features. The same model can power recommendations and personalized search.

search_personalization_model.yaml

model:
  name: "discovery_model" # Can be used for recs and search

connectors:
  - type: "Dataset"
    name: "user_interactions"
    id: "interactions"

  - type: "Dataset"
    name: "item_metadata" # Ensure relevant text fields are included
    id: "items"

fetch:
  events: |
    SELECT user_id, item_id, timestamp AS created_at, event_type FROM interactions

  items: |
    SELECT
      item_id,
      title,        # Searchable field
      description, # Searchable field
      category,
      image_url,
      product_url
    FROM items

3. Create the Model:

create_search_model.sh
shaped create-model --file search_personalization_model.yaml

4. Monitor Training: Wait for the model discovery_model to become ACTIVE.

view_discovery_model.sh
shaped view-model --model-name discovery_model

5. Fetch Search Results (Application Backend Logic):

  • Option A: Standard Keyword Search (using retrieve) Use this for non-personalized keyword matching.
search_retrieve_example.py

1 from shaped import Shaped
2 import os
3 
4 api_key = os.environ.get("SHAPED_API_KEY")
5 shaped_client = Shaped(api_key)
6 
7 response = shaped_client.retrieve(
8     model_name='discovery_model',
9     text_query="machine learning basics",
10     limit=20,
11     return_metadata=True
12 )
13 
14 keyword_results = response.metadata
15 query = "machine learning basics"
16 print(f"Found {len(keyword_results)} keyword results for '{query}'")
  • Option B: Personalized Search (using rank + text_query) Use this to get results ranked by both keyword relevance and user preference.
search_rank_example.py

1 from shaped import Shaped
2 import os
3 
4 api_key = os.environ.get("SHAPED_API_KEY")
5 shaped_client = Shaped(api_key)
6 
7 response = shaped_client.rank(
8     model_name='discovery_model',
9     text_query="machine learning basics",
10     user_id="USER_123",  # Add user ID for personalization
11     limit=20,
12     return_metadata=True
13 )
14 
15 keyword_results = response.metadata
16 query = "machine learning basics"
17 print(f"Found {len(keyword_results)} keyword results for '{query}'")

Conclusion: Deliver Search That Truly Understands Users

Standard keyword search often leaves users frustrated, forcing them to sift through irrelevant results. Building a truly personalized search experience traditionally requires integrating and managing complex search indexing, machine learning, and real-time serving systems.

Shaped offers a radically simpler, unified approach. By combining high-performance keyword retrieval (retrieve) with powerful, AI-driven personalized ranking (rank with text_query), Shaped allows you to deliver search results that are not only relevant to the query but also deeply tailored to each individual user's preferences and history. Leverage the same models and data that power your recommendations to create a seamless, intelligent discovery experience across your entire platform, boosting engagement and user satisfaction.

Ready to transform your search from a simple lookup tool into a personalized discovery engine?

Request a demo of Shaped today to see it in action with your specific use case. Or, start exploring immediately with our free trial sandbox.

Get up and running with one engineer in one sprint

Guaranteed lift within your first 30 days or your money back

100M+
Users and items
1000+
Queries per second
1B+
Requests

Related Posts

Tullie Murrell
 | 
April 25, 2025

Precision@K: Measuring What Matters at the Top of Your Rankings

Tullie Murrell
 | 
May 23, 2025

Bridging Worlds: Training Language Models on User Behavior for Smarter Recommendations

Tullie Murrell
 | 
April 22, 2025

One Embedding to Rule Them All