Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix spawn gen #336

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading