Bird
Raised Fist0

Semantic Search - Dense Retrieval, Bi-Encoder, Cross-Encoder

SYSTEM-DESIGNhardInterview freq: very_high
Choose your preparation mode6 modes available
β–Ά
Execution Trace
Step 1/5
Data Ingest

Raw text data is loaded into the system for processing. Example: 'The quick brown fox jumps over the lazy dog.'

🎯 Understanding the importance of data quality at the ingestion stage.
raw_data = load_data('data_source')
Preprocess

Text is tokenized into individual words or subwords. Example: ['The', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog'].

🎯 Tokenization is crucial for converting text into a format suitable for embedding.
tokens = tokenizer.tokenize(raw_data)
Dense Vector Generation

Tokens are converted into dense vectors using a pre-trained model. Example: [0.1, 0.2, 0.3, ...].

🎯 Dense vectors capture semantic meaning, enabling effective retrieval.
dense_vectors = model.encode(tokens)
Bi-Encoder

Bi-encoder generates initial candidate embeddings for retrieval. Example: 100 candidate vectors generated.

🎯 Bi-encoders are efficient for initial retrieval due to independent encoding.
candidates = bi_encoder.retrieve(dense_vectors)
Cross-Encoder

Cross-encoder refines candidate scores by jointly encoding query and document. Example: Final scores range from 0.1 to 0.9.

🎯 Cross-encoders provide more accurate scoring by considering interactions.
final_scores = cross_encoder.score(candidates)
πŸ“Š
Diagram
Diagram
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Data Ingest β”‚ ──▢│   Preprocess  β”‚ ──▢│  Dense Vector  β”‚
β”‚   Raw Text    β”‚     β”‚   Tokenize    β”‚     β”‚  Generation   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚                     β”‚
                             β–Ό                     β–Ό
                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚  Bi-Encoder   β”‚     β”‚ Cross-Encoder β”‚
                      β”‚  Embeddings   β”‚     β”‚  Scoring      β”‚
                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚                     β”‚
                             β–Ό                     β–Ό
                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚  Retrieval     β”‚     β”‚   Ranking     β”‚
                      β”‚  Candidate     β”‚     β”‚   Final       β”‚
                      β”‚  Generation    β”‚     β”‚   Results     β”‚
                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • Data Ingest: Raw text input
  • Preprocess: Tokenization and cleaning
  • Dense Vector Generation: Embedding creation
  • Bi-Encoder: Initial candidate retrieval
  • Cross-Encoder: Final ranking and scoring
πŸ”‘
Key Moments
β–²
Q: Why is tokenization a critical step in the preprocessing stage?
A: Tokenization converts raw text into a structured format, enabling the creation of embeddings that capture semantic meaning.
Q: How do bi-encoders and cross-encoders differ in their approach to retrieval?
A: Bi-encoders independently encode queries and documents, making them efficient for initial retrieval, while cross-encoders jointly encode them for more accurate scoring.
Q: What role do dense vectors play in semantic search?
A: Dense vectors represent the semantic meaning of text, allowing for effective retrieval and ranking based on similarity.

The diagram illustrates a semantic search pipeline using dense retrieval with bi-encoder and cross-encoder models. It begins with data ingestion, where raw text is loaded and preprocessed through tokenization. Dense vectors are generated to capture semantic meaning. The bi-encoder model retrieves initial candidates efficiently, while the cross-encoder refines these candidates by scoring them more accurately. This system design ensures effective retrieval and ranking of search results, highlighting the importance of each component in the pipeline.

Primary Focus

βœ“ ML pipeline for semantic search using dense retrieval with bi-encoder and cross-encoder

Practice

(1/5)
1. In the context of agent system design, which component is primarily responsible for deciding the sequence of actions to achieve a goal?
easy
A. Memory Architecture
B. Planning
C. Tool Use
D. Data Preprocessing

Solution

  1. Step 1: Identify the role of each component

    Planning is responsible for deciding the sequence of actions to achieve a goal.
  2. Step 2: Eliminate wrong options

    Memory Architecture is for storing information, Tool Use is for executing actions, and Data Preprocessing is unrelated to action sequencing.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Planning = action sequence decision [OK]
Hint: Planning decides action sequences. [OK]
Common Mistakes:
2. For an LLM serving system focused on minimizing response time, which metric should be prioritized?
easy
A. Latency
B. Memory Usage
C. Accuracy
D. Throughput

Solution

  1. Step 1: Identify the goal.

    Minimizing response time directly relates to reducing latency.
  2. Step 2: Eliminate wrong options.

    Throughput measures volume, not speed. Accuracy is about correctness, not speed. Memory Usage affects capacity, not response time.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Minimize latency to cut response time. [OK]
Hint: Minimize latency to cut response time. [OK]
Common Mistakes:
3. In a text embedding pipeline, what is a likely failure mode if embeddings are not updated regularly with new data?
medium
A. Decreased model relevance
B. Model overfitting
C. Faster inference times
D. Increased computational cost

Solution

  1. Step 1: Consider the impact of stale embeddings.

    Embeddings that are not updated may not capture recent trends, leading to decreased relevance.
  2. Step 2: Eliminate wrong options.

    Increased cost and overfitting are unrelated to stale embeddings, and inference times are not directly affected.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Stale embeddings reduce relevance. [OK]
Hint: Stale embeddings reduce relevance. [OK]
Common Mistakes:
4. As the number of concurrent experiments increases in an A/B testing platform, which component is most likely to become a bottleneck first?
hard
A. Data Storage Layer
B. Experiment Dashboard
C. Randomization Engine
D. User Segmentation Module

Solution

  1. Step 1: Consider the impact of scaling experiments.

    More experiments generate more data, stressing storage.
  2. Step 2: Eliminate wrong options.

    Dashboard and segmentation handle display and grouping, while randomization is not data-intensive.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    More experiments = more data. [OK]
Hint: More experiments = more data. [OK]
Common Mistakes:
5. As a news feed system scales to 10x more users, which component is most likely to become a bottleneck first?
hard
A. Content Delivery Network
B. Recommendation Engine
C. User Interface
D. Data Storage

Solution

  1. Step 1: Analyze scaling challenges

    The Recommendation Engine processes user data to generate personalized feeds, which becomes computationally intensive as user numbers grow.
  2. Step 2: Consider other components

    B: Content Delivery Network scales well with caching. C: User Interface is less affected by user count. D: Data Storage can be expanded more easily than processing power.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Recommendation Engine struggles first with user scale. [OK]
Hint: Recommendation Engine struggles first with user scale. [OK]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard