Retrieval Tuned for Code
hybrid code retrieval
Part of: Codebase Assistant
Semantic search built for prose has a blind spot on code. An embedding model can miss that a query naming the function get user by id should retrieve the chunk that defines get user by id. Retrieval for code needs a second signal beyond semantic similarity: exact identifier matches. What we're building A retriever that combines two scores per chunk. One is how semantically similar the chunk is to the query, from an embedding comparison. The other is whether the query mentions an identifier, a function or variable name, that appears verbatim in the chunk's name. This is hybrid retrieval , and it's standard for code search because identifiers carry more precise meaning in code than words do in prose. Embedding code with a code-aware model General-purpose text embeddings are trained mostly on prose. For code, use a model trained on code, like Voyage AI's voyage-code-2: Each chunk and the query become vectors of numbers. You measure similarity between two vectors with cosine similarity : the cosine of the angle between them, from -1 (opposite) to 1 (identical direction). Closer to 1 means more semantically related. Adding the code-specific boost Cosine similarity alone still misses exa
Challenge: Score and Rank Code Chunks