Vector search
Finding items by closeness in embedding space rather than exact keywords.
Vector search finds items by closeness in embedding space, rather than by exact keywords. A query is turned into a vector, and the index returns the nearest neighbors. This is how you find a passage that answers a question even if the wording is different, or a piece of code that does the same job under another name.
It is a better fit than keyword search when the user speaks in sentences, or when the corpus uses many words for the same idea. It is a worse fit when the user is looking for an exact identifier, an error string, or a rare proper name. Those queries still want a lexical index. In practice the best systems run both and blend the results.
Chunking and the embedding model set the ceiling on quality. A vector for a whole chapter is usually too coarse; a vector for a half sentence is usually too thin. Return the original text, not just an id, and show enough of it that a person or a model can use it.
Evaluate with real questions and a simple metric, such as whether the right passage is in the top few hits. If it is not, a larger language model downstream will not save you.
Approximate nearest neighbor search
Finding vectors close to a query by checking a smart subset instead of every stored vector.
Approximate nearest neighbor search, or ANN, finds vectors close to a query without comparing it to every stored vector. Exact search is simple but scales linearly with the collection, which gets slow at millions of vectors. ANN indexes organize vectors into graphs, clusters, or compressed codes so a query only examines a small, promising subset.
The trade is a small loss in accuracy. ANN occasionally misses a true nearest neighbor, measured as recall: the share of the exact top results that the approximate search also returns. Well-tuned indexes commonly reach 95 percent recall or more at a fraction of the cost. Measure it on your own data by running exact search on a sample of queries and comparing, then tune index settings until the speed and recall fit your needs.
HNSW
Hierarchical navigable small world: a layered graph index for fast approximate vector search.
HNSW, short for hierarchical navigable small world, is a graph index for approximate nearest neighbor search and one of the most widely used. Every vector is a node linked to some of its near neighbors. The graph has layers: the top layers hold few nodes with long-range links, and the bottom layer holds every node. A search starts at the top, moves greedily toward the query, drops to the next layer, and refines until it reaches the bottom.
A few settings control the trade-offs. The number of links per node, often called M, raises recall and memory use. The candidate list size during index building improves graph quality at the cost of slower builds. The candidate list size during search, often called ef, lets you trade query speed for recall at query time. HNSW is fast and accurate but keeps the graph in memory and handles heavy deletes less gracefully than some alternatives.