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

Added m [skip ci]

This commit is contained in:
Andrew Kane
2026-10-05 19:46:23 -07:00
parent a5e13a6e1e
commit 737143a198
3 changed files with 11 additions and 9 deletions

View File

@@ -413,6 +413,7 @@ typedef struct HnswSearchState
HnswQuery q;
Relation index;
HnswSupport *support;
int m;
} HnswSearchState;
typedef struct HnswScanOpaqueData
@@ -423,7 +424,6 @@ typedef struct HnswScanOpaqueData
visited_hash v;
pairingheap *discarded;
HnswSearchState searchState;
int m;
int64 tuples;
double previousDistance;
Size maxMemory;
@@ -471,7 +471,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, int m, bool inserting, HnswElement skipElement, visited_hash * v, pairingheap **discarded, bool initVisited, int64 *tuples);
List *HnswSearchLayer(HnswSearchState * searchState, List *ep, int ef, int lc, bool inserting, 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

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

View File

@@ -827,10 +827,11 @@ HnswLoadUnvisitedFromDisk(HnswElement element, HnswUnvisited * unvisited, int *u
* Algorithm 2 from paper
*/
List *
HnswSearchLayer(HnswSearchState * searchState, List *ep, int ef, int lc, int m, bool inserting, HnswElement skipElement, visited_hash * v, pairingheap **discarded, bool initVisited, int64 *tuples)
HnswSearchLayer(HnswSearchState * searchState, List *ep, int ef, int lc, bool inserting, HnswElement skipElement, visited_hash * v, pairingheap **discarded, bool initVisited, int64 *tuples)
{
char *base = searchState->base;
Relation index = searchState->index;
int m = searchState->m;
List *w = NIL;
pairingheap *C = pairingheap_allocate(CompareNearestCandidates, NULL);
pairingheap *W = pairingheap_allocate(CompareFurthestCandidates, NULL);
@@ -1299,6 +1300,7 @@ HnswFindElementNeighbors(char *base, HnswElement element, HnswElement entryPoint
searchState.q.value = HnswGetValue(base, element);
searchState.index = index;
searchState.support = support;
searchState.m = m;
/* Precompute hash */
if (inMemory)
@@ -1315,7 +1317,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, m, true, skipElement, NULL, NULL, true, NULL);
w = HnswSearchLayer(&searchState, ep, 1, lc, true, skipElement, NULL, NULL, true, NULL);
ep = w;
}
@@ -1334,7 +1336,7 @@ HnswFindElementNeighbors(char *base, HnswElement element, HnswElement entryPoint
List *lw = NIL;
ListCell *lc2;
w = HnswSearchLayer(&searchState, ep, efConstruction, lc, m, true, skipElement, NULL, NULL, true, NULL);
w = HnswSearchLayer(&searchState, ep, efConstruction, lc, true, skipElement, NULL, NULL, true, NULL);
/* Convert search candidates to candidates */
foreach(lc2, w)