From fb4364719ea455030d906536d8f6c551db63dbe1 Mon Sep 17 00:00:00 2001 From: "Chendi.Xue" Date: Wed, 21 Aug 2024 09:47:24 -0500 Subject: [PATCH] Add local_embedding return 768 length to align with chatqna example (#313) Signed-off-by: Chendi.Xue --- .../langchain/local_embedding_768.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 comps/embeddings/langchain/local_embedding_768.py diff --git a/comps/embeddings/langchain/local_embedding_768.py b/comps/embeddings/langchain/local_embedding_768.py new file mode 100644 index 0000000000..a079bd6eda --- /dev/null +++ b/comps/embeddings/langchain/local_embedding_768.py @@ -0,0 +1,27 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +from langchain_community.embeddings import HuggingFaceBgeEmbeddings + +from comps import EmbedDoc768, ServiceType, TextDoc, opea_microservices, opea_telemetry, register_microservice + + +@register_microservice( + name="opea_service@local_embedding", + service_type=ServiceType.EMBEDDING, + endpoint="/v1/embeddings", + host="0.0.0.0", + port=6000, + input_datatype=TextDoc, + output_datatype=EmbedDoc768, +) +@opea_telemetry +def embedding(input: TextDoc) -> EmbedDoc768: + embed_vector = embeddings.embed_query(input.text) + res = EmbedDoc768(text=input.text, embedding=embed_vector) + return res + + +if __name__ == "__main__": + embeddings = HuggingFaceBgeEmbeddings(model_name="BAAI/bge-base-en-v1.5") + opea_microservices["opea_service@local_embedding"].start()