Repository: weaviate/weaviate (Go)

Issue:
[feature] Optionally provide Huggingface endpoint URL/path in `text2vec-huggingface`
The [Huggingface endpoint in t2v-hf](https://github.com/weaviate/weaviate/blob/abf30eac8656cf3bf1b471d9eb1416695777a53d/modules/text2vec-huggingface/clients/url.go) is hardcoded to the public HF endpoint.

Azure (and possibly others) offer [hosted endpoints](https://huggingface.co/blog/hugging-face-endpoints-on-azure), so making this URL and path optionally user-configurable would allow arbitrary deployment endpoints to be used.

This would provide appreciable cost and security benefits for users.

@hsm207 


Discussion: Also, See [link](https://weaviate-org.slack.com/archives/C039ZLWKHB7/p1674833800959789).


Also, see the service's [documentation ](https://azure.microsoft.com/en-us/solutions/hugging-face-on-azure/#overview)on azure.
I would like to take up this issue
cc: @etiennedi @kcm 
cc: @hsm207 
Pushed the commit for further review.
@TheAthleticCoder have you at least manually tested the new setting using azure's hosted endpoint?



Fix (patch):
diff --git a/modules/text2vec-huggingface/clients/url.go b/modules/text2vec-huggingface/clients/url.go
deleted file mode 100644
index 98fe61df067..00000000000
--- a/modules/text2vec-huggingface/clients/url.go
+++ /dev/null
@@ -1,34 +0,0 @@
-//                           _       _
-// __      _____  __ ___   ___  __ _| |_ ___
-// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
-//  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
-//   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
-//
-//  Copyright © 2016 - 2023 Weaviate B.V. All rights reserved.
-//
-//  CONTACT: hello@weaviate.io
-//
-
-package clients
-
-import "fmt"
-
-type huggingFaceUrlBuilder struct {
-	origin   string
-	pathMask string
-}
-
-func newHuggingFaceUrlBuilder() *huggingFaceUrlBuilder {
-	return &huggingFaceUrlBuilder{
-		origin:   "https://api-inference.huggingface.co",
-		pathMask: "/pipeline/feature-extraction/%s",
-	}
-}
-
-func (o *huggingFaceUrlBuilder) url(model string) string {
-	return fmt.Sprintf("%s%s", o.origin, o.getPath(model))
-}
-
-func (o *huggingFaceUrlBuilder) getPath(model string) string {
-	return fmt.Sprintf(o.pathMask, model)
-}
diff --git a/modules/text2vec-huggingface/clients/vectorizer.go b/modules/text2vec-huggingface/clients/vectorizer.go
index 42047d88821..94d71e92984 100644
--- a/modules/text2vec-huggingface/clients/vectorizer.go
+++ b/modules/text2vec-huggingface/clients/vectorizer.go
@@ -24,6 +24,11 @@ import (
 	"github.com/weaviate/weaviate/modules/text2vec-huggingface/ent"
 )
 
+const (
+	DefaultOrigin = "https://api-inference.huggingface.co"
+	DefaultPath   = "pipeline/feature-extraction"
+)
+
 type embeddingsRequest struct {
 	Inputs  []string `json:"inputs"`
 	Options *options `json:"options,omitempty"`
@@ -48,7 +53,6 @@ type huggingFaceApiError struct {
 type vectorizer struct {
 	apiKey                string
 	httpClient            *http.Client
-	urlBuilder            *huggingFaceUrlBuilder
 	bertEmbeddingsDecoder *bertEmbeddingsDecoder
 	logger                logrus.FieldLogger
 }
@@ -57,7 +61,6 @@ func New(apiKey string, logger logrus.FieldLogger) *vectorizer {
 	return &vectorizer{
 		apiKey:                apiKey,
 		httpClient:            &http.Client{},
-		urlBuilder:            newHuggingFaceUrlBuilder(),
 		bertEmbeddingsDecoder: newBertEmbeddingsDecoder(),
 		logger:                logger,
 	}
@@ -185,17 +188,6 @@ func (v *vectorizer) getApiKey(ctx context.Context) string {
 	return ""
 }
 
-func (v *vectorizer) getURL(config ent.VectorizationConfig) string {
-	if config.EndpointURL != "" {
-		return config.EndpointURL
-	}
-	return v.url(config.Model)
-}
-
-func (v *vectorizer) url(model string) string {
-	return v.urlBuilder.url(model)
-}
-
 func (v *vectorizer) getOptions(config ent.VectorizationConfig) options {
 	return options{
 		WaitForModel: config.WaitForModel,
@@ -203,3 +195,11 @@ func (v *vectorizer) getOptions(config ent.VectorizationConfig) options {
 		UseCache:     config.UseCache,
 	}
 }
+
+func (v *vectorizer) getURL(config ent.VectorizationConfig) string {
+	if config.EndpointURL != "" {
+		return config.EndpointURL
+	}
+
+	return fmt.Sprintf("%s/%s/%s", DefaultOrigin, DefaultPath, config.Model)
+}