← All topics

Performance, Evaluation & Benchmarking · Topic 181

Profiling a slow vector query

Profiling a slow vector query means measuring where time is spent end-to-end so you can target the real bottleneck—embedding the query, index traversal, distance computations, metadata filtering, or network/API overhead. Without profiling, it is easy to optimize the wrong layer.

Summary

  • Profiling a slow vector query means measuring where time is spent end-to-end so you can target the real bottleneck: embedding, index traversal, distance computations, metadata filtering, or network/API. Without profiling, it is easy to optimize the wrong layer.
  • Steps: end-to-end latency breakdown; index-level metrics (graph hops, efSearch); embedding latency; pre- vs. post-filter impact; CPU/GPU flame graphs. Fixes: tune efSearch, reduce dimension/quantize, move filtering earlier, scale out; check network latency. Pipeline: instrument stages, find bottleneck, fix. Practical tip: start with end-to-end breakdown before optimizing a single layer.

Profiling steps

Typical steps: (1) End-to-end latency breakdown—instrument the full path (embedding call, VDB request, post-processing) to see p50/p99 per stage. (2) Index-level metrics—if the VDB exposes them, check graph hop count (e.g. HNSW), number of distance evaluations, or efSearch vs. actual work done. (3) Embedding latency—measure time to embed the query; if this dominates, consider caching, smaller models, or batching. (4) Filter impactpre- vs. post-filtering and filter selectivity can greatly affect how many vectors are scanned. (5) CPU/GPU profiling—use flame graphs or profilers to see if time is in distance math, memory access, or serialization.

Common fixes

Common fixes after profiling: increase efSearch only if the bottleneck is recall, not index traversal; reduce embedding dimension or switch to quantized indices; move filtering earlier if the engine supports it; scale out or add replicas if the bottleneck is CPU per node; and ensure network latency and client-side time are not dominating.

Pipeline: instrument stages, find bottleneck, fix. Practical tip: start with end-to-end breakdown before optimizing a single layer.

Frequently Asked Questions

Why profile a slow vector query?

To find where time is spent end-to-end: embedding the query, index traversal, distance computations, metadata filtering, or network/API. Without profiling, it is easy to optimize the wrong layer. See latency and monitoring.

What should I measure when profiling?

End-to-end latency breakdown (embedding, VDB request, post-processing); index-level metrics (graph hops, efSearch vs. actual work); embedding latency; pre- vs. post-filter impact; CPU/GPU flame graphs for distance math and memory access.

What are common fixes after profiling?

Increase efSearch only if the bottleneck is recall; reduce embedding dimension or use quantized indices; move filtering earlier; scale out or add replicas; ensure network latency and client-side time are not dominating. See recall–latency trade-off.

How does filtering affect query speed?

Pre- vs. post-filtering and filter selectivity greatly affect how many vectors are scanned. If filtering dominates, move to pre-filtering if the engine supports it; see metadata filtering and metadata cardinality.