github.com/weaviate/weaviate@v1.24.6/usecases/modulecomponents/arguments/nearThermal/searcher.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 nearThermal
    13  
    14  import (
    15  	"context"
    16  
    17  	"github.com/pkg/errors"
    18  	"github.com/weaviate/weaviate/entities/modulecapabilities"
    19  	"github.com/weaviate/weaviate/entities/moduletools"
    20  )
    21  
    22  type Searcher struct {
    23  	vectorizer bindVectorizer
    24  }
    25  
    26  func NewSearcher(vectorizer bindVectorizer) *Searcher {
    27  	return &Searcher{vectorizer}
    28  }
    29  
    30  type bindVectorizer interface {
    31  	VectorizeThermal(ctx context.Context, thermal string, cfg moduletools.ClassConfig) ([]float32, error)
    32  }
    33  
    34  func (s *Searcher) VectorSearches() map[string]modulecapabilities.VectorForParams {
    35  	vectorSearches := map[string]modulecapabilities.VectorForParams{}
    36  	vectorSearches["nearThermal"] = s.vectorForNearThermalParam
    37  	return vectorSearches
    38  }
    39  
    40  func (s *Searcher) vectorForNearThermalParam(ctx context.Context, params interface{},
    41  	className string,
    42  	findVectorFn modulecapabilities.FindVectorFn,
    43  	cfg moduletools.ClassConfig,
    44  ) ([]float32, error) {
    45  	return s.vectorFromNearThermalParam(ctx, params.(*NearThermalParams), className, findVectorFn, cfg)
    46  }
    47  
    48  func (s *Searcher) vectorFromNearThermalParam(ctx context.Context,
    49  	params *NearThermalParams, className string, findVectorFn modulecapabilities.FindVectorFn,
    50  	cfg moduletools.ClassConfig,
    51  ) ([]float32, error) {
    52  	// find vector for given search query
    53  	vector, err := s.vectorizer.VectorizeThermal(ctx, params.Thermal, cfg)
    54  	if err != nil {
    55  		return nil, errors.Errorf("vectorize thermal: %v", err)
    56  	}
    57  
    58  	return vector, nil
    59  }