Skip to content

Commit

Permalink
Add Dockerfile for Retriever Microservice (opea-project#26)
Browse files Browse the repository at this point in the history
* 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

* add dockerfile for retriever microservice

Signed-off-by: letonghan <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add readme & modify docker folder path

Signed-off-by: letonghan <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* move docker folder of embedding

Signed-off-by: letonghan <[email protected]>

* update image&container name

Signed-off-by: letonghan <[email protected]>

* update image name in readme

Signed-off-by: letonghan <[email protected]>

---------

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
letonghan and pre-commit-ci[bot] authored May 8, 2024
1 parent aead3c9 commit 617065c
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 4 deletions.
4 changes: 2 additions & 2 deletions comps/embeddings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ python embedding_tei_gaudi.py

```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 .
docker build -t intel/gen-ai-comps:embedding-tei-server --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
docker run -d --name="embedding-tei-server" -p 6000:6000 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e TEI_ENDPOINT=$TEI_ENDPOINT intel/gen-ai-comps:embedding-tei-server
```

## Run Docker with Docker Compose
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ version: "3.8"

services:
embedding:
image: genaicomps/microservice/embedding:0.0.1
container_name: embedding_server
image: intel/gen-ai-comps:embedding-tei-server
container_name: embedding-tei-server
ports:
- "6000:6000"
ipc: host
Expand Down
81 changes: 81 additions & 0 deletions comps/retrievers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Retriever Microservice

This retriever microservice is a highly efficient search service designed for handling and retrieving embedding vectors. It operates by receiving an embedding vector as input and conducting a similarity search against vectors stored in a vectordb database. Users must specify the vectordb's URL and the index name, and the service searches within that index to find documents with the highest similarity to the input vector.

The service primarily utilizes measures of similarity in vector space to rapidly retrieve documents that are contentually similar. This vector-based retrieval approach is particularly suited for handling large datasets, offering fast and accurate search results that significantly enhance the efficiency and quality of information retrieval.

Overall, this microservice provides robust backend support for applications requiring efficient similarity searches, playing a vital role in scenarios such as recommendation systems, information retrieval, or any other context where precise measurement of document similarity is crucial.

# 🚀Start Microservice with Python

To start the retriever microservice, you need to install python packages first.

## Install Requirements

```bash
pip install -r requirements.txt
```

## Setup Vectordb Service

You need to setup your own vectordb service (Redis in this example), and ingest your knowledge documents into the vector database.

As for Redis, you could start a docker container using the following commands. Remember to ingest data into it manually.

```bash
docker run -d --name="redis-vector-db" -p 6379:6379 -p 8001:8001 redis/redis-stack:7.2.0-v9
```

## Setup Environment Variables

```bash
export REDIS_URL="redis://${your_ip}:6379"
export INDEX_NAME=${your_index_name}
```

## Start Retriever Service with Local Model

```bash
python langchain/retriever_redis.py
```

# 🚀Start Microservice with Docker

## Build Docker Image

```bash
cd ../../
docker build -t intel/gen-ai-comps:retriever-redis-server --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/retrievers/langchain/docker/Dockerfile .
```

## Run Docker with CLI

```bash
docker run -d --name="retriever-redis-server" -p 7000:7000 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e REDIS_URL=$REDIS_URL -e INDEX_NAME=$INDEX_NAME intel/gen-ai-comps:retriever-redis-server
```

## Run Docker with Docker Compose

```bash
cd langchain/docker
docker compose -f docker_compose_retriever.yaml up -d
```

# 🚀Consume Retriever Service

## Check Service Status

```bash
curl http://localhost:7000/v1/health_check\
-X GET \
-H 'Content-Type: application/json'
```

## Consume Embedding Service

```bash
curl http://localhost:7000/v1/retrieval\
-X POST \
-d '{"text":"Hello, world!", "embedding": [1,1,...,1]}' \
-H 'Content-Type: application/json'
```
39 changes: 39 additions & 0 deletions comps/retrievers/langchain/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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/retrievers/requirements.txt

ENV PYTHONPATH=$PYTHONPATH:/home/user

WORKDIR /home/user/comps/retrievers/langchain

ENTRYPOINT ["python", "retriever_redis.py"]


33 changes: 33 additions & 0 deletions comps/retrievers/langchain/docker/docker_compose_retriever.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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:
retriever:
image: intel/gen-ai-comps:retriever-redis-server
container_name: retriever-redis-server
ports:
- "7000:7000"
ipc: host
environment:
http_proxy: ${http_proxy}
https_proxy: ${https_proxy}
REDIS_URL: ${REDIS_URL}
INDEX_NAME: ${INDEX_NAME}
restart: unless-stopped

networks:
default:
driver: bridge
1 change: 1 addition & 0 deletions comps/retrievers/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ docarray[full]
fastapi
langchain_community
redis
sentence_transformers

0 comments on commit 617065c

Please sign in to comment.