Modern search has evolved from keyword matching to "understanding" meaning. This transformation is powered by high-dimensional vector math. In this post, we’ll explore the equations that make neural search possible.
1. Vector Embeddings
At its core, an embedding is a function that maps a string of text into a high-dimensional space. In this space, distance correlates with semantic similarity.
2. Measuring Similarity
To find the most relevant documents, we calculate the Cosine Similarity between the query vector and a document vector .
The similarity is defined as the cosine of the angle between them:
A similarity of indicates identical meaning, while indicates orthogonality (no relation).
3. The RAG Flow
Retrieval-Augmented Generation (RAG) uses this math to ground AI responses in factual data. The orchestration involves several moving parts:
4. Dimensionality Reduction
Visualizing these spaces requires projecting -dimensions (often or more) down to or . This is typically done using algorithms like t-SNE or UMAP.
The optimization objective for many of these algorithms involves minimizing the Kullback-Leibler divergence:
Summary
Neural search is more than just "AI magic"—it is a rigorous application of linear algebra and probability theory. By mastering these foundations, we can build more reliable and transparent agentic systems.