AI-Personalized Search in E-Commerce: Ranking and Conversion

We design and deploy artificial intelligence systems: from prototype to production-ready solutions. Our team combines expertise in machine learning, data engineering and MLOps to make AI work not in the lab, but in real business.
Showing 1 of 1All 1564 services
AI-Personalized Search in E-Commerce: Ranking and Conversion
Medium
~1-2 weeks
Frequently Asked Questions

AI Development Areas

AI Solution Development Stages

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1347
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1247
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    948
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1183
  • image_logo-advance_0.webp
    B2B Advance company logo design
    642
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    921

Personalization of Search Ranking in E-Commerce

Without personalization, a search engine shows the same results to all users. ML ranking considers browsing history, purchases, returns, and session context—reordering results individually. For example, one of our clients, a marketplace with 500,000 products, after implementing personalized ranking achieved a 15% increase in CTR and a 12% increase in average order value. The conversion gain from search ranges from 8–15%. Our stack: PyTorch, LightGBM, Hugging Face, Anthropic for LLMs. We use LambdaMART with custom features—a proven algorithm for ranking tasks. We have over 5 years of experience and have completed more than 20 projects for e-commerce, including marketplaces with product assortments from 10,000 to 1 million units.

How Personalized Ranking Works

The LambdaMART algorithm (LightGBM ranker) is trained on implicit feedback: clicks, purchases, view time. The feature vector includes five groups of features: relevance (BM25, exact match), product quality (rating, reviews, stock), business metrics (margin, promo, sales velocity), personalization (user browsing history, CTR in category), and session context (number of queries, device, time of day).

import numpy as np
import pandas as pd
from sklearn.ensemble import GradientBoostingClassifier
import lightgbm as lgb

class SearchPersonalizationEngine:
    """
    LambdaMART (LightGBM ranker) for personalized search.
    Trained on implicit feedback: clicks, purchases, view time.
    """

    def __init__(self):
        self.ranker = lgb.LGBMRanker(
            objective='lambdarank',
            n_estimators=300,
            learning_rate=0.05,
            num_leaves=63,
            min_child_samples=20,
            random_state=42
        )
        self.feature_names = []

    def build_features(self, query: str, products: pd.DataFrame,
                        user_history: dict, session_context: dict) -> pd.DataFrame:
        """Build feature vector for (query, product) pair"""
        features = []

        for _, product in products.iterrows():
            feat = {}

            # === Relevance features ===
            feat['bm25_score'] = product.get('search_score', 0)
            feat['title_match'] = int(all(
                word.lower() in product.get('title', '').lower()
                for word in query.split()
            ))
            feat['exact_match'] = int(query.lower() == product.get('title', '').lower())

            # === Product quality features ===
            feat['rating'] = product.get('rating', 3.0)
            feat['reviews_count'] = np.log1p(product.get('reviews_count', 0))
            feat['in_stock'] = int(product.get('in_stock', True))
            feat['days_since_added'] = product.get('days_since_added', 365)
            feat['photo_count'] = min(product.get('photo_count', 1), 10)

            # === Business features ===
            feat['margin_score'] = product.get('margin_percentile', 0.5)
            feat['is_promoted'] = int(product.get('is_promoted', False))
            feat['sales_velocity_7d'] = np.log1p(product.get('sales_7d', 0))

            # === Personalization features ===
            sku = product.get('sku', '')
            category = product.get('category', '')
            brand = product.get('brand', '')

            feat['user_viewed_sku'] = int(sku in user_history.get('viewed_skus', set()))
            feat['user_viewed_category'] = int(category in user_history.get('viewed_categories', set()))
            feat['user_purchased_brand'] = int(brand in user_history.get('purchased_brands', set()))
            feat['user_purchase_count_category'] = user_history.get('category_purchase_counts', {}).get(category, 0)

            feat['user_category_ctr'] = user_history.get('category_ctrs', {}).get(category, 0.05)

            user_avg_price = user_history.get('avg_order_value', 0)
            product_price = product.get('price', 0)
            if user_avg_price > 0:
                feat['price_ratio'] = product_price / user_avg_price
            else:
                feat['price_ratio'] = 1.0

            # === Session context ===
            feat['session_query_count'] = session_context.get('query_count', 1)
            feat['session_has_cart'] = int(session_context.get('has_cart', False))
            feat['device_mobile'] = int(session_context.get('device', 'desktop') == 'mobile')
            feat['hour_of_day'] = session_context.get('hour', 12)

            feat['sku'] = sku
            features.append(feat)

        df = pd.DataFrame(features)
        self.feature_names = [c for c in df.columns if c != 'sku']
        return df

    def train(self, training_data: pd.DataFrame):
        feature_cols = [c for c in training_data.columns
                        if c not in ['query_id', 'sku', 'relevance_label']]
        X = training_data[feature_cols]
        y = training_data['relevance_label']
        groups = training_data.groupby('query_id').size().values
        self.ranker.fit(X, y, group=groups)

    def rank(self, query: str, products: pd.DataFrame,
              user_history: dict, session_context: dict) -> pd.DataFrame:
        features_df = self.build_features(query, products, user_history, session_context)
        X = features_df[self.feature_names]
        scores = self.ranker.predict(X)
        products = products.copy()
        products['rank_score'] = scores
        return products.sort_values('rank_score', ascending=False)

Why Consider Behavioral Signals?

Users with different histories see the same results—that's lost sales. For example, if a user frequently buys electronics, they should see laptops and smartphones higher than stationery. Without behavioral signals, the model cannot account for such preferences. We implemented behavioral features: category views, brand purchases, category CTR, average order value. This gave a conversion boost of 8–12% in our clients' projects.

Comparison of Ranking Approaches

Approach Personalization Consideration Performance Implementation Complexity
TF-IDF / BM25 No High Low
Learning to Rank (LambdaMART) Yes Medium Medium
Neural Rankers (Transformers) Yes Low (at large scale) High

LambdaMART offers the optimal balance between personalization quality and maintenance costs. Neural rankers require GPUs and large datasets, while BM25 does not account for individual preferences.

Metrics Before and After Implementation

Metric Before After
Search CTR 3.2% 3.7%
Conversion Rate 2.1% 2.4%
NDCG@5 0.62 0.71
Example LightGBM ranker configuration
lgb_params = {
    'objective': 'lambdarank',
    'boosting_type': 'gbdt',
    'metric': 'ndcg',
    'num_leaves': 63,
    'learning_rate': 0.05,
    'feature_fraction': 0.8,
    'bagging_fraction': 0.8,
    'bagging_freq': 5,
    'verbose': 0,
    'random_state': 42
}

Query Understanding and Expansion

Queries often contain typos, synonyms, or ambiguity. We use LLMs (Anthropic Claude) for correction, extracting brand, category, price, and seasonality. This allows correct processing of 95% of queries without additional rules.

from anthropic import Anthropic

class QueryUnderstandingLayer:
    """Search query processing: correction, expansion, intent"""

    def __init__(self):
        self.llm = Anthropic()

    def parse_query(self, raw_query: str, catalog_categories: list[str]) -> dict:
        response = self.llm.messages.create(
            model="claude-3-5-sonnet-20241022",
            max_tokens=200,
            messages=[{
                "role": "user",
                "content": f"""Parse this e-commerce search query and return JSON.

Query: "{raw_query}"
Available categories: {catalog_categories[:20]}

Return JSON:
{{
  "corrected_query": "...",
  "intent": "informational|navigational|transactional",
  "extracted_brand": "...",
  "extracted_category": "...",
  "price_filter": {{"min": null, "max": null}},
  "color": null,
  "size": null,
  "synonyms": ["...", "..."]
}}"""
            }]
        )

        import json
        try:
            return json.loads(response.content[0].text)
        except Exception:
            return {'corrected_query': raw_query, 'intent': 'transactional', 'synonyms': []}

    def detect_seasonal_intent(self, query: str, current_month: int) -> float:
        seasonal_keywords = {
            'winter': [12, 1, 2],
            'summer': [6, 7, 8],
            'spring': [3, 4, 5],
            'autumn': [9, 10, 11]
        }
        query_lower = query.lower()
        for season, months in seasonal_keywords.items():
            if season in query_lower and current_month in months:
                return 1.2
        return 1.0

How A/B Testing Improves Ranking

Before deploying a new model, we run an A/B test: part of the traffic goes to control, part to treatment. Metrics: CTR, Conversion Rate, NDCG@5, Revenue per Search. Deterministic assignment (by user_id hash) ensures clean experimentation.

class SearchRankingExperiment:
    """A/B/n tests for ranking algorithms"""

    def __init__(self, variants: dict):
        self.variants = variants

    def assign_user(self, user_id: str) -> str:
        bucket = hash(user_id) % 100
        if bucket < 50:
            return 'control'
        return 'treatment'

    def track_metrics(self, search_logs: pd.DataFrame) -> pd.DataFrame:
        return search_logs.groupby('variant').agg(
            ctr=('clicked', 'mean'),
            conversion_rate=('purchased', 'mean'),
            avg_position_clicked=('click_position', 'mean'),
            ndcg_at_5=('ndcg_5', 'mean'),
            revenue_per_search=('revenue', 'mean')
        ).round(4)

How to Implement Personalized Ranking

The implementation process consists of the following stages:

  1. Audit of current search results and metric collection (CTR, CR, NDCG).
  2. Develop data collection schema: query logs, clicks, purchases, user history.
  3. Feature engineering: generate 50+ features (relevance, quality, business, personalization, context).
  4. Train LambdaMART model with cross-validation and hyperparameter tuning.
  5. Deploy on Kubernetes with Triton Inference Server.
  6. A/B testing: compare new model with current for 1–2 weeks.
  7. Optimization and documentation, team training.

Typical Mistakes in Implementation

  • Using relevance only without personalization—results do not change.
  • Too many features without regularization—overfitting and degradation on new data.
  • Wrong quality metric: NDCG is better suited for ranking than MSE.
  • Lack of online validation via A/B tests—offline metrics do not guarantee production success.

Personalized search is especially effective for head queries (top 20% of queries account for 80% of traffic). For tail queries, semantic search via vector index is more important than personalization. Typical metric improvement: CTR +12%, Conversion Rate +8%, Revenue per Search +10% with correct feature engineering.

Contact us to evaluate your project. We will conduct a free audit of your current search results and offer an optimal solution. Order a pilot project: model training on your data in 2 weeks.

Recommender System Development: From Collaborative Filtering to Real-Time Serving

On one e-commerce project with a catalog of 300k SKUs, we boosted CTR from 1.8% to 4.4% — a 2.4x increase. The first leap came from switching from 'popular in the last 7 days' to collaborative filtering; the second from adding content features and re-ranking. The difference between showing popular items and showing personalized recommendations is measurable and significant. Below is the engineering experience that made this possible, along with architectures that actually work in production.

Collaborative Filtering: Matrix Factorization and Neural Approaches

Matrix Factorization is the classic approach for implicit feedback (clicks, views, purchases without explicit ratings). ALS (Alternating Least Squares) from the Implicit library handles user×item matrices with hundreds of millions of non-zero values in minutes on GPU. Latent factors 64–256, regularization λ=0.01–0.1 are starting parameters. Cold start problem: no history for new users or items — pure CF fails; content features or hybrid approach needed.

Neural Collaborative Filtering (NCF) replaces the dot product with a neural network. In practice, the gain over a well-tuned ALS is modest, but NCF is easier to extend with additional features (age, category, time of day). Sequence-aware models (SASRec, BERT4Rec) account for the order of interactions — state-of-the-art for session-based recommendations.

How to Choose Recommender System Architecture?

The answer depends on data, load, and cold start requirements. Below are three main approaches with selection criteria.

Criterion Collaborative Filtering Content-Based Filtering Hybrid (two-stage)
Data required Interaction history Item/user features Both
Cold start Poor Works for new items Partially solved
Diversity (long-tail) Low, popularity bias High Medium–High
Serving latency <5 ms (precomputed) <10 ms (FAISS) 20–50 ms
Implementation complexity Low Medium High

Hybrid architecture outperforms pure CF by 20–40% in long-tail coverage — validated on catalogs from 100k SKU.

Content-Based Filtering: When Interaction History is Scarce

Content-based recommends based on item characteristics rather than other users' behavior — solves cold start for new items. Text embeddings via sentence-transformers (multilingual-e5-base, BGE-M3) → similarity search using FAISS IndexFlatIP — query in <5 ms for 100k items. Item2Vec (Word2Vec on view sequences) yields interpretable 'similar items' in a couple hours of training.

Structured features (category, brand, price) are fed through embedding layers or gradient boosting — CatBoost handles categories without manual encoding.

Why Hybrid Models Work Better?

Production systems are almost always two-level. Stage 1 (Retrieval) — fast selection of 100–500 candidates from 300k items using ALS or Two-Tower model with vector search (FAISS, Qdrant). Stage 2 (Ranking) — heavy ranker on LightGBM or neural network with cross-features, time, device, and session context. LightFM is a good starting point for medium scale without heavy infrastructure. Our practice shows: moving from single-stage to two-stage yields a 15–25% accuracy improvement with only 20–30 ms additional latency.

Real-Time Serving: Architecture Under Load

Latency SLA — 50–100 ms at thousands of requests per second. Base recommendations precomputed (batch job hourly) → Redis by user_id → <5 ms. Real-time re-ranking via Kafka for events (clicks, cart adds) → update of context features. Feature serving — Redis with TTL (views in 24 hours, last clicked item). At 10k req/s, we deploy Redis Cluster with replication.

A/B testing is the only reliable way to measure improvements. Offline metrics do not always correlate with online. Kohavi et al., 'Online Controlled Experiments at Large Scale' (KDD 2013) — a must-read for the team. Test on 5–10% of traffic, monitor CTR, conversion, revenue per session. One of our client systems after hybridization increased revenue by 18% over a month of A/B.

Recommender System Development Timeline

The stages and typical time frames are in the table below. Costs are calculated individually based on catalog scale and latency requirements.

Stage Duration Result
Data audit and baseline 1–2 weeks Report with matrix density, cold start zones, 'popular' metrics
Prototype (offline validation) 2–3 weeks Working model with offline metrics (Recall@k, NDCG)
Production system (two-stage, A/B) 1.5–2.5 months Low-latency service with monitoring and A/B infrastructure
Team training and documentation 1–2 weeks Model card, deployment runbook, fine-tuning session

What's Included in Turnkey Development

  1. Data audit — user×item matrix density (typically <0.1%), activity distribution, temporal patterns, cold start statistics.
  2. Baseline — 'popular' as a simple threshold that is often hard to beat.
  3. Iterative improvement — ALS → content features → two-stage → sequence-aware. Each step with A/B.
  4. Serving infrastructure — batch precomputation, Redis, real-time re-ranking, Grafana monitoring.
  5. Documentation — model card with metrics, deployment instructions, feature descriptions.
  6. Team training — session on interpreting results and model fine-tuning.
  7. Support — 1 month post-launch (incident fixes, pipeline tuning).

We are a team with 7+ years of experience in recommender systems, having delivered over 30 projects for e-commerce and media. We guarantee transparent A/B testing and documented metric improvements.

Want to assess the growth potential of your catalog? Contact us for a free data audit. Order recommender system development — first prototype within two weeks.

Example ALS config for implicit feedback
from implicit.als import AlternatingLeastSquares

model = AlternatingLeastSquares(
    factors=64,
    regularization=0.05,
    iterations=15,
    use_gpu=True
)
model.fit(user_item_matrix)

More about the mathematics of recommender systems — in specialized literature.