Bird
Raised Fist0

RAG - Retrieval-Augmented Generation System Design

SYSTEM-DESIGNhardInterview freq: very_high
Choose your preparation mode6 modes available
๐ŸŽฏ
Design a Retrieval-Augmented Generation System for Real-Time Customer Support
45 min ยท senior
senior

Your team of 5 engineers has 8 months to build a real-time customer support system using RAG for a platform with 10M DAU. The system must handle 1000 QPS with a P99 latency SLA of 200ms. You have access to a large corpus of support documents and chat logs but no labeled data for training. Design the ML system.

  • 10M DAU platform
  • 1000 QPS with P99 latency SLA of 200ms
  • Large corpus of support documents and chat logs
  • No labeled data for training
  • Team of 5 engineers, 8-month timeline
๐Ÿ“‹
Guided Steps
1/5
Step 1
Data Ingestion and Preprocessing
How will you handle data ingestion and preprocessing given the large corpus of documents and chat logs?
๐Ÿ’ก Hint
Consider the trade-off between preprocessing time and the need for real-time data updates.
Batch preprocessing with periodic updates because real-time preprocessing would exceed latency constraints.
Mid: Proposes a batch processing pipeline. Senior: Also considers data freshness and proposes a strategy for incremental updates.
โš ๏ธCommon Wrong Answer
Relying solely on real-time preprocessing, leading to unacceptable latency during peak loads.
Step 2
Retrieval System Design
What retrieval system will you design to ensure relevant documents are fetched quickly?
๐Ÿ’ก Hint
Think about the balance between retrieval accuracy and speed.
Use a vector search engine like FAISS because it balances retrieval speed with the ability to handle large-scale data.
Mid: Suggests using a vector search engine. Senior: Explains indexing strategy and how it impacts retrieval latency.
โš ๏ธCommon Wrong Answer
Choosing a traditional keyword-based search, which fails to meet the latency requirements.
Step 3
Generation Model Selection
Which generation model will you choose to generate responses, and why?
๐Ÿ’ก Hint
Consider the trade-off between model complexity and inference speed.
Select a transformer-based model like BERT or GPT-3 fine-tuned for speed because they offer a good balance of performance and latency.
Mid: Chooses a transformer model. Senior: Justifies the choice with specific latency and performance metrics.
โš ๏ธCommon Wrong Answer
Selecting a complex model without considering inference latency, leading to SLA breaches.
Step 4
System Integration and Latency Optimization
How will you integrate the retrieval and generation components to meet the latency SLA?
๐Ÿ’ก Hint
Think about how to minimize data transfer and processing time between components.
Use a tightly coupled architecture with shared memory for fast data transfer because it minimizes latency.
Mid: Proposes a basic integration. Senior: Details specific optimizations like shared memory or RPC to reduce latency.
โš ๏ธCommon Wrong Answer
Loose coupling of components, resulting in high data transfer latency.
Step 5
Monitoring and Feedback Loop
How will you monitor the system and incorporate user feedback to improve performance?
๐Ÿ’ก Hint
Consider both system performance metrics and user interaction data.
Implement real-time monitoring with feedback loops using user interaction data because it allows for continuous improvement.
Mid: Sets up basic monitoring. Senior: Proposes a feedback loop for model retraining and performance tuning.
โš ๏ธCommon Wrong Answer
Neglecting user feedback, leading to a system that doesn't adapt to user needs.
๐Ÿ“Š
Scoring Rubric
โ–ผ Show
Must Have - 60%
  • Batch preprocessing strategy with incremental updates for data freshness.
  • Use of a vector search engine like FAISS for fast retrieval.
  • Selection of a transformer-based model with latency considerations.
  • Integration strategy that minimizes data transfer latency.
  • Real-time monitoring and feedback loop for continuous improvement.
Good to Have - 30%
  • Detailed indexing strategy for the retrieval system.
  • Specific latency and performance metrics for model selection.
  • Optimizations like shared memory or RPC for component integration.
  • User feedback loop that informs model retraining.
Bonus - 10%
  • Proposes a hybrid retrieval approach combining vector and keyword search.
  • Considers scalability of the system beyond the initial 1000 QPS.
  • Incorporates advanced techniques like knowledge distillation for model efficiency.
โœ…
Model Answer
โ–ผ Reveal

The ideal design involves a batch preprocessing pipeline with incremental updates, a vector search engine for fast retrieval, and a transformer-based model for generation. The system should be tightly integrated to minimize latency, with real-time monitoring and a feedback loop for continuous improvement.

  • Batch preprocessing with periodic updates to balance data freshness and processing time.
  • Vector search engine like FAISS for efficient retrieval at scale.
  • Transformer-based model fine-tuned for speed to meet latency requirements.
  • Tightly coupled architecture with shared memory to minimize data transfer latency.
  • Real-time monitoring and feedback loop using user interaction data for system improvement.
Real-time preprocessing causing latency spikes.
Keyword-based retrieval failing to meet scale and speed needs.
Complex generation models breaching latency SLAs.
Static system without user feedback adaptation.

Practice

(1/5)
1. In an A/B testing platform for ML models, which component is responsible for ensuring that users are consistently assigned to the same variant across multiple sessions?
easy
A. Randomization Engine
B. User Segmentation Module
C. Experiment Dashboard
D. Session Persistence Layer

Solution

  1. Step 1: Identify the role of each component.

    The Session Persistence Layer ensures consistent user assignment across sessions.
  2. Step 2: Eliminate wrong options.

    Randomization Engine assigns variants initially, User Segmentation Module groups users, and Experiment Dashboard displays results.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Session consistency needs persistence. [OK]
Hint: Session consistency needs persistence. [OK]
Common Mistakes:
2. In the context of LLM evaluation systems, which component is responsible for providing a standardized set of tasks to assess model performance?
easy
A. Benchmarks
B. LLM-as-Judge
C. Data preprocessing
D. Human evaluation

Solution

  1. Step 1: Identify the role of each component

    Benchmarks provide standardized tasks for evaluation.
  2. Step 2: Eliminate wrong options

    Human evaluation involves subjective assessment, LLM-as-Judge uses models to evaluate, and data preprocessing is unrelated to task standardization.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Benchmarks standardize tasks for fair comparison. [OK]
Hint: Benchmarks standardize tasks for fair comparison. [OK]
Common Mistakes:
3. Which metric is most appropriate for evaluating the performance of a Two-Tower Model for Retrieval?
easy
A. Mean Squared Error (MSE)
B. Log Loss
C. F1 Score
D. Precision at K

Solution

  1. Step 1: Identify the goal of the retrieval model

    The goal is to rank items effectively for users, making ranking metrics like Precision at K suitable.
  2. Step 2: Eliminate wrong options

    Mean Squared Error (MSE) (MSE) is for regression tasks. F1 Score (F1 Score) is for classification tasks. Log Loss (Log Loss) is also for classification tasks.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Use ranking metrics like Precision at K. [OK]
Hint: Use ranking metrics like Precision at K. [OK]
Common Mistakes:
4. A bot detection system using device fingerprinting is failing to detect bots effectively. What is the most likely failure mode?
medium
A. The system is not considering user agent strings.
B. The system is not updating fingerprints frequently enough.
C. The system is overly reliant on IP addresses.
D. The system is using outdated behavioral models.

Solution

  1. Step 1: Identify the core issue with device fingerprinting.

    Device fingerprints need frequent updates to remain effective against evolving bots.
  2. Step 2: Eliminate wrong options.

    Behavioral models and IP reliance are not directly related to fingerprinting; user agent strings are not unique enough.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Frequent updates needed for effective fingerprinting [OK]
Hint: Frequent updates needed for effective fingerprinting [OK]
Common Mistakes:
5. In a neural collaborative filtering system, what is a likely failure mode if the model is not performing well on new users?
medium
A. Data leakage from training to validation sets.
B. Overfitting due to too many layers in the neural network.
C. Cold start problem due to lack of user interaction data.
D. Underfitting due to insufficient model complexity.

Solution

  1. Step 1: Identify the issue with new users.

    New users often lack interaction data, leading to the cold start problem.
  2. Step 2: Eliminate wrong options.

    Options A and D relate to model complexity, not new user performance. Data leakage from training to validation sets. is about data leakage, not specific to new users.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    New users = cold start issue [OK]
Hint: New users = cold start issue [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