forked from opea-project/GenAIComps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add local_embedding return 768 length to align with chatqna example (o…
…pea-project#313) Signed-off-by: Chendi.Xue <[email protected]>
- Loading branch information
1 parent
30aaedd
commit fb43647
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |