Skip to content

Commit f00e907

Browse files
committed
Update README for new API
1 parent 0236acb commit f00e907

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ go get github.com/coder/hnsw@main
3232
```
3333

3434
```go
35-
g := hnsw.NewGraph[hnsw.Vector]()
35+
g := hnsw.NewGraph[int]()
3636
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}),
4040
)
4141

4242
neighbors := g.Search(
4343
[]float32{0.5, 0.5, 0.5},
4444
1,
4545
)
46-
fmt.Printf("best friend: %v\n", neighbors[0].Embedding())
46+
fmt.Printf("best friend: %v\n", neighbors[0].Vec)
4747
// Output: best friend: [1 1 1]
4848
```
4949

@@ -59,13 +59,13 @@ If you're using a single file as the backend, hnsw provides a convenient `SavedG
5959

6060
```go
6161
path := "some.graph"
62-
g1, err := LoadSavedGraph[hnsw.Vector](path)
62+
g1, err := LoadSavedGraph[int](path)
6363
if err != nil {
6464
panic(err)
6565
}
6666
// Insert some vectors
6767
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)}))
6969
}
7070

7171
// Save to disk
@@ -76,7 +76,7 @@ if err != nil {
7676

7777
// Later...
7878
// g2 is a copy of g1
79-
g2, err := LoadSavedGraph[Vector](path)
79+
g2, err := LoadSavedGraph[int](path)
8080
if err != nil {
8181
panic(err)
8282
}
@@ -94,10 +94,10 @@ nearly at disk speed. On my M3 Macbook I get these benchmark results:
9494
goos: darwin
9595
goarch: arm64
9696
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
9999
PASS
100-
ok github.com/coder/hnsw 2.530s
100+
ok github.com/coder/hnsw 2.624s
101101
```
102102

103103
when saving/loading a graph of 100 vectors with 256 dimensions.

0 commit comments

Comments
 (0)