AI EngineeringInterview preparation
Foundation·Concept·2 min read

Vector databases, vector search, and semantic search

Practice this question

🔴 MUST KNOW · 🟠 SHOULD KNOW for hybrid search and reranking.

Overview

  • A vector database stores vectors and supports similarity queries with metadata.
  • Vector search is the numerical operation; semantic search is the application goal of finding meaningfully related content.
  • Existing databases can also add vector indexes, so you do not always need a separate product.

Why this matters

Comparing a query with every document becomes expensive as the corpus grows.

An everyday example

An organized warehouse can find a nearby matching item without checking every shelf individually.

A technical example

Query the index for the 20 closest chunks where tenantId=t1 and documentStatus=active.

How it works

  1. Store embeddings
  2. Build a search index
  3. Encode query
  4. Apply supported filters
  5. Search candidates
  6. Return text IDs and scores.
  • Approximate nearest neighbor, or ANN, searches efficiently while accepting that it may miss some true closest results.

Architecture and flow

Query → embedding → filtered vector index → top-k chunks → application.

The insurance assistant example

Retrieve relevant active motor-policy clauses for the signed-in customer's insurer and product.

When to use it

For repeated similarity queries over a corpus too large or too active for simple scans.

When to avoid it

A few hundred records may work with exact in-memory comparison; relational or document queries are better for exact IDs.

Interview answer

“A vector index accelerates similarity search. I choose exact or approximate search based on scale, filtering, recall, and latency requirements.”

Benefits, trade-offs, and production considerations

  • HNSW is a graph-like ANN index; IVF partitions vector space into groups.
  • Both trade recall, memory, construction cost, and query time.
  • Benchmark with real tenant filters: global recall numbers can conceal poor filtered search.
Adapted from 13_AI.MD · “Vector databases, vector search, and semantic search”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.