Vector Embeddings

Vector embeddings convert real-world content, like documents and images, into 1-D numerical representations (arrays). These arrays have N values, representing N dimensions. They are called vectors and can be compared with each other efficiently. These vectors aren’t random blobs of numbers. They live in a semantic multi-dimensional space, and their position encodes real meaning.

Key Takeaways ● Vector embeddings = position in a multi-dimensional space. ● Each axis can be thought of as representing a property: realism, length, time, and popularity. ● Similar vectors = semantically similar content. ● Clusters = emergent structure from data, not hard-coded.


Compression & Quantization

  1. Product Quantization (PQ) ● Break each vector into sub-vectors (e.g., split a 128D vector into 8 chunks of 16D). ● For each chunk, find the nearest centroid from a pre-trained codebook ● Store only the index of the centroid, not the float values. So instead of storing 128 floats (512 bytes), you store 8 integers (8 bytes). That’s a 64x reduction. PQ is used heavily in Facebook's FAISS, Milvus, and other modern vector DBs.
  2. Scalar Quantization (SQ) ● Compress each float in the vector individually. ● Convert from 32-bit float to 8-bit (or less) integer using fixed scale and offset. This is simpler than PQ but less precise. Often combined with vector normalization

Key Takeaways ● Vector compression allows fast, scalable search. ● PQ: Sub-vector + codebook trick (most powerful). ● SQ: Per-float quantization. ● INT8: Hardware-friendly, model-compatible. ● Always balance: size vs recall vs latency.


Search Execution Flow: From Query to Result

Step 1: Embed the Query

Step 2: Search the Index

we use ANN (Approximate Nearest Neighbor) indexes like IVF and HNSW.

Step 3: Score & Rank For each candidate vector from the index, compute a similarity score using either:

  1. L2 distance (Euclidean)
  2. Cosine similarity
  3. Dot product (less common) Then return the top-K closest vectors. Cosine similarity is usually preferred for textual embeddings since it's scale-invariant