← All topics

Basic Fundamentals · Topic 20

The lifecycle of a vector query

The lifecycle of a vector query is the path from the user’s request to the returned nearest neighbors. Typically: (1) the query (e.g. text or image) is turned into a vector by the same embedding model used for the corpus; (2) the query vector and parameters (k, filters, etc.) are sent to the vector database; (3) the engine runs ANN (or exact) search on the target collection; (4) results (IDs, scores, payloads) are returned, and optionally re-ranked or merged (e.g. in hybrid search).

Summary

  • Step 1: Query (e.g. text) → same embedding model → query vector.
  • Step 2: Query vector + k + optional filters sent to VDB (often application embeds; some DBs support “query by text”).
  • Step 3: VDB runs ANN (or exact) on target collection; index (e.g. HNSW) traversed to find points.
  • Step 4: Return IDs, scores, payloads; optionally re-rank or merge with hybrid; latency and recall depend on index and parameters.

From user request to query vector

The user’s request (e.g. a search phrase, an image, or “items like this”) must be turned into a vector. That’s almost always done with the same embedding model used when indexing the corpus, so that query and documents live in the same latent space. Embedding the query is often done in the application layer: your service calls an embedding API or model, then sends the vector to the VDB. Some systems support “query by text” and run the embedding inside the DB. Either way, the critical input to the VDB is the query vector plus parameters: k (how many neighbors), optional filters, and optionally which collection to search.

Query-side embedding latency adds to total response time. For low-latency requirements, use a fast embedding model or cache embeddings for repeated or similar queries. Batch embedding of multiple queries can improve throughput when the VDB or your pipeline supports it.

Search inside the vector database

The VDB receives the query vector and parameters. It runs ANN (or exact) search on the target collection: the index (e.g. HNSW) is traversed to find candidate points, distances or similarities are computed, and the top k are returned. If filters are specified, the engine may apply pre- or post-filtering. Latency is dominated by index traversal and distance computations; recall depends on index parameters (e.g. efSearch for HNSW) and the curse of dimensionality. The result is a list of (ID, score, optional payload) for the k nearest points.

In distributed deployments the coordinator may send the query to several shards and merge the per-shard top-k by score. The merge step (e.g. k-way merge by distance) ensures the final list is the global top-k across all shards. This adds a small amount of latency and network overhead compared to a single-node search.

After the VDB: re-ranking and hybrid

Once the VDB returns candidates, the application may re-rank them (e.g. with a cross-encoder) or merge with results from keyword search in a hybrid search pipeline (e.g. RRF). So the full lifecycle can include: embed query → VDB ANN → optional re-rank/merge → return to user. Understanding this flow helps when tuning (e.g. efSearch for HNSW), adding filters or re-ranking, or designing semantic search and RAG pipelines end to end.

Distributed and multi-stage flows

In a distributed VDB, the query may be fanned out to multiple shards by a coordinator; each shard returns its top-k, and the coordinator merges (e.g. by score) to produce the final top-k. So the lifecycle can include: embed → send to coordinator → fan-out to shards → ANN per shard → merge → optional re-rank → return. See load balancing and network latency for production considerations.

Frequently Asked Questions

Where does embedding happen in the lifecycle?

Usually in the application: your service embeds the query (same model as the corpus) and sends the vector to the VDB. Some VDBs support “query by text” and embed inside the DB; then the lifecycle starts at the DB with the text query.

What affects query latency the most?

Index traversal (e.g. efSearch in HNSW), number of distance computations, and—in distributed setups—network latency. Embedding the query can also add latency if done synchronously. See measuring latency and profiling a slow query.

Can I run multiple vector queries in one request?

Some APIs support batch query: send multiple query vectors and get top-k for each. That can reduce round-trips and improve throughput. Check your VDB’s API for batch or bulk query support.

How does the lifecycle change with hybrid search?

You run both a vector query and a keyword (e.g. BM25) query, then merge results (e.g. RRF or weighted). So the “lifecycle” has two retrieval paths that meet at the merge step. Some VDBs expose hybrid as a single API that does both internally.