liveBook · Manning

SQL

As explained in Machine Learning System Design

A request containing terms or criteria submitted to a search engine to retrieve relevant information.

A search query is the main object handled by a search engine. Its quality affects both validation design and production data health: real user queries must be represented without allowing duplicate or leaked examples to distort evaluation. section 7.5.2 section 14.5.2

Build reliable query datasets by following these checks:

  • Represent real production queries and cover varied topics and contexts. section 7.5.2
  • Group queries by user, remove duplicates, and keep each user in only one split. section 7.5.2
  • Filter obvious garbage while retaining plausible unusual queries to avoid training-serving skew. section 14.5.2
  • Monitor query-related search stages such as candidate fetching, final ranking, and override application. section 14.5.2
def assign_bucket(user_id):
    _hash = sha1(user_id.encode()).hexdigest()
    return int(_hash, 16) % n_buckets

def assign_split(user_id):
    bucket = assign_bucket(user_id)
    if bucket < n_buckets * train_ratio:
        return 'train'
    elif bucket < n_buckets * (train_ratio + val_ratio):
        return 'val'
    else:
        return 'test'

Use deterministic user-ID hashing to assign stable training, validation, and test splits while allowing future ratio changes. section 7.5.2

How Machine Learning System Design covers it

How deep it goes
Explains dataset safeguards, filtering tradeoffs, monitoring targets, and deterministic splitting, but does not describe query syntax.
Examples
Uses duplicate queries, keyboard-generated garbage, seasonal users, emerging topics, and hashed user-ID split assignment as examples.
What it assumes
Assumes familiarity with search-engine data and dataset splits while specifying validation safeguards and monitoring concerns.
What you can do after
Diagnose query-data risks by checking leakage, duplication, filtering skew, latency, and production distribution changes.
How it connects
Connects search queries with data leakage, training data, validation sets, test sets, distribution drift, and monitoring.

Also explained in

Compare how 25 books explain SQL →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning System Design. The section links point to the parts of the book it draws on.