github.com/weaviate/weaviate@v1.24.6/adapters/repos/db/vector/hnsw/restore_test.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package hnsw 13 14 import ( 15 "context" 16 "io" 17 "os" 18 "path" 19 "testing" 20 21 "github.com/stretchr/testify/assert" 22 "github.com/weaviate/weaviate/adapters/repos/db/vector/common" 23 "github.com/weaviate/weaviate/adapters/repos/db/vector/hnsw/distancer" 24 "github.com/weaviate/weaviate/adapters/repos/db/vector/testinghelpers" 25 "github.com/weaviate/weaviate/entities/cyclemanager" 26 ent "github.com/weaviate/weaviate/entities/vectorindex/hnsw" 27 ) 28 29 func Test_RestartFromZeroSegments(t *testing.T) { 30 testPath := t.TempDir() 31 src := path.Join(".", "compression_tests", "fixtures", "restart-from-zero-segments", "1234567") 32 source, err := os.Open(src) 33 assert.Nil(t, err) 34 dstPath := path.Join(testPath, "main.hnsw.commitlog.d") 35 assert.Nil(t, os.Mkdir(dstPath, 0o777)) 36 destination, err := os.Create(path.Join(dstPath, "1234567")) 37 assert.Nil(t, err) 38 _, err = io.Copy(destination, source) 39 assert.Nil(t, err) 40 source.Close() 41 destination.Close() 42 43 efConstruction := 64 44 ef := 32 45 maxNeighbors := 32 46 dimensions := 20 47 vectors_size := 10000 48 queries_size := 1 49 vectors, _ := testinghelpers.RandomVecs(vectors_size, queries_size, dimensions) 50 distancer := distancer.NewL2SquaredProvider() 51 uc := ent.UserConfig{} 52 uc.MaxConnections = maxNeighbors 53 uc.EFConstruction = efConstruction 54 uc.EF = ef 55 uc.VectorCacheMaxObjects = 10e12 56 uc.PQ = ent.PQConfig{Enabled: true, Encoder: ent.PQEncoder{Type: ent.PQEncoderTypeKMeans, Distribution: ent.PQEncoderDistributionNormal}} 57 config := Config{ 58 RootPath: testPath, 59 ID: "main", 60 MakeCommitLoggerThunk: MakeNoopCommitLogger, 61 DistanceProvider: distancer, 62 VectorForIDThunk: func(ctx context.Context, id uint64) ([]float32, error) { 63 return vectors[int(id)], nil 64 }, 65 TempVectorForIDThunk: func(ctx context.Context, id uint64, container *common.VectorSlice) ([]float32, error) { 66 copy(container.Slice, vectors[int(id)]) 67 return container.Slice, nil 68 }, 69 } 70 71 _, err = New( 72 config, uc, 73 cyclemanager.NewCallbackGroupNoop(), cyclemanager.NewCallbackGroupNoop(), cyclemanager.NewCallbackGroupNoop(), testinghelpers.NewDummyStore(t)) 74 75 assert.Nil(t, err) 76 }