eta.embedding.HFEmbedder

class HFEmbedder(host='https://api-inference.huggingface.co/pipeline/feature-extraction/', model='sentence-transformers/all-distilroberta-v1')[source]

Bases: Embedder

An embedder that uses HuggingFace’s API to compute embeddings.

Parameters:
  • host (str) – The URL of the embedding API to use.

  • model (str) – The name of the specific model to use.

host
Type:

str

model
Type:

str

url
Type:

str

header
Type:

dict

Methods

embed

Embed a text or list of texts.

embed_api

query_api

score

Score a set of documents relative to a text.

embed(texts)[source]

Embed a text or list of texts.

Parameters:

texts (str or list[str]) – Either a single text string or a list of text strings to embed.

Returns:

The embedding or embeddings computed from the input.

Return type:

list[float] or list[list[float]]

score(text, documents, embeddings=[])

Score a set of documents relative to a text.

Parameters:
  • text (str) – A query text to use in computing scores for each document.

  • documents (list[str]) – A list of documents to score.

  • embeddings (list[list[float]], optional) – If embeddings for the documents have already been precomputed, passing the embeddings as an argument will bypass creating new embeddings for the documents.

Returns:

Scores for each document.

Return type:

list[float]