-
Notifications
You must be signed in to change notification settings - Fork 4
/
disk_test.go
75 lines (63 loc) · 1.35 KB
/
disk_test.go
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
75
package bbq
import (
"testing"
)
func TestDiskBackend(t *testing.T) {
testDiskBackendQuantization(t, NoQuantization{})
}
func TestDiskBackendF16(t *testing.T) {
testDiskBackendQuantization(t, Float16Quantization{})
}
func testDiskBackendQuantization[L any](t *testing.T, q Quantization[L]) {
vecs := NewRandVectorSet(*nVectors, *dim, nil)
mem := NewMemoryBackend(*dim)
dir := t.TempDir()
t.Log("TempDir:", dir)
be, err := NewDiskBackend(dir, *dim, q)
if err != nil {
t.Fatal(err)
}
store, err := NewVectorStore(be, *nBasis)
if err != nil {
t.Fatal(err)
}
for i, v := range vecs {
err := mem.PutVector(ID(i), v)
if err != nil {
t.Fatal("error mem put", err)
}
err = store.AddVector(ID(i), v)
if err != nil {
t.Fatal("error store put", err)
}
if i%10000 == 0 {
t.Log("Wrote", i)
}
}
err = store.Sync()
if err != nil {
t.Fatal(err)
}
err = store.Close()
if err != nil {
t.Fatal(err)
}
t.Log("Reopening")
// Reopen
be, err = NewDiskBackend(dir, *dim, q)
if err != nil {
t.Fatal("Couldn't open disk backend", err)
}
store, err = NewVectorStore(be, *nBasis)
if err != nil {
t.Fatal("Couldn't open vector store", err)
}
targetvecs := NewRandVectorSet(*testvecs, *dim, nil)
for _, v := range targetvecs {
fts, err := FullTableScanSearch(mem, v, 20)
fts.Len()
if err != nil {
t.Fatal(err)
}
}
}