@@ -32,18 +32,18 @@ go get github.com/coder/hnsw@main
32
32
```
33
33
34
34
``` go
35
- g := hnsw.NewGraph [hnsw. Vector ]()
35
+ g := hnsw.NewGraph [int ]()
36
36
g.Add (
37
- hnsw.MakeVector ( " 1 " , []float32 {1 , 1 , 1 }),
38
- hnsw.MakeVector ( " 2 " , []float32 {1 , -1 , 0.999 }),
39
- hnsw.MakeVector ( " 3 " , []float32 {1 , 0 , -0.5 }),
37
+ hnsw.MakeNode ( 1 , []float32 {1 , 1 , 1 }),
38
+ hnsw.MakeNode ( 2 , []float32 {1 , -1 , 0.999 }),
39
+ hnsw.MakeNode ( 3 , []float32 {1 , 0 , -0.5 }),
40
40
)
41
41
42
42
neighbors := g.Search (
43
43
[]float32 {0.5 , 0.5 , 0.5 },
44
44
1 ,
45
45
)
46
- fmt.Printf (" best friend: %v \n " , neighbors[0 ].Embedding () )
46
+ fmt.Printf (" best friend: %v \n " , neighbors[0 ].Vec )
47
47
// Output: best friend: [1 1 1]
48
48
```
49
49
@@ -59,13 +59,13 @@ If you're using a single file as the backend, hnsw provides a convenient `SavedG
59
59
60
60
``` go
61
61
path := " some.graph"
62
- g1 , err := LoadSavedGraph [hnsw. Vector ](path)
62
+ g1 , err := LoadSavedGraph [int ](path)
63
63
if err != nil {
64
64
panic (err)
65
65
}
66
66
// Insert some vectors
67
67
for i := 0 ; i < 128 ; i++ {
68
- g1.Add (MakeVector (strconv. Itoa (i) , []float32 {float32 (i)}))
68
+ g1.Add (hnsw. MakeNode (i , []float32 {float32 (i)}))
69
69
}
70
70
71
71
// Save to disk
@@ -76,7 +76,7 @@ if err != nil {
76
76
77
77
// Later...
78
78
// g2 is a copy of g1
79
- g2 , err := LoadSavedGraph [Vector ](path)
79
+ g2 , err := LoadSavedGraph [int ](path)
80
80
if err != nil {
81
81
panic (err)
82
82
}
@@ -94,10 +94,10 @@ nearly at disk speed. On my M3 Macbook I get these benchmark results:
94
94
goos: darwin
95
95
goarch: arm64
96
96
pkg: github.com/coder/hnsw
97
- BenchmarkGraph_Import-16 2733 369803 ns/op 228.65 MB/s 352041 B/op 9880 allocs/op
98
- BenchmarkGraph_Export-16 6046 194441 ns/op 1076.65 MB/s 261854 B/op 3760 allocs/op
97
+ BenchmarkGraph_Import-16 4029 259927 ns/op 796.85 MB/s 496022 B/op 3212 allocs/op
98
+ BenchmarkGraph_Export-16 7042 168028 ns/op 1232.49 MB/s 239886 B/op 2388 allocs/op
99
99
PASS
100
- ok github.com/coder/hnsw 2.530s
100
+ ok github.com/coder/hnsw 2.624s
101
101
```
102
102
103
103
when saving/loading a graph of 100 vectors with 256 dimensions.
0 commit comments