Design a RAG Ranking Pipeline
MicrosoftSoftware Engineer · OnsiteLast updated
This problem tests your ability to design a multi-stage retrieval and ranking architecture for a RAG system, focusing on balancing search accuracy, latency, and system scalability.
Problem: Designing a RAG Ranking Pipeline
You are asked to design the backend pipeline for an enterprise-grade document assistant. Users submit natural language queries, and the system must retrieve relevant information from a corpus of 10 million internal PDF and Word documents to generate an accurate response.
Requirements
- Functional: The system should retrieve the top-K relevant document chunks and pass them to an LLM to generate a grounded answer.
- Non-functional: The system must handle a latency of under 2 seconds for a query. The pipeline must scale to handle 500 queries per second (QPS).
- Access Control: The system must respect document-level permissions (i.e., users can only retrieve snippets from documents they are authorized to view).
Your Task
Design the architecture for this pipeline. Please address the following:
- Indexing Pipeline: How do you process documents, chunk them, and store them for efficient retrieval?
- Retrieval Strategy: How do you balance speed and relevance? Consider a two-stage approach (retrieval and re-ranking).
- Access Control: How do you integrate permission checks without significantly impacting retrieval latency?
- Evaluation: What metrics would you use to measure the quality of the retrieval phase versus the generation phase?
Include a high-level diagram or description of the components and their interactions.
Hints
Hint 1
Consider using an inverted index (like BM25) for keyword-based filtering alongside a vector database for semantic search.
Hint 2
Access control can be handled by filtering at the database level using document-id metadata or by employing an ACL-aware search index.
Hint 3
A two-stage pipeline using a lightweight retriever (dense/sparse) followed by a cross-encoder re-ranker is standard for managing accuracy vs. latency trade-offs.
Follow-up questions
- How would you handle document updates or deletions in your index to ensure the retrieved information is always fresh?
- If the LLM generates a hallucinated answer despite relevant retrieved context, what diagnostic steps or architectural changes would you implement?
- How would you optimize the system if the document corpus grew to 1 billion documents?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.