Find answers from the community

Updated 2 months ago

how can I use an embedding model like embed_model = HuggingFaceEmbeddings( model_name=

how can I use an embedding model like embed_model = HuggingFaceEmbeddings(
model_name="sentence-transformers/all-mpnet-base-v2"
) to directly generate an embedding for a text snippet?
k
L
W
4 comments
Please stand by @chsurf as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
To generate an embedding for a text snippet using the HuggingFaceEmbeddings model, you would first need to initialize the model with the desired model name. After that, you can use the get_text_embedding method to generate the embedding for your text snippet. However, the exact method to generate the embedding is not provided in the extracts.

Here is an example of how you might initialize the model:

Plain Text
from langchain.embeddings import HuggingFaceEmbeddings
from llama_index import ServiceContext, set_global_service_context

embed_model = HuggingFaceEmbeddings(
    model_name="sentence-transformers/all-mpnet-base-v2"
)

service_context = ServiceContext.from_defaults(embed_model=embed_model)

# optionally set a global service context
set_global_service_context(service_context)


Unfortunately, the extracts do not provide the exact method to generate the embedding for a text snippet using this model. You might want to refer to the official documentation or source code of the HuggingFaceEmbeddings class for more details.

Sources:
  • Langchain Embeddings ()
  • Github Source Code ()
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
embed_model.get_text_embedding(text)
Add a reply
Sign up and join the conversation on Discord