Vector Database Technology: Principles and a Practical Selection Guide

    This article explains how vector databases work and how to choose the right one for production use. It covers why traditional databases fall short for semantic search, the core data model and similarity metrics, the trade-offs among graph-based, quantization-based, and clustering-based indexes, filtering strategies in the retrieval pipeline, capacity planning for storage and replicas, and evaluation, operations, and common use cases. Readers will gain a practical framework for matching index choices and filtering designs to their latency, memory, and recall requirements.

    1. Why Vector Databases Are Needed

    Traditional relational databases and key-value stores excel at exact matching. Their query semantics rely on deterministic comparisons between field values and index structures. However, unstructured data such as text, speech, images, and video cannot express semantic similarity through a finite set of enumerated values.

    The common industry approach is to first use an embedding model to map raw data into high-dimensional dense vectors, so that semantically similar objects sit closer together in the vector space. Nearest neighbor search then handles the “find similar” retrieval task. Vector databases are designed for exactly this pattern: they natively support persistent storage of high-dimensional vectors, approximate nearest neighbor indexes, filtered hybrid search, and horizontal scaling.

    It is important to note that vectorization and vector storage are two separate stages. The former is handled by model inference services; the latter is handled by the database. Conflating the two often leads to inaccurate capacity estimates and unpredictable end-to-end latency.

    2. Core Data Model and Similarity Metrics

    A typical vector record contains a primary key, a vector field, scalar fields, and an optional reference to the raw data. Scalar fields are used for business filtering (such as tenant, time range, or category). Raw data is generally stored in object storage, with the database keeping only a reference, which prevents large fields from polluting the index structure.

    The similarity metric defines what “similar” means, and it must align with the application goal:

    • Inner product: suitable for normalized vectors, with the lowest computation cost;
    • Cosine similarity: ignores magnitude and considers only direction, commonly used for text semantics;
    • Euclidean distance: sensitive to magnitude, suitable for certain image feature scenarios.
    1. # Example: after normalization, inner product is equivalent to cosine similarity
    2. import numpy as np
    3. def normalize(v):
    4. n = np.linalg.norm(v)
    5. return v / n if n > 0 else v
    6. q = normalize(model.encode("return and refund policy"))
    7. scores = index.search(q, top_k=10) # returns primary keys and similarity scores

    A common mistake is using different normalization strategies or different model versions during training and querying. This can cause a cliff-like drop in recall and is difficult to diagnose from monitoring metrics.

    3. Index Mechanisms and Complexity Trade-offs

    Exact search requires traversing all vectors, with complexity growing linearly as data volume increases, which cannot support online services. Vector databases therefore commonly adopt approximate nearest neighbor algorithms, trading controllable accuracy loss for order-of-magnitude performance gains. The common approaches fall into three categories:

    1. Graph-based neighbor traversal: builds a navigable hierarchical graph structure and greedily descends layer by layer during queries. It offers high recall but high memory usage and longer build times.
    2. Quantization-based encoding compression: splits vectors and quantizes them into a finite codebook, significantly reducing memory usage. It suits billion-scale datasets but requires an additional reranking step to correct accuracy.
    3. Clustering-based inverted structures: clusters first and then searches within candidate clusters. Parameters are intuitive and easy to tune, but it is sensitive to changes in data distribution.

    There is no “optimal index” in engineering, only an index that matches the constraints. For online retrieval with ample memory budget and strict latency requirements, graph structures are preferred. For offline analysis with massive data scale, cost sensitivity, and tolerance for slight recall loss, quantization compression is preferred. In practice, quantization and graph structures are often combined into a two-stage retrieval process of “coarse filtering + fine ranking.”

    4. Retrieval Pipeline and Filtering Strategies

    A complete query typically includes request parsing, vectorization, index search, scalar filtering, result reranking, and result packaging. The filtering position is a key design point:

    • Post-filtering: search first, then filter. It is simple to implement, but may return fewer than top_k results when filter conditions are strict.
    • Pre-filtering: narrow the candidate set first, then search. Results are complete, but an overly small candidate set breaks the index structure and significantly degrades performance.

    A more robust approach is to let the database carry filter conditions during index traversal and set a lower-bound threshold for the candidate set, balancing completeness and performance.

    5. Data Scale and Capacity Planning

    Capacity estimation should cover four parts: raw vectors, index structures, scalar fields, and replicas. Taking a single vector dimension of d and a count of n as an example, the floating-point storage for raw vectors alone is approximately n×d×4 bytes. With quantization compression, this can drop by several times, but raw or half-precision data needed for reranking must be retained additionally. The number of replicas directly determines read throughput and fault tolerance, usually at least two replicas.

    On the write side, pay attention to batch size and refresh frequency: too small a batch amplifies index build overhead, while too large a batch prolongs visibility latency. It is recommended to trigger on dual thresholds of “batch record count + time interval.”

    6. Evaluation, Operations, and Typical Scenarios

    Before going live, an offline evaluation set must be established to compare different index parameters using metrics such as recall and mean reciprocal rank. After going live, a monitoring and alerting system should track query latency percentiles, recall fluctuation, memory watermark, and write backlog. Capacity changes and index rebuilds should support rolling execution to avoid overall unavailability.

    Typical scenarios include document chunk retrieval in enterprise knowledge base question answering, image-to-image search and product similar recommendation, speech and video segment deduplication, and similar behavior clustering in risk control. These scenarios share a common feature of “semantic matching + scalar constraints.” Therefore, selection should focus on validating hybrid filtering capability, incremental write visibility, and multi-tenant isolation, rather than only the peak speed of a single query. When building on the cloud, general capabilities such as object storage, message queues, container platforms, and log monitoring can be combined to accomplish data ingestion, incremental synchronization, and observability. Relevant product categories from Baidu AI Cloud can also be evaluated along these lines.