Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
OurBuilding Ambient Agents with LangGraph course is now available on LangChain Academy!
Open In ColabOpen on GitHub

model2vec

Model2Vec is a technique to turn any sentence transformer into a really small static modelmodel2vec can be used to generate embeddings.

Setup

pip install -U langchain-community

Instantiation

Ensure thatmodel2vec is installed

pip install -U model2vec

Indexing and Retrieval

from langchain_community.embeddingsimport Model2vecEmbeddings
API Reference: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])

Direct Usage

Here's how you would directly make use ofmodel2vec

from model2vecimport 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 Reference

For more information check out the model2vec githubrepo

Related


[8]ページ先頭

©2009-2025 Movatter.jp