Database / pgvector basics Interview Questions
What PostgreSQL configuration parameters affect pgvector performance?
Several PostgreSQL-level settings directly impact pgvector query and index performance. Tuning these appropriately for a vector workload can yield significant speedups.
| Parameter | Default | Recommended (vector workload) | Effect |
|---|---|---|---|
| maintenance_work_mem | 64MB | 2-8GB | Memory for index builds - most impactful for HNSW build speed |
| max_parallel_maintenance_workers | 2 | CPU cores - 1 | Parallel workers for index build |
| work_mem | 4MB | 64-256MB | Memory per query operation |
| effective_cache_size | 4GB | ~75% of RAM | Helps query planner estimate index usage |
| shared_buffers | 128MB | 25% of RAM | PostgreSQL shared memory cache |
| hnsw.ef_search | 40 | 40-200 (based on recall needs) | HNSW query-time recall/speed tradeoff |
| ivfflat.probes | 1 | 1-lists (based on recall needs) | IVFFlat query-time recall/speed tradeoff |
-- Permanently set in postgresql.conf or via ALTER SYSTEM: ALTER SYSTEM SET maintenance_work_mem = '4GB'; ALTER SYSTEM SET max_parallel_maintenance_workers = 7; ALTER SYSTEM SET work_mem = '128MB'; -- Apply config changes without full restart: SELECT pg_reload_conf(); -- Set per-session (for index build or critical query): SET maintenance_work_mem = '4GB'; SET max_parallel_maintenance_workers = 7; CREATE INDEX ON items USING hnsw (embedding vector_cosine_ops); RESET maintenance_work_mem; RESET max_parallel_maintenance_workers; -- Per-query tuning: SET hnsw.ef_search = 100; -- increase recall for this query SELECT * FROM items ORDER BY embedding <-> '[...]' LIMIT 5; RESET hnsw.ef_search; -- Verify current settings: SHOW maintenance_work_mem; SHOW hnsw.ef_search; SHOW ivfflat.probes;
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
