Add HuggingFaceInferenceAPIEmbeddingsComponent class (#1431)
Adds a new HuggingFaceInferenceAPIEmbeddingsComponent component class <img width="658" alt="image" src="https://github.com/logspace-ai/langflow/assets/763757/175ff5ec-9ea4-4232-8009-63f022132c51">
This commit is contained in:
commit
620ef2b26a
2 changed files with 92 additions and 23 deletions
|
|
@ -0,0 +1,42 @@
|
||||||
|
from langflow import CustomComponent
|
||||||
|
from typing import Optional, Dict
|
||||||
|
from langchain_community.embeddings.huggingface import HuggingFaceInferenceAPIEmbeddings
|
||||||
|
|
||||||
|
|
||||||
|
class HuggingFaceInferenceAPIEmbeddingsComponent(CustomComponent):
|
||||||
|
display_name = "HuggingFaceInferenceAPIEmbeddings"
|
||||||
|
description = "HuggingFace sentence_transformers embedding models, API version."
|
||||||
|
documentation = (
|
||||||
|
"https://github.com/huggingface/text-embeddings-inference"
|
||||||
|
)
|
||||||
|
|
||||||
|
def build_config(self):
|
||||||
|
return {
|
||||||
|
"api_key": {"display_name": "API Key", "password": True, "advanced": True},
|
||||||
|
"api_url": {"display_name": "API URL", "advanced": True},
|
||||||
|
"model_name": {"display_name": "Model Name"},
|
||||||
|
"cache_folder": {"display_name": "Cache Folder", "advanced": True},
|
||||||
|
"encode_kwargs": {"display_name": "Encode Kwargs", "advanced": True, "field_type": "dict"},
|
||||||
|
"model_kwargs": {"display_name": "Model Kwargs", "field_type": "dict", "advanced": True},
|
||||||
|
"multi_process": {"display_name": "Multi Process", "advanced": True},
|
||||||
|
}
|
||||||
|
|
||||||
|
def build(
|
||||||
|
self,
|
||||||
|
api_key: Optional[str] = "",
|
||||||
|
api_url: str = "http://localhost:8080",
|
||||||
|
model_name: str = "BAAI/bge-large-en-v1.5",
|
||||||
|
cache_folder: Optional[str] = None,
|
||||||
|
encode_kwargs: Optional[Dict] = {},
|
||||||
|
model_kwargs: Optional[Dict] = {},
|
||||||
|
multi_process: bool = False,
|
||||||
|
) -> HuggingFaceInferenceAPIEmbeddings:
|
||||||
|
return HuggingFaceInferenceAPIEmbeddings(
|
||||||
|
api_key=api_key,
|
||||||
|
api_url=api_url,
|
||||||
|
model_name=model_name,
|
||||||
|
cache_folder=cache_folder,
|
||||||
|
encode_kwargs=encode_kwargs,
|
||||||
|
model_kwargs=model_kwargs,
|
||||||
|
multi_process=multi_process,
|
||||||
|
)
|
||||||
|
|
@ -15,7 +15,7 @@ class QdrantComponent(CustomComponent):
|
||||||
return {
|
return {
|
||||||
"documents": {"display_name": "Documents"},
|
"documents": {"display_name": "Documents"},
|
||||||
"embedding": {"display_name": "Embedding"},
|
"embedding": {"display_name": "Embedding"},
|
||||||
"api_key": {"display_name": "API Key", "password": True},
|
"api_key": {"display_name": "API Key", "password": True, "advanced": True},
|
||||||
"collection_name": {"display_name": "Collection Name"},
|
"collection_name": {"display_name": "Collection Name"},
|
||||||
"content_payload_key": {"display_name": "Content Payload Key", "advanced": True},
|
"content_payload_key": {"display_name": "Content Payload Key", "advanced": True},
|
||||||
"distance_func": {"display_name": "Distance Function", "advanced": True},
|
"distance_func": {"display_name": "Distance Function", "advanced": True},
|
||||||
|
|
@ -36,7 +36,7 @@ class QdrantComponent(CustomComponent):
|
||||||
def build(
|
def build(
|
||||||
self,
|
self,
|
||||||
embedding: Embeddings,
|
embedding: Embeddings,
|
||||||
documents: List[Document],
|
documents: Optional[Document] = None,
|
||||||
api_key: Optional[str] = None,
|
api_key: Optional[str] = None,
|
||||||
collection_name: Optional[str] = None,
|
collection_name: Optional[str] = None,
|
||||||
content_payload_key: str = "page_content",
|
content_payload_key: str = "page_content",
|
||||||
|
|
@ -44,7 +44,7 @@ class QdrantComponent(CustomComponent):
|
||||||
grpc_port: Optional[int] = 6334,
|
grpc_port: Optional[int] = 6334,
|
||||||
host: Optional[str] = None,
|
host: Optional[str] = None,
|
||||||
https: bool = False,
|
https: bool = False,
|
||||||
location: str = ":memory:",
|
location: Optional[str] = None,
|
||||||
metadata_payload_key: str = "metadata",
|
metadata_payload_key: str = "metadata",
|
||||||
path: Optional[str] = None,
|
path: Optional[str] = None,
|
||||||
port: Optional[int] = 6333,
|
port: Optional[int] = 6333,
|
||||||
|
|
@ -54,7 +54,33 @@ class QdrantComponent(CustomComponent):
|
||||||
timeout: Optional[float] = None,
|
timeout: Optional[float] = None,
|
||||||
url: Optional[str] = None,
|
url: Optional[str] = None,
|
||||||
) -> Union[VectorStore, Qdrant, BaseRetriever]:
|
) -> Union[VectorStore, Qdrant, BaseRetriever]:
|
||||||
return Qdrant.from_documents(
|
if documents is None:
|
||||||
|
from qdrant_client import QdrantClient
|
||||||
|
client = QdrantClient(
|
||||||
|
location=location,
|
||||||
|
url=host,
|
||||||
|
port=port,
|
||||||
|
grpc_port=grpc_port,
|
||||||
|
https=https,
|
||||||
|
prefix=prefix,
|
||||||
|
timeout=timeout,
|
||||||
|
prefer_grpc=prefer_grpc,
|
||||||
|
metadata_payload_key=metadata_payload_key,
|
||||||
|
content_payload_key=content_payload_key,
|
||||||
|
api_key=api_key,
|
||||||
|
collection_name=collection_name,
|
||||||
|
host=host,
|
||||||
|
path=path,
|
||||||
|
)
|
||||||
|
vs = Qdrant(client=client,
|
||||||
|
collection_name=collection_name,
|
||||||
|
embeddings=embedding,
|
||||||
|
search_kwargs=search_kwargs,
|
||||||
|
distance_func=distance_func,
|
||||||
|
)
|
||||||
|
return vs
|
||||||
|
else:
|
||||||
|
vs = Qdrant.from_documents(
|
||||||
documents=documents,
|
documents=documents,
|
||||||
embedding=embedding,
|
embedding=embedding,
|
||||||
api_key=api_key,
|
api_key=api_key,
|
||||||
|
|
@ -74,3 +100,4 @@ class QdrantComponent(CustomComponent):
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
url=url,
|
url=url,
|
||||||
)
|
)
|
||||||
|
return vs
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue