Fixed zero handling for HNSW level selection - resolves #1023

Co-authored-by: cuishuang <imcusg@gmail.com>
This commit is contained in:
Andrew Kaneandcuishuang committed 2026-09-08 07:26:15 -07:00
1 parent e48241b4dc
commit efa08fda9e
1 file changed
+2 -1
+2 -1
View File
@@ -246,7 +246,8 @@ HnswInitElement(char *base, ItemPointer heaptid, int m, double ml, int maxLevel,
{
HnswElement element = HnswAlloc(allocator, sizeof(HnswElementData));
int level = (int) (-log(RandomDouble()) * ml);
double uniform = RandomDouble();
int level = uniform == 0.0 ? maxLevel : (int) (-log(uniform) * ml);
/* Cap level */
if (level > maxLevel)