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 docker & readme for Embedding Microservice (opea-project#22)
* add docker & readme for embedding service Signed-off-by: letonghan <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: letonghan <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
0d11636
commit 6a84533
Showing
6 changed files
with
186 additions
and
7 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,106 @@ | ||
# Embeddings Microservice | ||
|
||
The Embedding Microservice is designed to efficiently convert textual strings into vectorized embeddings, facilitating seamless integration into various machine learning and data processing workflows. This service utilizes advanced algorithms to generate high-quality embeddings that capture the semantic essence of the input text, making it ideal for applications in natural language processing, information retrieval, and similar fields. | ||
|
||
Key Features: | ||
|
||
**High Performance**: Optimized for quick and reliable conversion of textual data into vector embeddings. | ||
|
||
**Scalability**: Built to handle high volumes of requests simultaneously, ensuring robust performance even under heavy loads. | ||
|
||
**Ease of Integration**: Provides a simple and intuitive API, allowing for straightforward integration into existing systems and workflows. | ||
|
||
**Customizable**: Supports configuration and customization to meet specific use case requirements, including different embedding models and preprocessing techniques. | ||
|
||
Users are albe to configure and build embedding-related services according to their actual needs. | ||
|
||
# 🚀Start Microservice with Python | ||
|
||
Currently, we provide two ways to implement the embedding service: | ||
|
||
1. Build the embedding model **_locally_** from the server, which is faster, but takes up memory on the local server. | ||
|
||
2. Build it based on the **_TEI endpoint_**, which provides more flexibility, but may bring some network latency. | ||
|
||
For both of the implementations, you need to install requirements first. | ||
|
||
## Install Requirements | ||
|
||
```bash | ||
pip install -r langchain/requirements.txt | ||
``` | ||
|
||
## Start Embedding Service with Local Model | ||
|
||
```bash | ||
python local_embedding.py | ||
``` | ||
|
||
## Start Embedding Service with TEI | ||
|
||
First, you need to start a TEI service. | ||
|
||
```bash | ||
your_port=8090 | ||
model="BAAI/bge-large-en-v1.5" | ||
revision="refs/pr/5" | ||
docker run -p $your_port:80 -v ./data:/data --name tei_server -e http_proxy=$http_proxy -e https_proxy=$https_proxy --pull always ghcr.io/huggingface/text-embeddings-inference:cpu-1.2 --model-id $model --revision $revision | ||
``` | ||
|
||
Then you need to test your TEI service using the following commands: | ||
|
||
```bash | ||
curl localhost:$your_port/embed \ | ||
-X POST \ | ||
-d '{"inputs":"What is Deep Learning?"}' \ | ||
-H 'Content-Type: application/json' | ||
``` | ||
|
||
Start the embedding service with the TEI_ENDPOINT. | ||
|
||
```bash | ||
cd langchain | ||
export TEI_ENDPOINT="http://localhost:$yourport" | ||
python embedding_tei_gaudi.py | ||
``` | ||
|
||
# 🚀Start Microservice with Docker | ||
|
||
## Build Docker Image | ||
|
||
```bash | ||
cd ../../ | ||
docker build -t genaicomps/microservice/embedding:0.0.1 --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/embeddings/docker/Dockerfile . | ||
``` | ||
|
||
## Run Docker with CLI | ||
|
||
```bash | ||
docker run -d --name="embedding_server" -p 6000:6000 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e TEI_ENDPOINT=$TEI_ENDPOINT genaicomps/microservice/embedding:0.0.1 | ||
``` | ||
|
||
## Run Docker with Docker Compose | ||
|
||
```bash | ||
cd docker | ||
docker compose -f docker_compose.yaml up -d | ||
``` | ||
|
||
# 🚀Consume Embedding Service | ||
|
||
## Check Service Status | ||
|
||
```bash | ||
curl http://localhost:6000/v1/health_check\ | ||
-X GET \ | ||
-H 'Content-Type: application/json' | ||
``` | ||
|
||
## Consume Embedding Service | ||
|
||
```bash | ||
curl http://localhost:6000/v1/embeddings\ | ||
-X POST \ | ||
-d '{"text":"Hello, world!"}' \ | ||
-H 'Content-Type: application/json' | ||
``` |
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,38 @@ | ||
# Copyright (c) 2024 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
FROM langchain/langchain:latest | ||
|
||
RUN apt-get update -y && apt-get install -y --no-install-recommends --fix-missing \ | ||
libgl1-mesa-glx \ | ||
libjemalloc-dev \ | ||
vim | ||
|
||
RUN useradd -m -s /bin/bash user && \ | ||
mkdir -p /home/user && \ | ||
chown -R user /home/user/ | ||
|
||
USER user | ||
|
||
COPY comps /home/user/comps | ||
|
||
RUN pip install --no-cache-dir --upgrade pip && \ | ||
pip install --no-cache-dir -r /home/user/comps/embeddings/langchain/requirements.txt | ||
|
||
ENV PYTHONPATH=$PYTHONPATH:/home/user | ||
|
||
WORKDIR /home/user/comps/embeddings/langchain | ||
|
||
ENTRYPOINT ["python", "embedding_tei_gaudi.py"] | ||
|
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,32 @@ | ||
# Copyright (c) 2024 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
version: "3.8" | ||
|
||
services: | ||
embedding: | ||
image: genaicomps/microservice/embedding:0.0.1 | ||
container_name: embedding_server | ||
ports: | ||
- "6000:6000" | ||
ipc: host | ||
environment: | ||
http_proxy: ${http_proxy} | ||
https_proxy: ${https_proxy} | ||
TEI_ENDPOINT: ${TEI_ENDPOINT} | ||
restart: unless-stopped | ||
|
||
networks: | ||
default: | ||
driver: bridge |
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
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
docarray[full] | ||
fastapi | ||
langchain | ||
sentence_transformers |
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