github.com/weaviate/weaviate@v1.24.6/modules/text2vec-cohere/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-cohere/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  		Vectors:    [][]float32{{0, 1, 2, 3}},
    32  		Dimensions: 4,
    33  		Text:       text,
    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  		Vectors:    [][]float32{{0.1, 1.1, 2.1, 3.1}},
    44  		Dimensions: 4,
    45  		Text:       text,
    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  	cohereModel  string
    57  	truncateType string
    58  	baseURL      string
    59  }
    60  
    61  func (f fakeClassConfig) Class() map[string]interface{} {
    62  	classSettings := map[string]interface{}{
    63  		"vectorizeClassName": f.vectorizeClassName,
    64  		"model":              f.cohereModel,
    65  		"truncate":           f.truncateType,
    66  		"baseURL":            f.baseURL,
    67  	}
    68  	return classSettings
    69  }
    70  
    71  func (f fakeClassConfig) ClassByModuleName(moduleName string) map[string]interface{} {
    72  	return f.classConfig
    73  }
    74  
    75  func (f fakeClassConfig) Property(propName string) map[string]interface{} {
    76  	if propName == f.skippedProperty {
    77  		return map[string]interface{}{
    78  			"skip": true,
    79  		}
    80  	}
    81  	if propName == f.excludedProperty {
    82  		return map[string]interface{}{
    83  			"vectorizePropertyName": false,
    84  		}
    85  	}
    86  	if f.vectorizePropertyName {
    87  		return map[string]interface{}{
    88  			"vectorizePropertyName": true,
    89  		}
    90  	}
    91  	return nil
    92  }
    93  
    94  func (f fakeClassConfig) Tenant() string {
    95  	return ""
    96  }
    97  
    98  func (f fakeClassConfig) TargetVector() string {
    99  	return ""
   100  }