-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbench_hnsw.go
More file actions
74 lines (63 loc) · 1.71 KB
/
Copy pathbench_hnsw.go
File metadata and controls
74 lines (63 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//go:build ignore
// +build ignore
package main
import (
"log"
"net/http"
_ "net/http/pprof"
"github.com/habedi/hann/core"
"github.com/habedi/hann/example"
"github.com/habedi/hann/hnsw"
)
func main() {
// Start the pprof HTTP server on port 6060. It exposes the profiling
// endpoints at /debug/pprof/.
go func() {
log.Println("Starting pprof server on :6060")
if err := http.ListenAndServe("localhost:6060", nil); err != nil {
log.Printf("pprof server failed: %v", err)
}
}()
// Benchmark the HNSW index on the FashionMNIST and Glove datasets.
BenchHNSWIndexFashionMNIST()
BenchHNSWIndexGlove25()
BenchHNSWIndexGlove200()
}
func BenchHNSWIndexFashionMNIST() {
factory := func() core.Index {
dimension := 784
M := 32
ef := 300
index, err := hnsw.New(dimension, hnsw.WithM(M), hnsw.WithEf(ef))
if err != nil {
log.Fatalf("Failed to create HNSW index: %v", err)
}
return index
}
example.RunDataset(factory, "fashion-mnist-784-euclidean",
"example/data/nearest-neighbors-datasets", 100, -1, 5)
}
func BenchHNSWIndexGlove25() {
factory := func() core.Index {
dimension := 25
index, err := hnsw.New(dimension, hnsw.WithMetric(core.Cosine))
if err != nil {
log.Fatalf("Failed to create HNSW index: %v", err)
}
return index
}
example.RunDataset(factory, "glove-25-angular",
"example/data/nearest-neighbors-datasets", 100, -1, 5)
}
func BenchHNSWIndexGlove200() {
factory := func() core.Index {
dimension := 200
index, err := hnsw.New(dimension, hnsw.WithMetric(core.Cosine))
if err != nil {
log.Fatalf("Failed to create HNSW index: %v", err)
}
return index
}
example.RunDataset(factory, "glove-200-angular",
"example/data/nearest-neighbors-datasets", 100, -1, 5)
}