github.com/weaviate/weaviate@v1.24.6/modules/multi2vec-palm/vectorizer/fakes_for_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 vectorizer
    13  
    14  import (
    15  	"context"
    16  
    17  	"github.com/weaviate/weaviate/modules/multi2vec-palm/ent"
    18  )
    19  
    20  type builder struct {
    21  	fakeClassConfig *fakeClassConfig
    22  }
    23  
    24  func newConfigBuilder() *builder {
    25  	return &builder{
    26  		fakeClassConfig: &fakeClassConfig{config: map[string]interface{}{}},
    27  	}
    28  }
    29  
    30  func (b *builder) addSetting(name string, value interface{}) *builder {
    31  	b.fakeClassConfig.config[name] = value
    32  	return b
    33  }
    34  
    35  func (b *builder) addWeights(textWeights, imageWeights []interface{}) *builder {
    36  	if textWeights != nil || imageWeights != nil {
    37  		weightSettings := map[string]interface{}{}
    38  		if textWeights != nil {
    39  			weightSettings["textFields"] = textWeights
    40  		}
    41  		if imageWeights != nil {
    42  			weightSettings["imageFields"] = imageWeights
    43  		}
    44  		b.fakeClassConfig.config["weights"] = weightSettings
    45  	}
    46  	return b
    47  }
    48  
    49  func (b *builder) build() *fakeClassConfig {
    50  	return b.fakeClassConfig
    51  }
    52  
    53  type fakeClassConfig struct {
    54  	config map[string]interface{}
    55  }
    56  
    57  func (c fakeClassConfig) Class() map[string]interface{} {
    58  	return c.config
    59  }
    60  
    61  func (c fakeClassConfig) ClassByModuleName(moduleName string) map[string]interface{} {
    62  	return c.config
    63  }
    64  
    65  func (c fakeClassConfig) Property(propName string) map[string]interface{} {
    66  	return c.config
    67  }
    68  
    69  func (f fakeClassConfig) Tenant() string {
    70  	return ""
    71  }
    72  
    73  func (f fakeClassConfig) TargetVector() string {
    74  	return ""
    75  }
    76  
    77  type fakeClient struct{}
    78  
    79  func (c *fakeClient) Vectorize(ctx context.Context,
    80  	texts, images, videos []string, config ent.VectorizationConfig,
    81  ) (*ent.VectorizationResult, error) {
    82  	result := &ent.VectorizationResult{
    83  		TextVectors:  [][]float32{{1.0, 2.0, 3.0, 4.0, 5.0}},
    84  		ImageVectors: [][]float32{{10.0, 20.0, 30.0, 40.0, 50.0}},
    85  	}
    86  	return result, nil
    87  }