Module deck

Embeddings and vector search flashcards

Reviewing needs JavaScript. You can read every card in the list below.

Loading your cards...

Back to the module15 cards in this deck

Read all 15 cards as a list

Embeddings and similarity search

  1. Front
    Why cosine similarity for text embeddings?
    Back
    It compares direction only, so differences in vector length do not skew the ranking. It is the usual default for text embeddings, as long as the index uses the metric the model expects.
  2. Front
    What does an embedding model return for a chunk, and what does 'close' mean?
    Back
    One fixed-length vector for the whole chunk. Close vectors mean similar meaning, because contrastive training pulled matching pairs together and pushed others apart.
  3. Front
    Why is cosine as cheap as a dot product after normalizing?
    Back
    Both lengths are 1, so the denominator is 1. For unit vectors, Euclidean distance squared is 2 - 2(a·b), so it gives the same ranking too.
  4. Front
    Why can a raw dot product mis-rank results?
    Back
    It mixes angle with length, so a longer vector can outscore one that points closer to the query. Normalize, or use cosine.
  5. Front
    Query 'ERR-40412' returns general error pages. Cause and fix?
    Back
    Exact identifiers carry little learned meaning, so embeddings rank them poorly. Add keyword (BM25) search and merge with vector results: hybrid search.
  6. Front
    Results are on topic but do not answer the question. What helps?
    Back
    Embeddings measure topical closeness, not answer quality. Retrieve more candidates, then rerank them with a model that reads query and passage together.
  7. Front
    Why must index and query use the same embedding model?
    Back
    Each model builds its own vector space. Scores across models mean nothing, and no error is raised. Re-embed the whole corpus when you change models.

Vector databases

  1. Front
    What is HNSW?
    Back
    Hierarchical Navigable Small World: a layered proximity graph. Search starts in a sparse top layer, hops toward the query and descends to a dense bottom layer. High recall, memory-heavy.
  2. Front
    Is ANN search exact? What is recall@k?
    Back
    No. Recall@k is the share of the true top-k neighbors the index returned. It is the price paid for speed and memory.
  3. Front
    What do ef_search, M and ef_construction do in HNSW?
    Back
    ef_search: candidates tracked per query (more recall, more latency; adjustable per query). M: links per node. ef_construction: build-time search width. M and ef_construction are fixed at build, so changing them means a rebuild.
  4. Front
    IVF in one line?
    Back
    Cluster vectors around centers learned in a training step. At query time scan only the nprobe nearest clusters. Lighter on memory than HNSW; recall depends on nprobe and on training data.
  5. Front
    How do you measure ANN recall?
    Back
    On a sample of real queries, compute exact top-k by brute force and ANN top-k, and take the overlap. Change one knob at a time and record recall and latency.
  6. Front
    What does product quantization (PQ) trade?
    Back
    It stores compressed approximations of vectors to save memory and speed up distance checks, at some recall loss. Re-ranking a short list with the original vectors recovers some of it.
  7. Front
    When is pgvector enough, and when move to a dedicated database?
    Back
    Start with what you run (often pgvector) and measure. Move when a measured limit (latency, memory, ops burden, filtering) forces it. Qdrant and Weaviate are open source and can be self-hosted.
  8. Front
    Fewer than k results with a metadata filter, and stale results after an edit: causes?
    Back
    Filter applied after the ANN search removes candidates (fix: iterative scan, larger candidate list, partitioning). Stale: old chunks not overwritten or deleted, so use deterministic chunk IDs.