model2vec
Overview
Model2Vec is a technique to turn any sentence transformer into a really small static model model2vec can be used to generate embeddings.
Setup
pip install -U langchain-community
Instantiation
Ensure that model2vec
is installed
pip install -U model2vec
Indexing and Retrieval
from langchain_community.embeddings import 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 of 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 Reference
For more information check out the model2vec github repo
Related
- Embedding model conceptual guide
- Embedding model how-to guides