What Hybrid Search Looks Like When It Has to Run on Your Laptop
Suppose you are working in a codebase you did not write, and you type the following question: Where is ERR_CONN_RESET handled? The answer exists. One file contains a catch block that checks for exactly that constant and retries the request. A purely semantic search may not put that file first. It may return a connection-pool module, a general error-handling utility and a retry helper. All three…
Hybrid search is a combination of lexical search and dense search, each with its own strengths and trade-offs. Lexical search preserves exact identifiers, while dense search preserves meaning. Neither approach alone can preserve both. The article explains the process of hybrid search when running on a laptop, specifically using the ctx tool.
The pipeline starts with deciding what a document is, which involves chunking. ctx routes each file by type, creating segments for different file types. Code files are split into segments based on definitions, such as functions, classes, and enums. Markdown files are split using headings and their content. The choice of units for retrieval is crucial, as the retriever can only return the units provided.
The article notes that earlier versions of ctx kept only functions and classes, but later versions also included constants and module-level code, improving retrieval for 69% of code questions.
The dense side of the pipeline involves embedding each chunk into a vector and comparing vectors to answer queries. The default embedding model used is BAAI/bge-large-en-v1.5, which produces 1,024-dimensional vectors. The vectors are L2-normalized and taken from the first token ([CLS]) for BGE models. The article highlights that this approach preserves meaning but may give up precision on very large units, such as a 2,000-line class, which would still be treated as a single definition.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.