Change HF embedding library (#1440)
This commit is contained in:
2
Makefile
2
Makefile
@@ -11,7 +11,7 @@ install:
|
|||||||
|
|
||||||
install_all:
|
install_all:
|
||||||
poetry install --all-extras
|
poetry install --all-extras
|
||||||
poetry run pip install pinecone-text pinecone-client langchain-anthropic "unstructured[local-inference, all-docs]" ollama deepgram-sdk==3.2.7
|
poetry run pip install pinecone-text pinecone-client langchain-anthropic "unstructured[local-inference, all-docs]" ollama deepgram-sdk==3.2.7 langchain-huggingface
|
||||||
|
|
||||||
install_es:
|
install_es:
|
||||||
poetry install --extras elasticsearch
|
poetry install --extras elasticsearch
|
||||||
|
|||||||
@@ -2,7 +2,14 @@ import os
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from langchain_community.embeddings import HuggingFaceEmbeddings
|
from langchain_community.embeddings import HuggingFaceEmbeddings
|
||||||
from langchain_community.embeddings.huggingface import HuggingFaceInferenceAPIEmbeddings
|
|
||||||
|
try:
|
||||||
|
from langchain_huggingface import HuggingFaceEndpointEmbeddings
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
raise ModuleNotFoundError(
|
||||||
|
"The required dependencies for HuggingFaceHub are not installed."
|
||||||
|
"Please install with `pip install langchain_huggingface`"
|
||||||
|
) from None
|
||||||
|
|
||||||
from embedchain.config import BaseEmbedderConfig
|
from embedchain.config import BaseEmbedderConfig
|
||||||
from embedchain.embedder.base import BaseEmbedder
|
from embedchain.embedder.base import BaseEmbedder
|
||||||
@@ -19,10 +26,9 @@ class HuggingFaceEmbedder(BaseEmbedder):
|
|||||||
"Please set the HUGGINGFACE_ACCESS_TOKEN environment variable or pass API Key in the config."
|
"Please set the HUGGINGFACE_ACCESS_TOKEN environment variable or pass API Key in the config."
|
||||||
)
|
)
|
||||||
|
|
||||||
embeddings = HuggingFaceInferenceAPIEmbeddings(
|
embeddings = HuggingFaceEndpointEmbeddings(
|
||||||
model_name=self.config.model,
|
model=self.config.endpoint,
|
||||||
api_url=self.config.endpoint,
|
huggingfacehub_api_token=self.config.api_key or os.getenv("HUGGINGFACE_ACCESS_TOKEN"),
|
||||||
api_key=self.config.api_key or os.getenv("HUGGINGFACE_ACCESS_TOKEN"),
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
embeddings = HuggingFaceEmbeddings(model_name=self.config.model)
|
embeddings = HuggingFaceEmbeddings(model_name=self.config.model)
|
||||||
|
|||||||
Reference in New Issue
Block a user