coder / coder/hnsw

Panic will appear when running this demo.

Open
#15 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
237
Forks
32
PR merge metrics
No merged PRs in 30d

Description

Panic will appear when running this demo.
```
package main

import (
"math/rand"
"sync"
"time"

"github.com/coder/hnsw"
)

var (
idToEmb = map[int64][]float32{
8832462: {0.16308737, -0.015082314, -0.13542788, 0.0050275815},
8836285: {0.12513474, -0.01645081, -0.18823123, 0.0038108851},
8833448: {0.12430125, -0.028154016, -0.16484132, -0.013979792},
8835979: {0.11317906, -0.015129599, -0.081378885, 0.14409661},
8833623: {0.047779884, -0.01809181, -0.11893867, -0.042758342},
8836020: {0.16370028, -0.018596498, -0.13393748, -0.025386846},
8833095: {0.13081397, -0.011383214, -0.043572865, 0.007917681},
105126: {0.087190986, -0.013881853, -0.16933066, 0.09613177},
}
)

func test2() {
g := &hnsw.Graph[int64]{
Distance: hnsw.CosineDistance,
Rng: rand.New(rand.NewSource(time.Now().UnixNano())),
M: 32,
Ml: 0.28,
EfSearch: 300,
}
wg := sync.WaitGroup{}
mtx := sync.Mutex{}
for id, emb := range idToEmb {
wg.Add(1)
go func(id int64, emb []float32) {
mtx.Lock()
g.Add(hnsw.MakeNode(id, emb))
mtx.Unlock()
wg.Done()
}(id, emb)
}
wg.Wait()

for id, emb := range idToEmb {
g.Add(hnsw.MakeNode(id, emb))
}

}

func main() {
test2()
}

```

There should be something wrong here.
```
if elevator != nil {
searchPoint = layer.nodes[*elevator]
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the Go demo from the issue and reproducing the panic. Then inspect the `elevator` lookup around `searchPoint = layer.nodes[*elevator]`; done means the shown demo completes without panicking and the cause at that lookup is addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
databases, search
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.