github.com/weaviate/weaviate@v1.24.6/test/modules/text2vec-transformers/transformers_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 test
    13  
    14  import (
    15  	"os"
    16  	"testing"
    17  
    18  	"github.com/stretchr/testify/assert"
    19  	"github.com/weaviate/weaviate/test/helper"
    20  	graphqlhelper "github.com/weaviate/weaviate/test/helper/graphql"
    21  	"github.com/weaviate/weaviate/test/helper/sample-schema/books"
    22  )
    23  
    24  func Test_T2VTransformers(t *testing.T) {
    25  	helper.SetupClient(os.Getenv(weaviateEndpoint))
    26  	booksClass := books.ClassTransformersVectorizer()
    27  	helper.CreateClass(t, booksClass)
    28  	defer helper.DeleteClass(t, booksClass.Class)
    29  
    30  	t.Run("add data to Books schema", func(t *testing.T) {
    31  		for _, book := range books.Objects() {
    32  			helper.CreateObject(t, book)
    33  			helper.AssertGetObjectEventually(t, book.Class, book.ID)
    34  		}
    35  	})
    36  
    37  	t.Run("query Books data with nearText", func(t *testing.T) {
    38  		result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, `
    39  			{
    40  				Get {
    41  					Books(
    42  						nearText: {
    43  							concepts: ["Frank Herbert"]
    44  							distance: 0.3
    45  						}
    46  					){
    47  						title
    48  					}
    49  				}
    50  			}
    51  		`)
    52  		books := result.Get("Get", "Books").AsSlice()
    53  		expected := []interface{}{
    54  			map[string]interface{}{"title": "Dune"},
    55  		}
    56  		assert.ElementsMatch(t, expected, books)
    57  	})
    58  }