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 repo