What Is a Vector Database and How Does It Enable Semantic Search?
Fast recall
Quick revision
Core answer
text-embedding-ada-002. The database indexes those vectors with an HNSW or IVFFlat index and answers queries like 'give me the 10 nearest embeddings to this query vector', using cosine similarity or Euclidean distance as the metric. This is how semantic search works: two sentences with the same meaning have nearby vectors even if they share no words.Whether the candidate understands the distinction between keyword search and vector similarity search, and can explain embeddings, indexing strategies, and the role of a vector store in an LLM application
Describing a vector database as just a key-value store that happens to hold arrays. The key distinction is the approximate nearest-neighbour index — without it you'd do a full table scan on every query.
Explain HNSW graph construction and how it achieves sub-linear search time. Mention that PGVector is a Postgres extension so it fits inside an existing database and Spring AI's VectorStore abstraction hides the provider behind one interface.
Interview-ready guide
Interview answer
A vector database stores embeddings — dense float arrays produced by a language model — and indexes them so you can search by similarity. Two sentences with the same meaning land near each other in that high-dimensional space even if they share no words.
The search uses an HNSW index (a proximity graph) or ivfflat (bucket-based). HNSW gives sub-linear approximate nearest-neighbour search. You query it with similaritySearch and get back the closest Documents.
In Spring AI 1.0.0, the VectorStore interface is the abstraction. PgVectorStore, PineconeVectorStore, and WeaviateVectorStore all implement it. The sharp edge is index choice: HNSW is faster at query time but costs more to build and maintain; ivfflat builds faster but groups vectors into fixed buckets, so accuracy drops when the bucket count doesn't match your data distribution.
What Is a Vector Database and How Does It Enable Semantic Search
Direct Answer
A vector database stores high-dimensional numeric arrays (embeddings) and lets you search by similarity rather than exact match. A language model converts text, images, or audio into dense float arrays — e.g., 1536-dimensional vectors from OpenAI's text-embedding-ada-002. The database indexes those vectors with an HNSW or IVFFlat index and answers queries like 'give me the 10 nearest embeddings to this query vector', using cosine similarity or Euclidean distance as the metric. This is how semantic search works: two sentences with the same meaning have nearby vectors even if they share no words.
Deep Dive & Architecture
PGVector is a Postgres extension — no new infrastructure, vectors live in the same DB as your relational data, supports HNSW and ivfflat.
Best when your team already runs Postgres. Pinecone is a fully managed serverless vector service — zero ops, auto-scales, but vendor-locked and priced per query/storage.
Best for teams who want no vector infra at all. Weaviate is an open-source standalone vector database with built-in vectorization (it can call an embedding model itself during ingest) and a GraphQL/REST API. Best when you need rich filtering, multi-tenancy, or hybrid (keyword + vector) search without managing the embedding step. Spring AI 1.0.0 has first-class support for all three via PgVectorStore, PineconeVectorStore, and WeaviateVectorStore.
Describing a vector database as just a key-value store that happens to hold arrays. The key distinction is the approximate nearest-neighbour index — without it you'd do a full table scan on every query.
Common Mistakes & Pitfalls
Describing a vector database as just a key-value store that happens to hold arrays. The key distinction is the approximate nearest-neighbour index — without it you'd do a full table scan on every query.
Check your understanding
Answer these without looking back at the article.
- How do you generate and store document embeddings in a Spring Boot application with Spring AI?
- Compare PGVector, Pinecone, and Weaviate for Java backend use — when do you pick each?
- What is cosine similarity vs Euclidean distance in vector search, and when does it matter?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.