Vector Database Technology: Principles and Engineering Practices Explained
This article breaks down how vector databases work and how to run them in production. It covers the shift from exact keyword matching to semantic similarity search, the core math behind vectors and similarity metrics, the KNN-to-ANN transition, a typical five-layer architecture, and the main engineering challenges around index selection, filtering, data updates, multi-tenancy, and observability. It also outlines a cloud deployment approach and a practical checklist for evaluating recall, latency, and memory so that semantic search stays reliable at scale.
1. From Exact Matching to Semantic Matching: Where Vector Databases Fit
Traditional relational databases and inverted indexes are built for structured fields and exact keyword matching. Their query semantics are deterministic conditions such as “equals,” “greater than,” or “contains.” However, in scenarios dominated by unstructured data such as text, speech, images, and video, users usually want to “find similar,” “find related,” or “find semantically close” content. These needs cannot be expressed through literal matching. The data must first be mapped into a high-dimensional dense vector space, where similarity retrieval is then performed.
Vector databases are purpose-built storage and query engines for this pattern. They ingest vectors produced by embedding models that encode text, speech, images, video, and other data, and they handle vector persistence, index construction, filter management, similarity ranking, and result return. It is worth stressing that a vector database typically does not include the embedding model itself; it consumes the model’s output. Model selection and vector quality directly determine the upper limit of retrieval quality.
2. Core Concepts and Mathematical Foundations
2.1 Vectors and Vector Spaces
A vector is a fixed-length array of floating-point numbers, for example 768 or 1024 dimensions. No single dimension carries business meaning on its own; the relationships among dimensions jointly encode semantic information. Objects with similar meaning sit closer together in the vector space, and this is the fundamental assumption behind all retrieval capability.
2.2 Similarity Metrics
Three metrics are widely used in the industry:
- Inner product (dot product): measures directional consistency and is affected by magnitude; suitable for normalized vectors.
- Cosine similarity: considers only the angle between vectors and ignores magnitude; the most common choice for text semantic retrieval.
- Euclidean distance (L2): measures absolute distance in space; common in scenarios such as image features.
One engineering caveat: the metric must stay consistent with the assumptions used when the embedding model was trained. Otherwise you get the problem where “recall looks reasonable but ranking is scrambled.”
2.3 From KNN to ANN
Exact nearest neighbor search (KNN) compares a query against every record, so complexity grows linearly with data volume and becomes impractical beyond roughly a million records. Production systems therefore rely on approximate nearest neighbor (ANN) algorithms, trading a controlled loss of accuracy for order-of-magnitude performance gains. Common approaches include graph-based neighbor traversal, quantization-based encoding and compression, clustering-based inverted bucket retrieval, and combinations of these.
3. Typical Architecture Layers
A deployable vector retrieval system usually has five layers:
- Data ingestion layer: accepts raw business data and vectors, supporting both batch and streaming writes.
- Embedding and feature processing layer: calls model services to generate vectors and manages dimension alignment, normalization, and versioning.
- Storage and index layer: stores raw vectors, index structures, and scalar fields, with support for incremental builds and segment merging.
- Query and retrieval layer: performs vector recall, scalar filtering, multi-path fusion, and reranking.
- Service and governance layer: provides APIs, authentication, rate limiting, monitoring and alerting, and capacity management.
The illustrative write and query logic below is pseudocode that only expresses the flow:
# Write: raw data -> vector -> persistvec = embedding_model.encode(text, dim=768, normalize=True)collection.upsert(id=doc_id,vector=vec,fields={"tenant": "app_a", "lang": "zh", "updated_at": now()})# Query: vector recall + scalar filter + rerankcand = collection.search(vector=query_vec,top_k=200, # widen coarse recallfilter="tenant == 'app_a' and lang == 'zh'",metric="cosine")result = rerank(query_text, cand)[:20] # converge with fine ranking
4. Key Engineering Challenges and How to Handle Them
4.1 There Is No Universal Index Choice
Graph-based indexes offer high recall and fast queries but consume significant memory during construction. Quantization-compressed indexes are memory-friendly but need additional accuracy compensation. Clustering-based inverted schemes are sensitive to parameters and require ongoing tuning. The practical approach is to derive the index type from three constraints: data scale, memory budget, and latency target. Then evaluate the recall-versus-latency curve with real business samples rather than relying on generic benchmarks.
4.2 Coupling Between Filtering and Vector Search
Filtered vector search, whether filtering before or after retrieval, can significantly affect recall quality. If the candidate set becomes too small after filtering, the ANN graph may “fail to find enough neighbors.” A sound approach is to organize scalar fields and vectors within the same index unit and to design partitioning strategies for highly selective conditions.
4.3 Data Updates and Consistency
Vector data often changes continuously with the business. You need to handle inserts, updates, and deletes, and watch for temporary resource spikes caused by index segment merging. Deletes are usually handled by marking, and actual space reclamation depends on background merging, so capacity planning must leave headroom.
4.4 Multi-Tenancy and Resource Isolation
When multiple business teams share a cluster, use collections, partitions, or namespaces for logical isolation, together with quotas and rate limiting to keep a single tenant from affecting overall stability.
4.5 Observability
Metrics that must be monitored include query latency percentiles, recall count distribution, index build time, memory and disk watermarks, failure rates, and rate-limit counts. The absence of recall quality evaluation is the root cause of most projects being unable to explain their results.
5. Deployment on the Cloud
On cloud platforms such as Baidu AI Cloud, building this kind of system usually does not require assembling every component from scratch. You can compose general capability categories: use a container platform to host retrieval services with elastic scaling, object storage to hold raw assets and model artifacts, a message queue for write buffering and peak shaving, logging and monitoring services to close the observability loop, and key and permission management for access control. With smaller data volumes or during a validation phase, start with a single cluster to verify the pipeline quickly. Once in production, gradually introduce sharding, replicas, and cross-availability-zone deployment.
6. Practical Recommendations Checklist
- Run a small-scale baseline evaluation first, and establish three baselines: recall, latency, and memory.
- Pin the embedding model version; any model upgrade must involve a full rebuild or a dual-write canary rollout.
- Standardize normalization and the similarity metric, and keep writes and queries strictly aligned.
- Widen top_k for coarse recall, then converge with a reranking model to balance quality and cost.
- Design partitioning and indexes for scalar filters to avoid recall collapse under highly selective conditions.
- Set up capacity watermark alerts and a periodic merge strategy to prevent performance degradation as data grows.
- Retain raw data and vector versions to support issue tracing and quality attribution.
The value of a vector database lies not in “storing vectors” but in turning semantic similarity into a retrieval capability that is engineerable, governable, and measurable. Understanding its mathematical assumptions, index trade-offs, and governance costs is what allows semantic search to serve the business reliably.
