github.com/weaviate/weaviate@v1.24.6/modules/text2vec-aws/vectorizer/texts_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  	"strings"
    17  	"testing"
    18  
    19  	"github.com/stretchr/testify/assert"
    20  	"github.com/stretchr/testify/require"
    21  )
    22  
    23  // as used in the nearText searcher
    24  func TestVectorizingTexts(t *testing.T) {
    25  	type testCase struct {
    26  		name               string
    27  		input              []string
    28  		expectedClientCall string
    29  		expectedService    string
    30  		expectedRegion     string
    31  		expectedModel      string
    32  	}
    33  
    34  	tests := []testCase{
    35  		{
    36  			name:               "single word",
    37  			input:              []string{"hello"},
    38  			expectedClientCall: "hello",
    39  			expectedService:    "bedrock",
    40  		},
    41  		{
    42  			name:               "multiple words",
    43  			input:              []string{"hello world, this is me!"},
    44  			expectedClientCall: "hello world, this is me!",
    45  			expectedService:    "bedrock",
    46  		},
    47  		{
    48  			name:               "multiple sentences (joined with a dot)",
    49  			input:              []string{"this is sentence 1", "and here's number 2"},
    50  			expectedClientCall: "and here's number 2",
    51  			expectedService:    "bedrock",
    52  		},
    53  		{
    54  			name:               "multiple sentences already containing a dot",
    55  			input:              []string{"this is sentence 1.", "and here's number 2"},
    56  			expectedClientCall: "and here's number 2",
    57  			expectedService:    "bedrock",
    58  		},
    59  		{
    60  			name:               "multiple sentences already containing a question mark",
    61  			input:              []string{"this is sentence 1?", "and here's number 2"},
    62  			expectedClientCall: "and here's number 2",
    63  			expectedService:    "bedrock",
    64  		},
    65  		{
    66  			name:               "multiple sentences already containing an exclamation mark",
    67  			input:              []string{"this is sentence 1!", "and here's number 2"},
    68  			expectedClientCall: "and here's number 2",
    69  			expectedService:    "bedrock",
    70  		},
    71  		{
    72  			name:               "multiple sentences already containing comma",
    73  			input:              []string{"this is sentence 1,", "and here's number 2"},
    74  			expectedClientCall: "and here's number 2",
    75  			expectedService:    "bedrock",
    76  		},
    77  	}
    78  
    79  	for _, test := range tests {
    80  		t.Run(test.name, func(t *testing.T) {
    81  			client := &fakeClient{}
    82  
    83  			v := New(client)
    84  
    85  			settings := &fakeClassConfig{
    86  				service: "bedrock",
    87  				region:  "",
    88  				model:   "",
    89  			}
    90  			vec, err := v.Texts(context.Background(), test.input, settings)
    91  
    92  			require.Nil(t, err)
    93  			assert.Equal(t, []float32{0.1, 1.1, 2.1, 3.1}, vec)
    94  			assert.Equal(t, test.expectedClientCall, strings.Join(client.lastInput, ","))
    95  			assert.Equal(t, test.expectedService, client.lastConfig.Service)
    96  			assert.Equal(t, test.expectedRegion, client.lastConfig.Region)
    97  			assert.Equal(t, test.expectedModel, client.lastConfig.Model)
    98  		})
    99  	}
   100  }