From 5b5ea2af30ed6046fb5b68aecfdea6e1f52856cb Mon Sep 17 00:00:00 2001 From: Tom Aarsen <37621491+tomaarsen@users.noreply.github.com> Date: Fri, 24 May 2024 17:21:03 +0200 Subject: [PATCH] docs: Add explanation on how to use Hugging Face embeddings (#22118) - **Description:** I've added a tab on embedding text with LangChain using Hugging Face models to here: https://python.langchain.com/v0.2/docs/how_to/embed_text/. HF was mentioned in the running text, but not in the tabs, which I thought was odd. - **Issue:** N/A - **Dependencies:** N/A - **Twitter handle:** No need, this is tiny :) Also, I had a ton of issues with the poetry docs/lint install, so I haven't linted this. Apologies for that. cc @Jofthomas - Tom Aarsen --- docs/docs/how_to/embed_text.mdx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/docs/how_to/embed_text.mdx b/docs/docs/how_to/embed_text.mdx index 1be7b054d1e..ed75a36a624 100644 --- a/docs/docs/how_to/embed_text.mdx +++ b/docs/docs/how_to/embed_text.mdx @@ -75,6 +75,31 @@ Otherwise you can initialize without any params: from langchain_cohere import CohereEmbeddings embeddings_model = CohereEmbeddings() +``` + + + + +To start we'll need to install the Hugging Face partner package: + +```bash +pip install langchain-huggingface +``` + +You can then load any [Sentence Transformers model](https://huggingface.co/models?library=sentence-transformers) from the Hugging Face Hub. + +```python +from langchain_huggingface import HuggingFaceEmbeddings + +embeddings_model = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2") +``` + +You can also leave the `model_name` blank to use the default [sentence-transformers/all-mpnet-base-v2](https://huggingface.co/sentence-transformers/all-mpnet-base-v2) model. + +```python +from langchain_huggingface import HuggingFaceEmbeddings + +embeddings_model = HuggingFaceEmbeddings() ```