ParadeDB query tuning trims latency for ANN searches by adjusting planner settings, index parameters, and SQL structure.
ParadeDB builds on PostgreSQL, so the planner still decides between sequential scans, IVFFlat index scans, or HNSW. Default settings assume small data; large vector stores need manual tweaks for millisecond searches.
Start with EXPLAIN (ANALYZE, BUFFERS)
. It shows whether the call uses an IVFFlat/HNSW index or falls back to a sequential scan. Look for Seq Scan lines; they indicate missing indexes or bad parameters.
EXPLAIN (ANALYZE, BUFFERS)SELECT id, nameFROM productsORDER BY embedding <-> '[0.12,0.03, … ]' LIMIT 10;
Set planner flags before running the query or in the session:
SET enable_seqscan TO off;SET enable_bitmapscan TO off;
These nudge PostgreSQL toward the IVFFlat/HNSW index without touching global config.
IVFFlat: tune lists
on creation (CREATE INDEX … lists = 2048
) and ivfflat.probes
at query time (SET ivfflat.probes TO 10;
). More lists and probes raise recall but slow reads; measure both.
HNSW: tweak M
and ef_construction
at build, hnsw.ef_search
per query. Higher values improve accuracy with extra CPU.
Wrap multiple target vectors in a CTE and join once. This avoids repeated index startups.
WITH target(vec) AS ( VALUES ('[0.1, … ]'::vector), ('[0.2, … ]'::vector))SELECT p.id, t.vecFROM target t, LATERAL ( SELECT id FROM products ORDER BY embedding <-> t.vec LIMIT 5) p;
Increase shared_buffers
, work_mem
, and maintenance_work_mem
to keep vector pages hot and speed index builds. Disable track_io_timing
in prod if not debugging; it adds overhead.
EXPLAIN ANALYZE
firstivfflat.probes
or hnsw.ef_search
only as neededNo, only the current session is affected. Reset with SET enable_seqscan = on;
.
Yes if they change frequently. Isolating updates avoids index bloat on the main product catalog.
Choose HNSW for read-heavy workloads needing high recall (>0.95). IVFFlat suits mixed read/write or smaller datasets.