can I use api to get the embeddings?

#72
by starmaq - opened

rn it seems like the api can just return the similarity score, not the embeddings

Hi there, this example in the Sentence-transformers official documentation may be helpful for you.

from sentence_transformers import SentenceTransformer

# 1. Load a pretrained Sentence Transformer model
model = SentenceTransformer("all-MiniLM-L6-v2")

# The sentences to encode
sentences = [
    "The weather is lovely today.",
    "It's so sunny outside!",
    "He drove to the stadium.",
]

# 2. Calculate embeddings by calling model.encode()
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 384]

# 3. Calculate the embedding similarities
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[1.0000, 0.6660, 0.1046],
#         [0.6660, 1.0000, 0.1411],
#         [0.1046, 0.1411, 1.0000]])

I have the same request: use the API to encode the embeddings. Here, the solution computes similarities.
To be more specific, i would like that, in the provided example https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/discussions/72?inference_api=true, we call request.post(API_URL, headers=headers, json=payload) where payload is a simple text. The expected result would be a list of vectors like model.encode(sentences) would do.

Looks like it is working! Could you explain where you have find the documentation explaining we have to use this API_URL? It would be useful if we have similar needs in the future.
Thank you.

@incognitoluke I'm trying to add the API on Ragflow but keep getting the error : Fail to access embedding model(sentence-transformers/all-MiniLM-L6-v2___HuggingFace).Error: 429 - {"error":"Please log in or use a HF access token"}

Sign up or log in to comment