Skip to content

Commit

Permalink
fix spawn gen
Browse files Browse the repository at this point in the history
  • Loading branch information
friendlymatthew committed Jun 11, 2024
1 parent abe9808 commit bf7c43b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/hnsw/hnsw.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewHnsw(d int, efConstruction int, M int, entryPoint Point) *Hnsw {
}

func (h *Hnsw) SpawnLevel() int {
return int(math.Floor(-math.Log(rand.Float64() * h.levelMultiplier)))
return int(math.Floor(-math.Log(rand.Float64()) * h.levelMultiplier))
}

func (h *Hnsw) GenerateId() Id {
Expand Down Expand Up @@ -181,6 +181,11 @@ func (h *Hnsw) InsertVector(q Point) error {

qId := h.GenerateId()
qTopLevel := h.SpawnLevel()

if qTopLevel < 0 {
panic("invalid top level cannot have a negative top level")
}

qFriends := NewFriends(qTopLevel)
h.friends[qId] = qFriends
h.points[qId] = &q
Expand Down

0 comments on commit bf7c43b

Please sign in to comment.