Skip to content
AnuragAnalytics
Go back

The Zero-Result Search Goldmine: Unlocking Crores in Lost Demand for Just ₹40 in AI Costs

4 min read

Your buyers are telling you exactly what to stock next. You are just not listening to the right signal.

Most e-commerce and quick-commerce teams look at their best-sellers and ask Merchandising to source adjacent products. Top-tier analytics teams don’t just look at what people bought—they look at what high-intent buyers tried to buy and failed to find.

The Zero-Result Search log isn’t a dead end. It is your most honest unmet-demand signal.

Over 8 years of scaling analytics across Amazon, PhonePe, and Ola, one pattern separates junior candidates from senior problem-solvers in analytics interviews: how you bridge messy, massive behavioral data with business action without blowing up compute or budget. Welcome to Episode 13 of the hardest interview questions at top-tier firms.


The Problem: 50 Million Unstructured Searches a Month

Suppose an interviewer asks:

We logged 50 million zero-result searches on our marketplace this month. How do you turn those logs into an actionable procurement list for our Merchandising team?

The Rookie Mistake #1: Brute-Force SQL

I’ll just GROUP BY all zero-result search terms this month and sort by COUNT(*).

At Amazon-scale, this fails on two fronts:

  1. Cluster Meltdown (OOM / Spill): Grouping 50 million raw, high-cardinality text strings—loaded with bots, keyboard smashes (asdfghjk), emojis, and 400-character copy-pastes—burns memory and triggers out-of-memory (OOM) spills.
  2. Long-Tail Fragmentation: Even if the query finishes, "cat allergic food", "grain-free kitten meals", and "hypo cat kibble" show up as completely separate rows. Your top-20 table gets filled with generic typos instead of real product gaps.

The Rookie Mistake #2: “Just Send It All to an LLM”

Let’s feed the 50 million rows into an LLM to categorize every search!

You just bankrupted your department’s API budget for the quarter—and introduced massive latency—to classify bot traffic and gibberish.

The fix isn’t a bigger cluster or a more expensive LLM. The fix is smarter SQL upstream.

ApproachRaw Volume Sent to AICompute / CostOutcome
Naive GROUP BYN/AHeavy cluster shuffle / OOM riskFragmented typos; misses true product intent
Raw LLM Classification50,000,000 rowsMassive API bill & slow batch jobsMostly spent on bots, noise, and non-buyers
SQL + Local HDBSCAN + Lean LLM300 micro-prompts< 5 sec SQL + ₹40 API costClean, ranked procurement list from active buyers

How World-Class Analysts Solve It: The 4-Stage Compression Pipeline

Instead of asking AI to clean raw logs, use pure SQL to radically compress the data before AI ever touches it.

4-Stage Pipeline: 50M Failed Searches to Crores in Demand for ₹40 AI Cost


Stage 1: Cut the Noise (INNER JOIN to Active Buyers)

Not every failed search carries equal commercial value. A significant share of raw search traffic comes from web scrapers, logged-out bots, accidental taps, and non-converting window-shoppers.

Before touching text parsing, INNER JOIN your zero-result search log to your active buyer base—users who completed at least one purchase in the last 60 days:

  • You eliminate ~80% of raw log volume in a single join.
  • Every remaining row represents unmet demand from a proven buyer—someone with a saved address, a working payment method, and established trust in your platform.

Stage 2: Sample Smart (Regex Cleanup + TABLESAMPLE)

Next, remove obvious bots, fat-fingered single-character taps, and pasted URLs, normalize the text, and take a block-level sample with TABLESAMPLE SYSTEM (5) (supported in engines like Trino/Presto, Postgres, and Snowflake/BigQuery equivalents):

WITH active_buyers AS (
    -- Proven buyers who completed an order in the last 60 days
    SELECT DISTINCT user_id
    FROM analytics.fact_orders
    WHERE order_status = 'COMPLETED'
      AND order_ts >= CURRENT_DATE - INTERVAL '60' DAY
),

cleaned_zero_searches AS (
    -- Block-level 5% sample AFTER filtering to active buyers & valid text bounds
    SELECT
        TRIM(REGEXP_REPLACE(LOWER(s.search_term), '[^a-z0-9 ]', '')) AS clean_term,
        s.user_id,
        s.search_ts
    FROM analytics.fact_search_logs TABLESAMPLE SYSTEM (5) s
    INNER JOIN active_buyers b
        ON s.user_id = b.user_id
    WHERE s.result_count = 0
      AND s.search_ts >= CURRENT_DATE - INTERVAL '30' DAY
      AND LENGTH(TRIM(s.search_term)) BETWEEN 4 AND 40
)

SELECT
    clean_term,
    COUNT(*) AS sampled_searches,
    COUNT(DISTINCT user_id) AS sampled_unique_buyers
FROM cleaned_zero_searches
WHERE LENGTH(clean_term) >= 4
GROUP BY 1
HAVING COUNT(DISTINCT user_id) >= 3   -- Drop one-off personal typos
ORDER BY 2 DESC
LIMIT 5000;

Look at what just happened mathematically:

  1. Joining to active_buyers cut 50M rows down to ~10M high-intent rows.
  2. TABLESAMPLE SYSTEM (5) + length/regex filters reduced the scan to ~200,000 clean rows, grouping in under 5 seconds.
  3. Filtering HAVING COUNT(DISTINCT user_id) >= 3 and taking the top 5,000 unique normalized search terms captures the overwhelming majority of repeatable buyer demand while discarding one-off noise.

(Note: When reporting total monthly demand later, remember to scale sampled counts by 20×, or run a fast exact match/join on the final 300 clustered patterns against the 60-day buyer slice.)


Stage 3: Cluster Locally (Embeddings + HDBSCAN = $0 API Cost)

Now you have ~5,000 clean search strings—and you still haven’t called a paid cloud LLM.

Why? Because grouping "cat allergic food", "grain-free kitten meals", and "hypoallergenic cat kibble" into one bucket is a semantic similarity problem, not a generative reasoning problem. You can solve it completely locally on a laptop or standard worker node:

  1. Encode the 5,000 terms into vectors using a lightweight local embedding model (e.g., all-MiniLM-L6-v2).
  2. Run HDBSCAN (a density-based clustering algorithm that automatically discovers the number of clusters and leaves unclusterable outliers in -1).
import pandas as pd
from sentence_transformers import SentenceTransformer
import hdbscan

# 1. Load the ~5,000 SQL-compressed terms
df = pd.read_csv("top_5000_zero_searches.csv")

# 2. Generate embeddings locally ($0 API cost)
model = SentenceTransformer("all-MiniLM-L6-v2")
embeddings = model.encode(df["clean_term"].tolist(), normalize_embeddings=True)

# 3. Cluster synonymous buyer intent without pre-specifying K
clusterer = hdbscan.HDBSCAN(min_cluster_size=4, metric="euclidean")
df["cluster_id"] = clusterer.fit_predict(embeddings)

# Keep dense clusters (exclude -1 noise)
clustered = df[df["cluster_id"] != -1]
n_clusters = clustered["cluster_id"].nunique()
print(f"Discovered {n_clusters} distinct product intent clusters.")

In seconds, those 5,000 fragmented queries collapse into ~300 clean intent clusters—still at zero token cost.


Stage 4: Prompt Lean (300 Micro-Prompts = ₹40 Total Cost)

Only now do you use an LLM—and only for what LLMs are uniquely great at: human-readable naming.

For each of the ~300 clusters, take just the top 5 most frequent search strings and send a tiny micro-prompt:

These user searches returned 0 results on an e-commerce store: ['cat allergic food', 'grain-free kitten meals', 'hypo cat kibble', 'sensitive stomach cat food', 'vet allergy cat dry food']. Give this product category a 3-word standardized name.

  • Volume: 300 micro-prompts × ~60 tokens each = ~18,000 tokens total.
  • Monthly AI Cost: Roughly ₹40 (less than a cup of coffee).

Compare that to the rookie pipeline: bankrupting the department vs. ₹40.


The “Aha!” Insight: Turn Clusters Into a Signed Purchase Order

Never stop at a list of cluster names. Join those 300 standardized category names back to your SQL search volumes and buyer counts.

From Raw Failed Searches to Prioritized Merchandising Procurement Signal

Instead of handing Merchandising a raw CSV dump of messy search strings, you hand them a prioritized procurement brief backed by proven buyer intent:

Standardized CategorySampled / Scaled Monthly SearchesProven 60d BuyersRepresentative QueriesMerchandising Action
Hypoallergenic Cat Food142,00068,400cat allergic food, hypo cat kibbleOnboard vet-approved SKU line immediately
Sugar-Free Electrolyte Powder96,50051,200keto hydration mix, zero sugar orsSource 3 top D2C brands
Type-C Magnetic Charger81,20044,900magsafe usb c tip, magnetic pd cableAdd accessories vendor

Look at the difference in how that lands in a leadership review:

We saw 142,000 failed searches for Hypoallergenic Cat Food this month—exclusively from active buyers who already ordered in the last 60 days.

That isn’t an analytics slide. That is a purchase order waiting to be signed.


Key Takeaways for Your Next Analytics Interview

  1. Always compress upstream in SQL before applying ML/AI: Joining to active buyers (INNER JOIN) and sampling smart (TABLESAMPLE + length/regex filters) turns an unmanageable 50M-row problem into a 5-second query.
  2. Use the right tool for each step: SQL for filtering and aggregation, local embeddings + HDBSCAN for semantic grouping, and an LLM only to name the final 300 clusters.
  3. Anchor insights to commercial intent: Filtering to proven buyers transforms noisy search logs into high-confidence revenue opportunities.

A junior analyst studies what sold. A world-class analyst monetizes what didn’t.



Previous Post
When Lenskart's Sales Drop 12% MoM: A Senior Analyst's Playbook