github.com/weaviate/weaviate@v1.24.6/modules/multi2vec-clip/vectorizer/texts.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  
    17  	"github.com/pkg/errors"
    18  	"github.com/weaviate/weaviate/entities/moduletools"
    19  	"github.com/weaviate/weaviate/modules/multi2vec-clip/ent"
    20  	libvectorizer "github.com/weaviate/weaviate/usecases/vectorizer"
    21  )
    22  
    23  func (v *Vectorizer) Texts(ctx context.Context, inputs []string,
    24  	cfg moduletools.ClassConfig,
    25  ) ([]float32, error) {
    26  	res, err := v.client.Vectorize(ctx, inputs, []string{}, v.getVectorizationConfig(cfg))
    27  	if err != nil {
    28  		return nil, errors.Wrap(err, "remote client vectorize")
    29  	}
    30  	if len(inputs) != len(res.TextVectors) {
    31  		return nil, errors.New("inputs are not equal to vectors returned")
    32  	}
    33  	return libvectorizer.CombineVectors(res.TextVectors), nil
    34  }
    35  
    36  func (v *Vectorizer) getVectorizationConfig(cfg moduletools.ClassConfig) ent.VectorizationConfig {
    37  	return ent.VectorizationConfig{InferenceURL: NewClassSettings(cfg).InferenceURL()}
    38  }