github.com/weaviate/weaviate@v1.24.6/usecases/traverser/traverser_get.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 traverser
    13  
    14  import (
    15  	"context"
    16  	"time"
    17  
    18  	"github.com/weaviate/weaviate/entities/dto"
    19  	enterrors "github.com/weaviate/weaviate/entities/errors"
    20  	"github.com/weaviate/weaviate/entities/models"
    21  )
    22  
    23  func (t *Traverser) GetClass(ctx context.Context, principal *models.Principal,
    24  	params dto.GetParams,
    25  ) ([]interface{}, error) {
    26  	before := time.Now()
    27  
    28  	ok := t.ratelimiter.TryInc()
    29  	if !ok {
    30  		// we currently have no concept of error status code or typed errors in
    31  		// GraphQL, so there is no other way then to send a message containing what
    32  		// we want to convey
    33  		return nil, enterrors.NewErrRateLimit()
    34  	}
    35  
    36  	defer t.ratelimiter.Dec()
    37  
    38  	t.metrics.QueriesGetInc(params.ClassName)
    39  	defer t.metrics.QueriesGetDec(params.ClassName)
    40  	defer t.metrics.QueriesObserveDuration(params.ClassName, before.UnixMilli())
    41  
    42  	err := t.authorizer.Authorize(principal, "get", "traversal/*")
    43  	if err != nil {
    44  		return nil, err
    45  	}
    46  
    47  	unlock, err := t.locks.LockConnector()
    48  	if err != nil {
    49  		return nil, enterrors.NewErrLockConnector(err)
    50  	}
    51  	defer unlock()
    52  
    53  	certainty := ExtractCertaintyFromParams(params)
    54  	if certainty != 0 || params.AdditionalProperties.Certainty {
    55  		// if certainty is provided as input, we must ensure
    56  		// that the vector index is configured to use cosine
    57  		// distance
    58  		if err := t.validateGetDistanceParams(params); err != nil {
    59  			return nil, err
    60  		}
    61  	}
    62  
    63  	return t.explorer.GetClass(ctx, params)
    64  }