github.com/weaviate/weaviate@v1.24.6/test/acceptance/graphql_resolvers/local_get_with_custom_vectors_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  	"fmt"
    16  	"testing"
    17  
    18  	graphqlhelper "github.com/weaviate/weaviate/test/helper/graphql"
    19  
    20  	"github.com/stretchr/testify/assert"
    21  	"github.com/weaviate/weaviate/test/helper"
    22  )
    23  
    24  func gettingObjectsWithCustomVectors(t *testing.T) {
    25  	t.Run("through Get {}", func(t *testing.T) {
    26  		query := `
    27  		{
    28  			Get {
    29  				CustomVectorClass(nearVector:{vector:[1,1,1]}) {
    30  					_additional {
    31  						id
    32  					}
    33  				}
    34  			}
    35  		}
    36  		`
    37  		result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query)
    38  		results := result.Get("Get", "CustomVectorClass").AsSlice()
    39  
    40  		expected := []interface{}{
    41  			map[string]interface{}{"_additional": map[string]interface{}{"id": string(cvc1)}},
    42  			map[string]interface{}{"_additional": map[string]interface{}{"id": string(cvc2)}},
    43  			map[string]interface{}{"_additional": map[string]interface{}{"id": string(cvc3)}},
    44  		}
    45  
    46  		assert.Equal(t, expected, results)
    47  	})
    48  }
    49  
    50  func exploreObjectsWithCustomVectors(t *testing.T) {
    51  	t.Run("through Explore {}", func(t *testing.T) {
    52  		query := `
    53  		{
    54  			Explore(nearVector: {vector:[1,1,1]}) {
    55  				beacon
    56  			}
    57  		}
    58  		`
    59  		result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query)
    60  		results := result.Get("Explore").AsSlice()
    61  
    62  		expected := []interface{}{
    63  			map[string]interface{}{"beacon": fmt.Sprintf("weaviate://localhost/CustomVectorClass/%s", cvc1)},
    64  			map[string]interface{}{"beacon": fmt.Sprintf("weaviate://localhost/CustomVectorClass/%s", cvc2)},
    65  			map[string]interface{}{"beacon": fmt.Sprintf("weaviate://localhost/CustomVectorClass/%s", cvc3)},
    66  		}
    67  
    68  		assert.Equal(t, expected, results)
    69  	})
    70  }