1
0
mirror of https://github.com/pgvector/pgvector.git synced 2026-10-23 10:48:54 +03:00

Added inserting [skip ci]

This commit is contained in:
Andrew Kane
2026-10-05 19:49:13 -07:00
parent 737143a198
commit c37df1bf41
3 changed files with 11 additions and 7 deletions

View File

@@ -414,6 +414,7 @@ typedef struct HnswSearchState
Relation index;
HnswSupport *support;
int m;
bool inserting;
} HnswSearchState;
typedef struct HnswScanOpaqueData
@@ -471,7 +472,7 @@ bool HnswCheckNorm(HnswSupport * support, Datum value);
Buffer HnswNewBuffer(Relation index, ForkNumber forkNum);
void HnswInitPage(Buffer buf, Page page);
void HnswInit(void);
List *HnswSearchLayer(HnswSearchState * searchState, List *ep, int ef, int lc, bool inserting, HnswElement skipElement, visited_hash * v, pairingheap **discarded, bool initVisited, int64 *tuples);
List *HnswSearchLayer(HnswSearchState * searchState, List *ep, int ef, int lc, HnswElement skipElement, visited_hash * v, pairingheap **discarded, bool initVisited, int64 *tuples);
HnswElement HnswGetEntryPoint(Relation index);
void HnswGetMetaPageInfo(Relation index, int *m, int *dimensions, HnswElement * entryPoint);
void *HnswAlloc(HnswAllocator * allocator, Size size);

View File

@@ -48,6 +48,7 @@ GetScanItems(IndexScanDesc scan, Datum value)
searchState->index = index;
searchState->support = support;
searchState->m = m;
searchState->inserting = false;
if (entryPoint == NULL)
return NIL;
@@ -56,11 +57,11 @@ GetScanItems(IndexScanDesc scan, Datum value)
for (int lc = entryPoint->level; lc >= 1; lc--)
{
w = HnswSearchLayer(searchState, ep, 1, lc, false, NULL, NULL, NULL, true, NULL);
w = HnswSearchLayer(searchState, ep, 1, lc, NULL, NULL, NULL, true, NULL);
ep = w;
}
return HnswSearchLayer(searchState, ep, hnsw_ef_search, 0, false, NULL, &so->v, hnsw_iterative_scan != HNSW_ITERATIVE_SCAN_OFF ? &so->discarded : NULL, true, &so->tuples);
return HnswSearchLayer(searchState, ep, hnsw_ef_search, 0, NULL, &so->v, hnsw_iterative_scan != HNSW_ITERATIVE_SCAN_OFF ? &so->discarded : NULL, true, &so->tuples);
}
/*
@@ -89,7 +90,7 @@ ResumeScanItems(IndexScanDesc scan)
ep = lappend(ep, sc);
}
return HnswSearchLayer(&so->searchState, ep, batch_size, 0, false, NULL, &so->v, &so->discarded, false, &so->tuples);
return HnswSearchLayer(&so->searchState, ep, batch_size, 0, NULL, &so->v, &so->discarded, false, &so->tuples);
}
/*

View File

@@ -827,11 +827,12 @@ HnswLoadUnvisitedFromDisk(HnswElement element, HnswUnvisited * unvisited, int *u
* Algorithm 2 from paper
*/
List *
HnswSearchLayer(HnswSearchState * searchState, List *ep, int ef, int lc, bool inserting, HnswElement skipElement, visited_hash * v, pairingheap **discarded, bool initVisited, int64 *tuples)
HnswSearchLayer(HnswSearchState * searchState, List *ep, int ef, int lc, HnswElement skipElement, visited_hash * v, pairingheap **discarded, bool initVisited, int64 *tuples)
{
char *base = searchState->base;
Relation index = searchState->index;
int m = searchState->m;
bool inserting = searchState->inserting;
List *w = NIL;
pairingheap *C = pairingheap_allocate(CompareNearestCandidates, NULL);
pairingheap *W = pairingheap_allocate(CompareFurthestCandidates, NULL);
@@ -1301,6 +1302,7 @@ HnswFindElementNeighbors(char *base, HnswElement element, HnswElement entryPoint
searchState.index = index;
searchState.support = support;
searchState.m = m;
searchState.inserting = true;
/* Precompute hash */
if (inMemory)
@@ -1317,7 +1319,7 @@ HnswFindElementNeighbors(char *base, HnswElement element, HnswElement entryPoint
/* 1st phase: greedy search to insert level */
for (int lc = entryLevel; lc >= level + 1; lc--)
{
w = HnswSearchLayer(&searchState, ep, 1, lc, true, skipElement, NULL, NULL, true, NULL);
w = HnswSearchLayer(&searchState, ep, 1, lc, skipElement, NULL, NULL, true, NULL);
ep = w;
}
@@ -1336,7 +1338,7 @@ HnswFindElementNeighbors(char *base, HnswElement element, HnswElement entryPoint
List *lw = NIL;
ListCell *lc2;
w = HnswSearchLayer(&searchState, ep, efConstruction, lc, true, skipElement, NULL, NULL, true, NULL);
w = HnswSearchLayer(&searchState, ep, efConstruction, lc, skipElement, NULL, NULL, true, NULL);
/* Convert search candidates to candidates */
foreach(lc2, w)