model2vec
概述
Model2Vec 是一种将任何句子转换器转换为非常小的静态模型的技术。 model2vec 可用于生成嵌入。
设置
pip install -U langchain-community
实例化
确保已安装 model2vec
pip install -U model2vec
索引和检索
from langchain_community.embeddings import Model2vecEmbeddings
API 参考:Model2vecEmbeddings
embeddings = Model2vecEmbeddings("minishlab/potion-base-8M")
query_text = "This is a test query."
query_result = embeddings.embed_query(query_text)
document_text = "This is a test document."
document_result = embeddings.embed_documents([document_text])
直接使用
以下是如何直接使用 model2vec
from model2vec import StaticModel
# Load a model from the HuggingFace hub (in this case the potion-base-8M model)
model = StaticModel.from_pretrained("minishlab/potion-base-8M")
# Make embeddings
embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."])
# Make sequences of token embeddings
token_embeddings = model.encode_as_sequence(["It's dangerous to go alone!", "It's a secret to everybody."])
API 参考
有关更多信息,请查看 model2vec github 存储库