6大核心模块(Modules)
示例
句子嵌入(Sentence Transformers)

LangChain

SentenceTransformers

SentenceTransformers (opens in a new tab)嵌入是使用HuggingFaceEmbeddings集成调用的。 我们还为那些更熟悉直接使用该包的用户添加了SentenceTransformerEmbeddings的别名。

SentenceTransformers是一个Python软件包,它可以生成文本和图像嵌入,源自于Sentence-BERT (opens in a new tab)

!pip install sentence_transformers > /dev/null
 
[notice] A new release of pip is available: 23.0.1 -> 23.1.1
[notice] To update, run: pip install --upgrade pip
 
from langchain.embeddings import HuggingFaceEmbeddings, SentenceTransformerEmbeddings 
 
embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
# Equivalent to SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")
 
text = "This is a test document."
 
query_result = embeddings.embed_query(text)
 
doc_result = embeddings.embed_documents([text, "This is not a test document."])