Compare commits

...

4 Commits

Author SHA1 Message Date
Andrew Kane
c207a2d50e Reduced lock contention with parallel HNSW index builds 2024-03-11 19:50:48 -07:00
Andrew Kane
569fd36396 Improved performance of parallel HNSW index builds 2024-03-11 18:32:39 -07:00
Andrew Kane
62350b1589 Added note about IVFFlat results [skip ci] 2024-03-06 00:29:55 -08:00
Andrew Kane
dd57309281 Added section about HNSW results - #480 [skip ci] 2024-03-06 00:27:50 -08:00
4 changed files with 19 additions and 0 deletions

View File

@@ -1,3 +1,7 @@
## 0.6.2 (unreleased)
- Reduced lock contention with parallel HNSW index builds
## 0.6.1 (2024-03-04) ## 0.6.1 (2024-03-04)
- Fixed error with `ANALYZE` and vectors with different dimensions - Fixed error with `ANALYZE` and vectors with different dimensions

View File

@@ -581,6 +581,10 @@ or choose to store vectors inline:
ALTER TABLE items ALTER COLUMN embedding SET STORAGE PLAIN; ALTER TABLE items ALTER COLUMN embedding SET STORAGE PLAIN;
``` ```
#### Why are there less results for a query after adding an HNSW index?
Results are limited by the size of the dynamic candidate list (`hnsw.ef_search`). There may be even less results due to dead tuples or filtering conditions in the query. We recommend setting `hnsw.ef_search` to at least twice the `LIMIT` of the query. If you need more than 500 results, use an IVFFlat index instead.
#### Why are there less results for a query after adding an IVFFlat index? #### Why are there less results for a query after adding an IVFFlat index?
The index was likely created with too little data for the number of lists. Drop the index until the table has more data. The index was likely created with too little data for the number of lists. Drop the index until the table has more data.
@@ -589,6 +593,8 @@ The index was likely created with too little data for the number of lists. Drop
DROP INDEX index_name; DROP INDEX index_name;
``` ```
Results can also be limited by the number of probes (`ivfflat.probes`).
## Reference ## Reference
### Vector Type ### Vector Type

View File

@@ -185,6 +185,7 @@ typedef struct HnswGraph
/* Entry state */ /* Entry state */
LWLock entryLock; LWLock entryLock;
LWLock entryWaitLock;
HnswElementPtr entryPoint; HnswElementPtr entryPoint;
/* Allocations state */ /* Allocations state */

View File

@@ -431,10 +431,15 @@ InsertTupleInMemory(HnswBuildState * buildstate, HnswElement element)
HnswGraph *graph = buildstate->graph; HnswGraph *graph = buildstate->graph;
HnswElement entryPoint; HnswElement entryPoint;
LWLock *entryLock = &graph->entryLock; LWLock *entryLock = &graph->entryLock;
LWLock *entryWaitLock = &graph->entryWaitLock;
int efConstruction = buildstate->efConstruction; int efConstruction = buildstate->efConstruction;
int m = buildstate->m; int m = buildstate->m;
char *base = buildstate->hnswarea; char *base = buildstate->hnswarea;
/* Wait if another process needs exclusive lock */
if (LWLockAcquireOrWait(entryWaitLock, LW_EXCLUSIVE))
LWLockRelease(entryWaitLock);
/* Get entry point */ /* Get entry point */
LWLockAcquire(entryLock, LW_SHARED); LWLockAcquire(entryLock, LW_SHARED);
entryPoint = HnswPtrAccess(base, graph->entryPoint); entryPoint = HnswPtrAccess(base, graph->entryPoint);
@@ -446,7 +451,9 @@ InsertTupleInMemory(HnswBuildState * buildstate, HnswElement element)
LWLockRelease(entryLock); LWLockRelease(entryLock);
/* Get exclusive lock */ /* Get exclusive lock */
LWLockAcquire(entryWaitLock, LW_EXCLUSIVE);
LWLockAcquire(entryLock, LW_EXCLUSIVE); LWLockAcquire(entryLock, LW_EXCLUSIVE);
LWLockRelease(entryWaitLock);
/* Get latest entry point after lock is acquired */ /* Get latest entry point after lock is acquired */
entryPoint = HnswPtrAccess(base, graph->entryPoint); entryPoint = HnswPtrAccess(base, graph->entryPoint);
@@ -612,6 +619,7 @@ InitGraph(HnswGraph * graph, char *base, long memoryTotal)
graph->indtuples = 0; graph->indtuples = 0;
SpinLockInit(&graph->lock); SpinLockInit(&graph->lock);
LWLockInitialize(&graph->entryLock, hnsw_lock_tranche_id); LWLockInitialize(&graph->entryLock, hnsw_lock_tranche_id);
LWLockInitialize(&graph->entryWaitLock, hnsw_lock_tranche_id);
LWLockInitialize(&graph->allocatorLock, hnsw_lock_tranche_id); LWLockInitialize(&graph->allocatorLock, hnsw_lock_tranche_id);
LWLockInitialize(&graph->flushLock, hnsw_lock_tranche_id); LWLockInitialize(&graph->flushLock, hnsw_lock_tranche_id);
} }