github.com/weaviate/weaviate@v1.24.6/modules/text2vec-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/text2vec-palm/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, titlePropertyValue string, 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 Texts: 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 Texts: 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 apiEndpoint string 56 projectID string 57 endpointID string 58 modelID string 59 properties interface{} 60 } 61 62 func (f fakeClassConfig) Class() map[string]interface{} { 63 classSettings := map[string]interface{}{ 64 "vectorizeClassName": f.vectorizeClassName, 65 } 66 if f.apiEndpoint != "" { 67 classSettings["apiEndpoint"] = f.apiEndpoint 68 } 69 if f.projectID != "" { 70 classSettings["projectID"] = f.projectID 71 } 72 if f.endpointID != "" { 73 classSettings["endpointID"] = f.endpointID 74 } 75 if f.modelID != "" { 76 classSettings["modelID"] = f.modelID 77 } 78 if f.properties != nil { 79 classSettings["properties"] = f.properties 80 } 81 for k, v := range f.classConfig { 82 classSettings[k] = v 83 } 84 return classSettings 85 } 86 87 func (f fakeClassConfig) ClassByModuleName(moduleName string) map[string]interface{} { 88 return f.Class() 89 } 90 91 func (f fakeClassConfig) Property(propName string) map[string]interface{} { 92 if propName == f.skippedProperty { 93 return map[string]interface{}{ 94 "skip": true, 95 } 96 } 97 if propName == f.excludedProperty { 98 return map[string]interface{}{ 99 "vectorizePropertyName": false, 100 } 101 } 102 if f.vectorizePropertyName { 103 return map[string]interface{}{ 104 "vectorizePropertyName": true, 105 } 106 } 107 return nil 108 } 109 110 func (f fakeClassConfig) Tenant() string { 111 return "" 112 } 113 114 func (f fakeClassConfig) TargetVector() string { 115 return "" 116 }