A document search service on Azure Database for PostgreSQL flexible server has an IVFFlat index named idx_documents_embedding on the documents table, built with vector_cosine_ops. Sessions run with ivfflat.probes = 30. Last month, about 40% new rows were added from a new product domain. Since then, users report less relevant results, and measured recall has dropped. EXPLAIN ANALYZE confirms that queries already use idx_documents_embedding.
Requirements:
- Restore recall for the shifted data distribution.
- Inserts and updates from the application must continue while the maintenance runs.
- Keep
ivfflat.probesat 30 rather than increasing the number of lists searched per query.
Which statement should you run?
A substantial change in vector distribution can degrade IVFFlat recall because its existing clusters no longer suit the data. Reindexing recalculates the cluster centroids, and CONCURRENTLY permits application writes during the rebuild. This statement leaves ivfflat.probes at 30, satisfying the query-time tuning constraint. A plain rebuild blocks writes, while increasing probes violates the required setting.
- Not correct:
REINDEX INDEX idx_documents_embedding;. A plain REINDEX rebuilds the clusters but blocks writes during the operation, conflicting with the requirement for application inserts and updates to continue. - Not correct:
SET ivfflat.probes = 100;. Increasing probes searches more lists and can improve recall at the cost of query time. This statement violates the requirement to retain a probe count of 30. - Not correct:
ANALYZE documents;. ANALYZE updates statistics used for query planning. It does not rebuild the IVFFlat clusters to address the changed vector distribution. - Correct:
REINDEX INDEX CONCURRENTLY idx_documents_embedding;. Rebuilding an IVFFlat index updates its cluster centroids for the current distribution, addressing the recall degradation. CONCURRENTLY permits application writes during the rebuild, and the statement leaves ivfflat.probes unchanged. - Not correct:
SET hnsw.ef_search = 200;. hnsw.ef_search controls query-time search width for HNSW indexes. It does not tune or rebuild the IVFFlat index used here.