github.com/weaviate/weaviate@v1.24.6/adapters/repos/db/vector/hnsw/config.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  	"github.com/sirupsen/logrus"
    16  	"github.com/weaviate/weaviate/adapters/repos/db/vector/common"
    17  	"github.com/weaviate/weaviate/adapters/repos/db/vector/hnsw/distancer"
    18  	"github.com/weaviate/weaviate/entities/errorcompounder"
    19  	"github.com/weaviate/weaviate/usecases/monitoring"
    20  )
    21  
    22  // Config for a new HSNW index, this contains information that is derived
    23  // internally, e.g. by the shard. All User-settable config is specified in
    24  // Config.UserConfig
    25  type Config struct {
    26  	// internal
    27  	RootPath              string
    28  	ID                    string
    29  	MakeCommitLoggerThunk MakeCommitLogger
    30  	VectorForIDThunk      common.VectorForID[float32]
    31  	TempVectorForIDThunk  common.TempVectorForID
    32  	Logger                logrus.FieldLogger
    33  	DistanceProvider      distancer.Provider
    34  	PrometheusMetrics     *monitoring.PrometheusMetrics
    35  
    36  	// metadata for monitoring
    37  	ShardName string
    38  	ClassName string
    39  }
    40  
    41  func (c Config) Validate() error {
    42  	ec := &errorcompounder.ErrorCompounder{}
    43  
    44  	if c.ID == "" {
    45  		ec.Addf("id cannot be empty")
    46  	}
    47  
    48  	if c.RootPath == "" {
    49  		ec.Addf("rootPath cannot be empty")
    50  	}
    51  
    52  	if c.MakeCommitLoggerThunk == nil {
    53  		ec.Addf("makeCommitLoggerThunk cannot be nil")
    54  	}
    55  
    56  	if c.VectorForIDThunk == nil {
    57  		ec.Addf("vectorForIDThunk cannot be nil")
    58  	}
    59  
    60  	if c.DistanceProvider == nil {
    61  		ec.Addf("distancerProvider cannot be nil")
    62  	}
    63  
    64  	return ec.ToError()
    65  }