Design a Codebase Semantic Indexing System
Last updated: May 21, 2025
Quick Overview
Design a system that indexes an entire codebase for semantic search and context retrieval for LLM prompts. Cover chunking strategies, embedding generation, incremental updates, and query-time retrieval.
Cursor
May 21, 20258
6
2,071 solved
Design a system that indexes an entire codebase for semantic search and context retrieval for LLM prompts. Cover chunking strategies, embedding generation, incremental updates, and query-time retrieval.
Cursor's context retrieval depends on understanding the semantic structure of a codebase. This question tests your ability to design a system that indexes code for retrieval-augmented generation. The interviewer expects you to discuss chunking at the AST level, embedding model selection, incremental indexing on file changes, and fast retrieval with relevance ranking.
What the Interviewer Expects
- Design a chunking strategy that respects code structure using AST parsing
- Select appropriate embedding models for code and discuss trade-offs
- Handle incremental index updates when files change without full reindexing
- Design a retrieval pipeline that ranks results by relevance to the current editing context
- Discuss storage choices for embeddings and metadata
Key Topics to Cover
How to Approach This
- Start by clarifying functional and non-functional requirements with the interviewer.
- Estimate the scale: QPS, storage, bandwidth. This drives your design decisions.
- Draw a high-level architecture first, then deep dive into 1-2 critical components.
- Discuss trade-offs explicitly (e.g., consistency vs availability, SQL vs NoSQL).
- Address failure scenarios, monitoring, and how the system handles 10x traffic spikes.
Possible Follow-up Questions
- How would you handle a monorepo with millions of files?
- How would you index codebases with multiple programming languages?
- What happens when the embedding model is updated and all vectors need regeneration?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
- Functional Requirements:
- Index the entire codebase for semantic search, allowing users to retrieve contextually relevant code snippets based on natural language queries.
- Support chunking...
Capacity Estimation
Assuming Cursor manages an average codebase of 500,000 lines of code per project:
- Each line of code can be estimated to generate about 30 tokens (considering comments, whitespace, etc.).
- This lead...