github.com/weaviate/weaviate@v1.24.6/modules/text2vec-aws/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/text2vec-aws/ent"
    18  )
    19  
    20  type fakeClient struct {
    21  	lastInput  []string
    22  	lastConfig ent.VectorizationConfig
    23  }
    24  
    25  func (c *fakeClient) Vectorize(ctx context.Context,
    26  	text []string, cfg ent.VectorizationConfig,
    27  ) (*ent.VectorizationResult, error) {
    28  	c.lastInput = text
    29  	c.lastConfig = cfg
    30  	return &ent.VectorizationResult{
    31  		Vector:     []float32{0, 1, 2, 3},
    32  		Dimensions: 4,
    33  		Text:       text[0],
    34  	}, nil
    35  }
    36  
    37  func (c *fakeClient) VectorizeQuery(ctx context.Context,
    38  	text []string, cfg ent.VectorizationConfig,
    39  ) (*ent.VectorizationResult, error) {
    40  	c.lastInput = text
    41  	c.lastConfig = cfg
    42  	return &ent.VectorizationResult{
    43  		Vector:     []float32{0.1, 1.1, 2.1, 3.1},
    44  		Dimensions: 4,
    45  		Text:       text[0],
    46  	}, nil
    47  }
    48  
    49  type fakeClassConfig struct {
    50  	classConfig           map[string]interface{}
    51  	vectorizeClassName    bool
    52  	vectorizePropertyName bool
    53  	skippedProperty       string
    54  	excludedProperty      string
    55  	// module specific settings
    56  	service       string
    57  	region        string
    58  	model         string
    59  	endpoint      string
    60  	targetModel   string
    61  	targetVariant string
    62  }
    63  
    64  func (f fakeClassConfig) Class() map[string]interface{} {
    65  	if len(f.classConfig) > 0 {
    66  		return f.classConfig
    67  	}
    68  	classSettings := map[string]interface{}{
    69  		"vectorizeClassName": f.vectorizeClassName,
    70  		"service":            f.service,
    71  		"region":             f.region,
    72  		"model":              f.model,
    73  		"endpoint":           f.endpoint,
    74  		"targetModel":        f.targetModel,
    75  		"targetVariant":      f.targetVariant,
    76  	}
    77  	return classSettings
    78  }
    79  
    80  func (f fakeClassConfig) ClassByModuleName(moduleName string) map[string]interface{} {
    81  	return f.classConfig
    82  }
    83  
    84  func (f fakeClassConfig) Property(propName string) map[string]interface{} {
    85  	if propName == f.skippedProperty {
    86  		return map[string]interface{}{
    87  			"skip": true,
    88  		}
    89  	}
    90  	if propName == f.excludedProperty {
    91  		return map[string]interface{}{
    92  			"vectorizePropertyName": false,
    93  		}
    94  	}
    95  	if f.vectorizePropertyName {
    96  		return map[string]interface{}{
    97  			"vectorizePropertyName": true,
    98  		}
    99  	}
   100  	return nil
   101  }
   102  
   103  func (f fakeClassConfig) Tenant() string {
   104  	return ""
   105  }
   106  
   107  func (f fakeClassConfig) TargetVector() string {
   108  	return ""
   109  }