github.com/weaviate/weaviate@v1.24.6/adapters/repos/db/inverted/config_update.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 inverted
    13  
    14  import (
    15  	"github.com/pkg/errors"
    16  	"github.com/weaviate/weaviate/entities/models"
    17  )
    18  
    19  func ValidateUserConfigUpdate(initial, updated *models.InvertedIndexConfig) error {
    20  	if updated.CleanupIntervalSeconds < 0 {
    21  		return errors.Errorf("cleanup interval seconds must be > 0")
    22  	}
    23  
    24  	err := validateBM25ConfigUpdate(initial, updated)
    25  	if err != nil {
    26  		return err
    27  	}
    28  
    29  	err = validateInvertedIndexConfigUpdate(initial, updated)
    30  	if err != nil {
    31  		return err
    32  	}
    33  
    34  	err = validateStopwordsConfigUpdate(initial, updated)
    35  	if err != nil {
    36  		return err
    37  	}
    38  
    39  	return nil
    40  }
    41  
    42  func validateBM25ConfigUpdate(initial, updated *models.InvertedIndexConfig) error {
    43  	if updated.Bm25 == nil {
    44  		updated.Bm25 = &models.BM25Config{
    45  			K1: initial.Bm25.K1,
    46  			B:  initial.Bm25.B,
    47  		}
    48  		return nil
    49  	}
    50  
    51  	err := validateBM25Config(updated.Bm25)
    52  	if err != nil {
    53  		return err
    54  	}
    55  
    56  	return nil
    57  }
    58  
    59  func validateInvertedIndexConfigUpdate(initial, updated *models.InvertedIndexConfig) error {
    60  	if updated.IndexPropertyLength != initial.IndexPropertyLength {
    61  		return errors.New("IndexPropertyLength cannot be changed when updating a schema")
    62  	}
    63  
    64  	if updated.IndexNullState != initial.IndexNullState {
    65  		return errors.New("IndexNullState cannot be changed when updating a schema")
    66  	}
    67  
    68  	return nil
    69  }
    70  
    71  func validateStopwordsConfigUpdate(initial, updated *models.InvertedIndexConfig) error {
    72  	if updated.Stopwords == nil {
    73  		updated.Stopwords = &models.StopwordConfig{
    74  			Preset:    initial.Stopwords.Preset,
    75  			Additions: initial.Stopwords.Additions,
    76  			Removals:  initial.Stopwords.Removals,
    77  		}
    78  		return nil
    79  	}
    80  
    81  	err := validateStopwordConfig(updated.Stopwords)
    82  	if err != nil {
    83  		return err
    84  	}
    85  
    86  	return nil
    87  }