Sentence Transformers on Hugging Face
Hugging Face sentence-transformers is a Python framework for state-of-the-art sentence, text and image embeddings. You can use these embedding models from the
HuggingFaceEmbeddings
class.
%pip install --upgrade --quiet langchain-huggingface
from langchain_huggingface import HuggingFaceEmbeddings
embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
text = "This is a test document."
query_result = embeddings.embed_query(text)
# show only the first 100 characters of the stringified vector
print(str(query_result)[:100] + "...")
API Reference:HuggingFaceEmbeddings
[-0.0383385568857193, 0.12346469610929489, -0.028642987832427025, 0.05365273728966713, 0.00884537026...
doc_result = embeddings.embed_documents([text, "This is not a test document."])
print(str(doc_result)[:100] + "...")
[[-0.038338493555784225, 0.12346471846103668, -0.028642840683460236, 0.05365276336669922, 0.00884535...