github.com/weaviate/weaviate@v1.24.6/modules/text2vec-huggingface/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-huggingface/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, 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, 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 model, passageModel, queryModel string 57 waitForModel, useGPU, useCache bool 58 endpointURL string 59 } 60 61 func (f fakeClassConfig) Class() map[string]interface{} { 62 if len(f.classConfig) > 0 { 63 return f.classConfig 64 } 65 classSettings := map[string]interface{}{ 66 "vectorizeClassName": f.vectorizeClassName, 67 "model": f.model, 68 "passageModel": f.passageModel, 69 "queryModel": f.queryModel, 70 "waitForModel": f.waitForModel, 71 "useGPU": f.useGPU, 72 "useCache": f.useCache, 73 "endpointURL": f.endpointURL, 74 } 75 return classSettings 76 } 77 78 func (f fakeClassConfig) ClassByModuleName(moduleName string) map[string]interface{} { 79 return f.classConfig 80 } 81 82 func (f fakeClassConfig) Property(propName string) map[string]interface{} { 83 if propName == f.skippedProperty { 84 return map[string]interface{}{ 85 "skip": true, 86 } 87 } 88 if propName == f.excludedProperty { 89 return map[string]interface{}{ 90 "vectorizePropertyName": false, 91 } 92 } 93 if f.vectorizePropertyName { 94 return map[string]interface{}{ 95 "vectorizePropertyName": true, 96 } 97 } 98 return nil 99 } 100 101 func (f fakeClassConfig) Tenant() string { 102 return "" 103 } 104 105 func (f fakeClassConfig) TargetVector() string { 106 return "" 107 }