All Posts
EngineeringMarch 31, 2026

Improving Product Recommendations with Vector Search and RAG

The recommendation engine powering most e-commerce platforms today is a decade-old idea dressed in modern infrastructure. Collaborative filtering, matrix factorization, and click-stream co-occurrence models are effective in the fat middle of your catalog. They fail at the edges: new products with no purchase history, long-tail SKUs, and users with sparse behavioral signals.

The recommendation engine powering most e-commerce platforms today is a decade-old idea dressed in modern infrastructure. Collaborative filtering, matrix factorization, and click-stream co-occurrence models are effective in the fat middle of your catalog. They fail at the edges: new products with no purchase history, long-tail SKUs, and users with sparse behavioral signals.

Vector search product recommendations for e-commerce offer a fundamentally different approach. Instead of asking "what do users who bought this also buy," you ask "what is semantically similar to this product and contextually relevant to this user." The difference is not marginal; it is the gap between a 2.1% CTR and a 4.8% CTR on recommendation carousels.

The Core Problem: Why Behavioral Models Break at Scale

Collaborative filtering works because purchase patterns cluster. Customers who buy camping stoves also buy fuel canisters. The signal is strong, the model is interpretable, and the infrastructure is well-understood.

The problem surfaces when you interrogate the failure modes.

Cold start: A new product with zero purchase history gets zero recommendations and zero exposure. You are effectively hiding a portion of your catalog from discovery until it accumulates behavioral signal. For brands that launch 200 new SKUs per season, this is not a theoretical edge case.

Long-tail sparsity: Products outside your top 20 percent of SKUs have too little purchase data to generate reliable co-occurrence scores. Your recommendation engine becomes a popularity amplifier, surfacing the same top-selling items in every context and starving everything else of discovery.

Intent blindness: A user searching for "sustainable outdoor gear for a weekend trip" is expressing an intent that spans multiple categories and requires semantic understanding. A behavioral model sees product IDs and purchase counts. It cannot interpret the query; it can only pattern-match on past behavior.

These are structural limitations, not tuning problems. You cannot fix them with more data or better hyperparameters.

The Technical Foundation: Embeddings, Vector Search, and RAG

Vector search addresses these limitations by representing products as dense numerical embeddings in a high-dimensional semantic space. Products with similar meaning, context, and use case cluster together regardless of their purchase history.

The embedding is generated by passing product attributes through a pre-trained language model (or a fine-tuned domain model). A product's title, description, material specifications, category path, and user reviews all contribute to its embedding. The result is a 768 to 1,536 dimensional vector that encodes semantic meaning.

At query time, the user's intent (expressed as a search query, a browsing context, or a product page view) is embedded using the same model. Approximate nearest-neighbor (ANN) search finds the top-K most semantically similar products in milliseconds, even across catalogs with millions of SKUs.

RAG (retrieval-augmented generation) adds a generative layer on top of this retrieval foundation. Instead of just returning similar products, you retrieve a candidate set and pass it to an LLM along with user context. The LLM can then reason about relevance, surface complementary products, and generate natural language explanations for the recommendation.

The combination is powerful. Retrieval gives you scale and latency guarantees. Generation gives you contextual reasoning and explainability.

INTERNAL LINK: embedding model selection → article on choosing the right embedding model for product catalog search

Implementation Deep-Dive

Step 1: Build Your Product Embedding Pipeline

Start with your product catalog data. For each SKU, construct a text representation that concatenates the attributes most predictive of semantic similarity.

def build_product_text(product: dict) -> str:
    parts = [
        product.get("title", ""),
        product.get("description", ""),
        " ".join(product.get("tags", [])),
        product.get("category_path", ""),
        product.get("material", ""),
        product.get("use_case", ""),
    ]
    return " | ".join(p for p in parts if p)

Run this through an embedding model. For most e-commerce use cases, text-embedding-3-small from OpenAI provides a strong baseline at reasonable cost (approximately $0.02 per million tokens). For domain-specific catalogs (technical industrial products, specialty apparel), fine-tuning on your own product pairs improves retrieval precision by 15 to 25 percent.

Batch-embed your full catalog offline. At 500,000 SKUs with an average of 200 tokens per product, the initial embedding run costs roughly $2 and takes under 10 minutes.

Step 2: Index Embeddings in Your Vector Database

Upsert the embeddings into your vector database with product metadata as filterable attributes.

vectors = [
    {
        "id": product["sku"],
        "values": embedding,
        "metadata": {
            "category": product["category"],
            "price": product["price"],
            "in_stock": product["inventory"] > 0,
            "brand": product["brand"],
        }
    }
    for product, embedding in zip(products, embeddings)
]

index.upsert(vectors=vectors, namespace="products")

Keep metadata lean. Vector databases are not optimized for complex relational queries; use metadata only for the filters you will apply at query time (category, price range, availability).

Step 3: Build the Retrieval Query Layer

At recommendation time, construct a query embedding from the user's context. This context can be a search query, the product they are currently viewing, or a composite of their recent session activity.

def get_recommendations(
    context_text: str,
    filters: dict,
    top_k: int = 20,
) -> list[dict]:
    query_embedding = embed(context_text)

    results = index.query(
        vector=query_embedding,
        top_k=top_k,
        filter=filters,
        include_metadata=True,
    )

    return results["matches"]

The top_k=20 retrieves more candidates than you will display. The next step is reranking this candidate set before surfacing results to the user.

Step 4: RAG Reranking for Contextual Relevance

Pass the retrieved candidates to an LLM with the user's context for final reranking and explanation generation.

def rag_rerank(candidates: list[dict], user_context: str) -> list[dict]:
    candidate_summaries = [
        f"{i+1}. {c['metadata']['title']} (${c['metadata']['price']})"
        for i, c in enumerate(candidates)
    ]

    prompt = f"""
    User context: {user_context}

    Candidate products:
    {chr(10).join(candidate_summaries)}

    Return the top 6 most relevant product IDs as a JSON array,
    ordered by relevance. Consider complementary use cases,
    not just similarity.
    """

    response = llm.complete(prompt)
    return parse_reranked_ids(response, candidates)

This reranking step typically adds 80 to 150ms of latency. For carousels that load asynchronously, this is acceptable. For synchronous search result pages, you may need to skip LLM reranking and rely on pure ANN recall with metadata filters.

INTERNAL LINK: RAG latency optimization → article on reducing inference latency in production LLM pipelines

The Decision Framework: Where to Apply This Pattern

Not every recommendation surface benefits equally from vector search and RAG. Apply selectively based on expected lift and latency tolerance.

SurfaceApproachExpected CTR Lift
Product detail page "similar items"Vector ANN only15 to 25%
Search results fallback (zero results)Hybrid vector + keyword40 to 60%
Cart cross-sell recommendationsVector ANN + RAG rerank20 to 35%
New product launch exposureVector ANN (cold start fix)Varies
Personalized homepage carouselBehavioral + vector hybrid10 to 20%

The highest-impact use case for most catalogs is the zero-results fallback. When a user's search query returns no exact matches, a vector similarity fallback surfaces semantically relevant products instead of a dead end. This alone typically recovers 8 to 12 percent of sessions that would otherwise bounce.

Hybrid Approaches: Do Not Throw Away Behavioral Data

Vector search is not a replacement for collaborative filtering; it is a complement. The right architecture combines both signals.

Use behavioral models for high-confidence recommendations on popular products. Use vector search for cold-start products, long-tail SKUs, and intent-based query contexts. A simple ensemble that weights the two signals by item popularity gives you the best of both systems without the complexity of a fully unified model.

The teams that win at e-commerce personalization are not those with the most sophisticated single model. They are those with the most thoughtful signal routing.

What This Means for Your Business

Vector search and RAG for product recommendations are not a science project. They are a measurable conversion lever.

The cold start problem alone costs most mid-size e-commerce brands 3 to 8 percent of potential GMV from new product launches. Fixing it with vector search pays back the implementation cost within the first product cycle.

At scale, the compounding effect matters more. Better recommendations increase average order value. Higher AOV justifies larger catalog investments. A larger catalog with better discovery creates a competitive moat that is genuinely hard for competitors to replicate without the same data infrastructure.

The semantic product search capability you build for recommendations also powers your site search, your AI shopping assistant, and your SEO-driven programmatic landing pages. The retrieval layer becomes infrastructure, not a one-off feature.

INTERNAL LINK: RAG for site search → article on building semantic site search for Shopify Plus and Salesforce Commerce Cloud

How Contra Collective Bridges the Gap

At Contra Collective, we design and implement production-ready vector search and RAG systems for enterprise e-commerce teams that need measurable results, not ML research projects. We handle the embedding pipeline architecture, vector database selection, retrieval tuning, and integration with your existing Shopify Plus or Salesforce Commerce Cloud stack.

Ready to make the right call for your stack? Book a free technical audit — no sales pitch, just clarity.

Final Thoughts

Collaborative filtering is not dead; it is just incomplete. The teams pulling ahead in e-commerce personalization are the ones who recognize that behavioral signals and semantic signals answer different questions, and build retrieval architectures that use both.

Vector search product recommendations for e-commerce solve the problems that behavioral models cannot: cold start, long-tail sparsity, and intent-based query handling. The implementation is not trivial, but it is well within reach for any team with a few engineers and a clear-eyed view of the trade-offs.

Start with the zero-results fallback. Measure the lift. Then expand to cart cross-sells and new product launch exposure. The data will tell you where to go next.

[ 02 ] — Keep Reading

More from the lab.

Jun 14, 2026Engineering

Stytch vs Magic.link: Passwordless Authentication for Modern Web Apps

Passwords are a UX tax. Every password a user creates is a support ticket waiting to happen, a security incident in the making, and a checkout abandonment rate line item your e-commerce analytics will eventually surface. The industry has known this for years. Passwordless authentication, once a niche experiment, is now table stakes for consumer-facing applications that care about conversion.

Jun 12, 2026Engineering

Cognito vs Clerk: AWS Native Auth vs Developer-First Identity in 2026

AWS Cognito is one of the most widely used authentication services in the world, and one of the most frequently replaced. Its usage stats reflect the gravitational pull of the AWS ecosystem. Its replacement frequency reflects something more honest about its developer experience. Clerk built its entire company on the premise that authentication should feel like a first-party framework feature, not a cloud service you configure through a JSON policy document.

Jun 12, 2026Engineering

Shopify Plus vs Salesforce Commerce Cloud: 2026 Enterprise Platform Decision

The enterprise commerce platform market has bifurcated sharply. On one side: Salesforce Commerce Cloud, a legacy powerhouse built for complexity and customization at a price that reflects it. On the other: Shopify Plus, a platform that has spent the last four years systematically closing the enterprise feature gap while keeping total cost of ownership radically lower. The question for most brands in 2026 is no longer whether Shopify Plus is enterprise-ready. It is whether SFCC's remaining advantages justify its cost.

Ready when you are

Want to discuss this topic?

Start a Conversation