From 045a056271dc5dd2e4f5dcd5cda8e42d58fc89dc Mon Sep 17 00:00:00 2001 From: "Wang, Xigui" Date: Wed, 6 Nov 2024 17:46:25 +0800 Subject: [PATCH] Enable milvus for retriever and datap-reparation Enable milvus vector database work with TEI embedding for retriever and data-preparation Signed-off-by: Wang, Xigui --- comps/dataprep/milvus/langchain/README.md | 111 ++++++------------ .../milvus/langchain/docker-compose.yml | 47 +++++++- .../milvus/langchain/prepare_doc_milvus.py | 18 +-- comps/dataprep/milvus/langchain/set_env.sh | 10 ++ comps/retrievers/milvus/langchain/README.md | 27 +++-- .../milvus/langchain/docker-compose.yml | 106 +++++++++++++++++ .../milvus/langchain/retriever_milvus.py | 4 +- comps/retrievers/milvus/langchain/set_env.sh | 9 ++ .../test_dataprep_milvus_langchain.sh | 29 ++--- 9 files changed, 237 insertions(+), 124 deletions(-) create mode 100644 comps/dataprep/milvus/langchain/set_env.sh create mode 100644 comps/retrievers/milvus/langchain/docker-compose.yml create mode 100644 comps/retrievers/milvus/langchain/set_env.sh diff --git a/comps/dataprep/milvus/langchain/README.md b/comps/dataprep/milvus/langchain/README.md index f349df54cb..8dd3b6b6b1 100644 --- a/comps/dataprep/milvus/langchain/README.md +++ b/comps/dataprep/milvus/langchain/README.md @@ -1,10 +1,14 @@ # Dataprep Microservice with Milvus +You can start retriever Microservice either by Python script or docker composer. + ## πŸš€1. Start Microservice with Python (Option 1) ### 1.1 Requirements ```bash +git clone https://github.com/opea-project/GenAIComps.git +cd GenAIComps/comps/dataprep/milvus/langchain pip install -r requirements.txt apt-get install tesseract-ocr -y apt-get install libtesseract-dev -y @@ -18,39 +22,11 @@ Please refer to this [readme](../../../vectorstores/milvus/README.md). ### 1.3 Setup Environment Variables ```bash -export no_proxy=${your_no_proxy} -export http_proxy=${your_http_proxy} -export https_proxy=${your_http_proxy} -export MILVUS_HOST=${your_milvus_host_ip} -export MILVUS_PORT=19530 -export COLLECTION_NAME=${your_collection_name} -export MOSEC_EMBEDDING_ENDPOINT=${your_embedding_endpoint} -``` - -### 1.4 Start Mosec Embedding Service - -First, you need to build a mosec embedding serving docker image. - -```bash -cd ../../.. -docker build --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy -t opea/embedding-mosec-endpoint:latest -f comps/embeddings/mosec/langchain/dependency/Dockerfile . +export HUGGINGFACEHUB_API_TOKEN="YOUR_HUGGINGFACEHUB_API_TOKEN" +source set_env.sh ``` -Then start the mosec embedding server. - -```bash -your_port=6010 -docker run -d --name="embedding-mosec-endpoint" -p $your_port:8000 opea/embedding-mosec-endpoint:latest -``` - -Setup environment variables: - -```bash -export MOSEC_EMBEDDING_ENDPOINT="http://localhost:$your_port" -export MILVUS_HOST=${your_host_ip} -``` - -### 1.5 Start Document Preparation Microservice for Milvus with Python Script +### 1.4 Start Document Preparation Microservice for Milvus with Python Script Start document preparation microservice for Milvus with below command. @@ -60,43 +36,23 @@ python prepare_doc_milvus.py ## πŸš€2. Start Microservice with Docker (Option 2) -### 2.1 Start Milvus Server - -Please refer to this [readme](../../../vectorstores/milvus/README.md). - -### 2.2 Build Docker Image +### 2.1 Build Docker Image ```bash -cd ../../.. -# build mosec embedding docker image -docker build --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy -t opea/embedding-langchain-mosec-endpoint:latest -f comps/embeddings/mosec/langchain/dependency/Dockerfile . +git clone https://github.com/opea-project/GenAIComps.git +cd GenAIComps/comps/dataprep/milvus/langchain # build dataprep milvus docker image -docker build -t opea/dataprep-milvus:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy --build-arg no_proxy=$no_proxy -f comps/dataprep/milvus/langchain/Dockerfile . -``` - -### 2.3 Setup Environment Variables - -```bash -export MOSEC_EMBEDDING_ENDPOINT="http://localhost:$your_port" -export MILVUS_HOST=${your_host_ip} -``` - -### 2.3 Run Docker with CLI (Option A) - -```bash -docker run -d --name="dataprep-milvus-server" -p 6010:6010 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e MOSEC_EMBEDDING_ENDPOINT=${MOSEC_EMBEDDING_ENDPOINT} -e MILVUS_HOST=${MILVUS_HOST} opea/dataprep-milvus:latest +docker compose build --no-cache ``` -### 2.4 Run with Docker Compose (Option B) +### 2.2 Run with Docker Compose (Option B) ```bash -mkdir model -cd model -git clone https://huggingface.co/BAAI/bge-base-en-v1.5 -cd ../ -# Update `host_ip` and `HUGGINGFACEHUB_API_TOKEN` in set_env.sh -. set_env.sh -docker compose -f docker-compose-dataprep-milvus.yaml up -d +git clone https://github.com/opea-project/GenAIComps.git +cd GenAIComps/comps/dataprep/milvus/langchain +export HUGGINGFACEHUB_API_TOKEN="YOUR_HUGGINGFACEHUB_API_TOKEN" +source set_env.sh +docker compose -f docker-compose.yaml up -d ``` ## πŸš€3. Consume Microservice @@ -105,15 +61,18 @@ docker compose -f docker-compose-dataprep-milvus.yaml up -d Once document preparation microservice for Milvus is started, user can use below command to invoke the microservice to convert the document to embedding and save to the database. -Make sure the file path after `files=@` is correct. +Update Knowledge Base via Local File nke-10k-2023.pdf. Get the file on a terminal. +``` +wget https://raw.githubusercontent.com/opea-project/GenAIComps/main/comps/retrievers/redis/data/nke-10k-2023.pdf +``` - Single file upload ```bash curl -X POST \ -H "Content-Type: multipart/form-data" \ - -F "files=@./file.pdf" \ - http://localhost:6010/v1/dataprep + -F "files=@./nke-10k-2023.pdf" \ + http://localhost:6007/v1/dataprep ``` You can specify chunk_size and chunk_size by the following commands. To avoid big chunks, pass a small chun_size like 500 as below (default 1500). @@ -124,7 +83,7 @@ curl -X POST \ -F "files=@./file.pdf" \ -F "chunk_size=500" \ -F "chunk_overlap=100" \ - http://localhost:6010/v1/dataprep + http://localhost:6007/v1/dataprep ``` - Multiple file upload @@ -135,15 +94,13 @@ curl -X POST \ -F "files=@./file1.pdf" \ -F "files=@./file2.pdf" \ -F "files=@./file3.pdf" \ - http://localhost:6010/v1/dataprep + http://localhost:6007/v1/dataprep ``` -- Links upload (not supported for llama_index now) - ```bash curl -X POST \ -F 'link_list=["https://www.ces.tech/"]' \ - http://localhost:6010/v1/dataprep + http://localhost:6007/v1/dataprep ``` or @@ -153,7 +110,7 @@ import requests import json proxies = {"http": ""} -url = "http://localhost:6010/v1/dataprep" +url = "http://localhost:6007/v1/dataprep" urls = [ "https://towardsdatascience.com/no-gpu-no-party-fine-tune-bert-for-sentiment-analysis-with-vertex-ai-custom-jobs-d8fc410e908b?source=rss----7f60cf5620c9---4" ] @@ -173,7 +130,7 @@ We support table extraction from pdf documents. You can specify process_table an Note: If you specify "table_strategy=llm", You should first start TGI Service, please refer to 1.2.1, 1.3.1 in https://github.com/opea-project/GenAIComps/tree/main/comps/llms/README.md, and then `export TGI_LLM_ENDPOINT="http://${your_ip}:8008"`. ```bash -curl -X POST -H "Content-Type: application/json" -d '{"path":"/home/user/doc/your_document_name","process_table":true,"table_strategy":"hq"}' http://localhost:6010/v1/dataprep +curl -X POST -H "Content-Type: application/json" -d '{"path":"/home/user/doc/your_document_name","process_table":true,"table_strategy":"hq"}' http://localhost:6007/v1/dataprep ``` We support table extraction from pdf documents. You can specify process_table and table_strategy by the following commands. "table_strategy" refers to the strategies to understand tables for table retrieval. As the setting progresses from "fast" to "hq" to "llm," the focus shifts towards deeper table understanding at the expense of processing speed. The default strategy is "fast". @@ -181,7 +138,7 @@ We support table extraction from pdf documents. You can specify process_table an Note: If you specify "table_strategy=llm", You should first start TGI Service, please refer to 1.2.1, 1.3.1 in https://github.com/opea-project/GenAIComps/tree/main/comps/llms/README.md, and then `export TGI_LLM_ENDPOINT="http://${your_ip}:8008"`. ```bash -curl -X POST -H "Content-Type: application/json" -d '{"path":"/home/user/doc/your_document_name","process_table":true,"table_strategy":"hq"}' http://localhost:6010/v1/dataprep +curl -X POST -H "Content-Type: application/json" -d '{"path":"/home/user/doc/your_document_name","process_table":true,"table_strategy":"hq"}' http://localhost:6007/v1/dataprep ``` ### 3.2 Consume get_file API @@ -191,7 +148,7 @@ To get uploaded file structures, use the following command: ```bash curl -X POST \ -H "Content-Type: application/json" \ - http://localhost:6010/v1/dataprep/get_file + http://localhost:6007/v1/dataprep/get_file ``` Then you will get the response JSON like this: @@ -224,19 +181,19 @@ The `file_path` here should be the `id` get from `/v1/dataprep/get_file` API. curl -X POST \ -H "Content-Type: application/json" \ -d '{"file_path": "https://www.ces.tech/.txt"}' \ - http://localhost:6010/v1/dataprep/delete_file + http://localhost:6007/v1/dataprep/delete_file # delete file curl -X POST \ -H "Content-Type: application/json" \ -d '{"file_path": "uploaded_file_1.txt"}' \ - http://localhost:6010/v1/dataprep/delete_file + http://localhost:6007/v1/dataprep/delete_file # delete all files and links, will drop the entire db collection curl -X POST \ -H "Content-Type: application/json" \ -d '{"file_path": "all"}' \ - http://localhost:6010/v1/dataprep/delete_file + http://localhost:6007/v1/dataprep/delete_file ``` ## πŸš€4. Troubleshooting @@ -248,5 +205,5 @@ curl -X POST \ -H "Content-Type: multipart/form-data" \ -F "files=@./file.pdf" \ -F "chunk_size=500" \ - http://localhost:6010/v1/dataprep + http://localhost:6007/v1/dataprep ``` diff --git a/comps/dataprep/milvus/langchain/docker-compose.yml b/comps/dataprep/milvus/langchain/docker-compose.yml index 8dde3fed06..0575942069 100644 --- a/comps/dataprep/milvus/langchain/docker-compose.yml +++ b/comps/dataprep/milvus/langchain/docker-compose.yml @@ -1,8 +1,6 @@ # Copyright (C) 2024 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -version: '3.5' - services: etcd: container_name: milvus-etcd @@ -13,7 +11,7 @@ services: - ETCD_QUOTA_BACKEND_BYTES=4294967296 - ETCD_SNAPSHOT_COUNT=50000 volumes: - - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/etcd:/etcd + - ./volumes/etcd:/etcd command: etcd -advertise-client-urls=http://127.0.0.1:2379 -listen-client-urls http://0.0.0.0:2379 --data-dir /etcd healthcheck: test: ["CMD", "etcdctl", "endpoint", "health"] @@ -31,7 +29,7 @@ services: - "5044:9001" - "5043:9000" volumes: - - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/minio:/minio_data + - ./volumes/minio:/minio_data command: minio server /minio_data --console-address ":9001" healthcheck: test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] @@ -49,8 +47,8 @@ services: ETCD_ENDPOINTS: etcd:2379 MINIO_ADDRESS: minio:9000 volumes: - - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/milvus:/var/lib/milvus - ${DOCKER_VOLUME_DIRECTORY:-.}/milvus.yaml:/milvus/configs/milvus.yaml + - ./volumes/milvus:/var/lib/milvus healthcheck: test: ["CMD", "curl", "-f", "http://localhost:9091/healthz"] interval: 30s @@ -64,6 +62,43 @@ services: - "etcd" - "minio" + dataprep-redis-service: + image: ${REGISTRY:-opea}/dataprep-milvus:${TAG:-latest} + build: + context: ../../../.. + dockerfile: ./comps/dataprep/milvus/langchain/Dockerfile + args: + http_proxy: ${http_proxy} + https_proxy: ${https_proxy} + container_name: test-comps-dataprep-milvus-server + ports: + - "6007:6007" + depends_on: + - standalone + - tei-embedding-service + environment: + no_proxy: ${no_proxy} + http_proxy: ${http_proxy} + https_proxy: ${https_proxy} + MILVUS_HOST: ${MILVUS_HOST} + MILVUS_PORT: ${MILVUS_PORT} + TEI_EMBEDDING_ENDPOINT: http://tei-embedding-service:80 + HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN} + + tei-embedding-service: + image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.5 + container_name: tei-embedding-server + ports: + - "6006:80" + volumes: + - "./data:/data" + shm_size: 1g + environment: + no_proxy: ${no_proxy} + http_proxy: ${http_proxy} + https_proxy: ${https_proxy} + command: --model-id ${EMBEDDING_MODEL_ID} --auto-truncate + networks: default: - name: milvus + driver: bridge diff --git a/comps/dataprep/milvus/langchain/prepare_doc_milvus.py b/comps/dataprep/milvus/langchain/prepare_doc_milvus.py index a6014b621a..890b50bbab 100644 --- a/comps/dataprep/milvus/langchain/prepare_doc_milvus.py +++ b/comps/dataprep/milvus/langchain/prepare_doc_milvus.py @@ -88,11 +88,12 @@ def ingest_chunks_to_milvus(file_name: str, chunks: List): batch_docs = insert_docs[i : i + batch_size] try: + url = "http://" + str(MILVUS_HOST) + ":" + str(MILVUS_PORT) _ = Milvus.from_documents( batch_docs, embeddings, collection_name=COLLECTION_NAME, - connection_args={"uri": milvus_uri}, + connection_args={"host": MILVUS_HOST, "port": MILVUS_PORT, "uri":url}, partition_key_field=partition_field_name, ) except Exception as e: @@ -190,7 +191,7 @@ def delete_by_partition_field(my_milvus, partition_field): logger.info(f"[ delete partition ] delete success: {res}") -@register_microservice(name="opea_service@prepare_doc_milvus", endpoint="/v1/dataprep", host="0.0.0.0", port=6010) +@register_microservice(name="opea_service@prepare_doc_milvus", endpoint="/v1/dataprep", host="0.0.0.0", port=6007) async def ingest_documents( files: Optional[Union[UploadFile, List[UploadFile]]] = File(None), link_list: Optional[str] = Form(None), @@ -207,10 +208,11 @@ async def ingest_documents( raise HTTPException(status_code=400, detail="Provide either a file or a string list, not both.") # define Milvus obj + url = "http://" + str(MILVUS_HOST) + ":" + str(MILVUS_PORT) my_milvus = Milvus( embedding_function=embeddings, collection_name=COLLECTION_NAME, - connection_args={"uri": milvus_uri}, + connection_args={"host": MILVUS_HOST, "port": MILVUS_PORT, "uri":url}, index_params=index_params, auto_id=True, ) @@ -336,17 +338,18 @@ async def ingest_documents( @register_microservice( - name="opea_service@prepare_doc_milvus", endpoint="/v1/dataprep/get_file", host="0.0.0.0", port=6010 + name="opea_service@prepare_doc_milvus", endpoint="/v1/dataprep/get_file", host="0.0.0.0", port=6007 ) async def rag_get_file_structure(): if logflag: logger.info("[ get ] start to get file structure") # define Milvus obj + url = "http://" + str(MILVUS_HOST) + ":" + str(MILVUS_PORT) my_milvus = Milvus( embedding_function=embeddings, collection_name=COLLECTION_NAME, - connection_args={"uri": milvus_uri}, + connection_args={"host": MILVUS_HOST, "port": MILVUS_PORT, "uri": url}, index_params=index_params, auto_id=True, ) @@ -388,7 +391,7 @@ async def rag_get_file_structure(): @register_microservice( - name="opea_service@prepare_doc_milvus", endpoint="/v1/dataprep/delete_file", host="0.0.0.0", port=6010 + name="opea_service@prepare_doc_milvus", endpoint="/v1/dataprep/delete_file", host="0.0.0.0", port=6007 ) async def delete_single_file(file_path: str = Body(..., embed=True)): """Delete file according to `file_path`. @@ -401,10 +404,11 @@ async def delete_single_file(file_path: str = Body(..., embed=True)): logger.info(file_path) # define Milvus obj + url = "http://" + str(MILVUS_HOST) + ":" + str(MILVUS_PORT) my_milvus = Milvus( embedding_function=embeddings, collection_name=COLLECTION_NAME, - connection_args={"uri": milvus_uri}, + connection_args={"host": MILVUS_HOST, "port": MILVUS_PORT, "uri":url}, index_params=index_params, auto_id=True, ) diff --git a/comps/dataprep/milvus/langchain/set_env.sh b/comps/dataprep/milvus/langchain/set_env.sh new file mode 100644 index 0000000000..4c9040fc15 --- /dev/null +++ b/comps/dataprep/milvus/langchain/set_env.sh @@ -0,0 +1,10 @@ +export DOCKER_VOLUME_DIRECTORY="../../../vectorstores/milvus" +export host_ip=$(hostname -i) +export no_proxy=${no_proxy},tei-embedding-service +export http_proxy=${http_proxy} +export https_proxy=${http_proxy} +export MILVUS_HOST=${host_ip} +export MILVUS_PORT=19530 +export EMBEDDING_MODEL_ID="BAAI/bge-base-en-v1.5" +# Optional COLLECTION_NAME +export COLLECTION_NAME=${your_collection_name} diff --git a/comps/retrievers/milvus/langchain/README.md b/comps/retrievers/milvus/langchain/README.md index 61978cdf74..6bef1becbd 100644 --- a/comps/retrievers/milvus/langchain/README.md +++ b/comps/retrievers/milvus/langchain/README.md @@ -1,10 +1,14 @@ # Retriever Microservice with Milvus +You can start retriever Microservice either by Python script or docker composer. + ## πŸš€Start Microservice with Python ### Install Requirements ```bash +git clone https://github.com/opea-project/GenAIComps.git +cd GenAIComps/comps/retrievers/milvus/langchain pip install -r requirements.txt ``` @@ -14,20 +18,14 @@ Please refer to this [readme](../../../vectorstores/milvus/README.md). ### Setup Environment Variables -```bash -export no_proxy=${your_no_proxy} -export http_proxy=${your_http_proxy} -export https_proxy=${your_http_proxy} -export MILVUS_HOST=${your_milvus_host_ip} -export MILVUS_PORT=19530 -export COLLECTION_NAME=${your_collection_name} -export MOSEC_EMBEDDING_ENDPOINT=${your_emdding_endpoint} ``` - +export HUGGINGFACEHUB_API_TOKEN="YOUR_HUGGINGFACEHUB_API_TOKEN" +#source set_env.sh +``` ### Start Retriever Service ```bash -export MOSEC_EMBEDDING_ENDPOINT="http://${your_ip}:6060" +export TEI_EMBEDDING_ENDPOINT="http://${your_ip}:6006" python retriever_redis.py ``` @@ -36,14 +34,17 @@ python retriever_redis.py ### Build Docker Image ```bash -cd ../../ -docker build -t opea/retriever-milvus:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/retrievers/milvus/langchain/Dockerfile . +git clone https://github.com/opea-project/GenAIComps.git +cd GenAIComps/comps/retrievers/milvus/langchain +# build dataprep milvus docker image +docker compose build --no-cache ``` ### Run Docker with CLI ```bash -docker run -d --name="retriever-milvus-server" -p 7000:7000 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e MOSEC_EMBEDDING_ENDPOINT=${your_emdding_endpoint} -e MILVUS_HOST=${your_milvus_host_ip} opea/retriever-milvus:latest +source set_env.sh +docker compose up -d ``` ## πŸš€3. Consume Retriever Service diff --git a/comps/retrievers/milvus/langchain/docker-compose.yml b/comps/retrievers/milvus/langchain/docker-compose.yml new file mode 100644 index 0000000000..323a4f77aa --- /dev/null +++ b/comps/retrievers/milvus/langchain/docker-compose.yml @@ -0,0 +1,106 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +services: + etcd: + container_name: milvus-etcd + image: quay.io/coreos/etcd:v3.5.5 + environment: + - ETCD_AUTO_COMPACTION_MODE=revision + - ETCD_AUTO_COMPACTION_RETENTION=1000 + - ETCD_QUOTA_BACKEND_BYTES=4294967296 + - ETCD_SNAPSHOT_COUNT=50000 + volumes: + - ./volumes/etcd:/etcd + command: etcd -advertise-client-urls=http://127.0.0.1:2379 -listen-client-urls http://0.0.0.0:2379 --data-dir /etcd + healthcheck: + test: ["CMD", "etcdctl", "endpoint", "health"] + interval: 30s + timeout: 20s + retries: 3 + + minio: + container_name: milvus-minio + image: minio/minio:RELEASE.2023-03-20T20-16-18Z + environment: + MINIO_ACCESS_KEY: minioadmin + MINIO_SECRET_KEY: minioadmin + ports: + - "5044:9001" + - "5043:9000" + volumes: + - ./volumes/minio:/minio_data + command: minio server /minio_data --console-address ":9001" + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] + interval: 30s + timeout: 20s + retries: 3 + + standalone: + container_name: milvus-standalone + image: milvusdb/milvus:v2.4.9 + command: ["milvus", "run", "standalone"] + security_opt: + - seccomp:unconfined + environment: + ETCD_ENDPOINTS: etcd:2379 + MINIO_ADDRESS: minio:9000 + volumes: + - ${DOCKER_VOLUME_DIRECTORY:-.}/milvus.yaml:/milvus/configs/milvus.yaml + - ./volumes/milvus:/var/lib/milvus + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:9091/healthz"] + interval: 30s + start_period: 90s + timeout: 20s + retries: 3 + ports: + - "19530:19530" + - "9091:9091" + depends_on: + - "etcd" + - "minio" + + retriever-server: + image: opea/retriever-milvus:latest + build: + context: ../../../.. + dockerfile: ./comps/retrievers/milvus/langchain/Dockerfile + args: + http_proxy: ${http_proxy} + https_proxy: ${https_proxy} + container_name: retriever-milvus-server + ports: + - "7000:7000" + ipc: host + environment: + no_proxy: ${no_proxy} + http_proxy: ${http_proxy} + https_proxy: ${https_proxy} + MILVUS_HOST: ${host_ip} + MILVUS_PORT: ${MILVUS_PORT} + TEI_EMBEDDING_ENDPOINT: http://tei-embedding-service:80 + HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN} + depends_on: + - tei-embedding-service + - standalone + restart: unless-stopped + + tei-embedding-service: + image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.5 + container_name: tei-embedding-server + ports: + - "6006:80" + volumes: + - "./data:/data" + shm_size: 1g + environment: + no_proxy: ${no_proxy} + http_proxy: ${http_proxy} + https_proxy: ${https_proxy} + command: --model-id ${EMBEDDING_MODEL_ID} --auto-truncate + +networks: + default: + driver: bridge diff --git a/comps/retrievers/milvus/langchain/retriever_milvus.py b/comps/retrievers/milvus/langchain/retriever_milvus.py index a4eb3ce43f..3586c5284b 100644 --- a/comps/retrievers/milvus/langchain/retriever_milvus.py +++ b/comps/retrievers/milvus/langchain/retriever_milvus.py @@ -69,9 +69,10 @@ def empty_embedding() -> List[float]: async def retrieve(input: EmbedDoc) -> SearchedDoc: if logflag: logger.info(input) + url = "http://" + str(MILVUS_HOST) + ":" + str(MILVUS_PORT) vector_db = Milvus( embeddings, - connection_args={"host": MILVUS_HOST, "port": MILVUS_PORT}, + connection_args={"host": MILVUS_HOST, "port": MILVUS_PORT, "uri": url}, collection_name=COLLECTION_NAME, ) start = time.time() @@ -114,6 +115,7 @@ async def retrieve(input: EmbedDoc) -> SearchedDoc: if logflag: logger.info(f"[ retriever_milvus ] TEI_EMBEDDING_ENDPOINT:{TEI_EMBEDDING_ENDPOINT}") embeddings = HuggingFaceHubEmbeddings(model=TEI_EMBEDDING_ENDPOINT) + print("embeddings info:", embeddings) else: # create embeddings using local embedding model if logflag: diff --git a/comps/retrievers/milvus/langchain/set_env.sh b/comps/retrievers/milvus/langchain/set_env.sh new file mode 100644 index 0000000000..7310732968 --- /dev/null +++ b/comps/retrievers/milvus/langchain/set_env.sh @@ -0,0 +1,9 @@ +export host_ip=$(hostname -i) +export DOCKER_VOLUME_DIRECTORY="../../../vectorstores/milvus" +export no_proxy=${no_proxy},tei-embedding-service +export EMBEDDING_MODEL_ID="BAAI/bge-base-en-v1.5" +export MILVUS_HOST=${host_ip} +export MILVUS_PORT=19530 +# Optional COLLECTION_NAME +export COLLECTION_NAME=${your_collection_name} + diff --git a/tests/dataprep/test_dataprep_milvus_langchain.sh b/tests/dataprep/test_dataprep_milvus_langchain.sh index 256b686f02..69a83f867c 100644 --- a/tests/dataprep/test_dataprep_milvus_langchain.sh +++ b/tests/dataprep/test_dataprep_milvus_langchain.sh @@ -11,14 +11,6 @@ ip_address=$(hostname -I | awk '{print $1}') function build_docker_images() { cd $WORKPATH echo $(pwd) - # langchain mosec embedding image - docker build --no-cache -t opea/langchain-mosec:comps --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy -f comps/embeddings/mosec/langchain/dependency/Dockerfile . - if [ $? -ne 0 ]; then - echo "opea/langchain-mosec built fail" - exit 1 - else - echo "opea/langchain-mosec built successful" - fi # dataprep milvus image docker build --no-cache -t opea/dataprep-milvus:comps --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/dataprep/milvus/langchain/Dockerfile . if [ $? -ne 0 ]; then @@ -27,27 +19,24 @@ function build_docker_images() { else echo "opea/dataprep-milvus built successful" fi + docker pull ghcr.io/huggingface/text-embeddings-inference:cpu-1.5 } function start_service() { # start milvus vector db cd $WORKPATH/comps/dataprep/milvus/langchain/ + # export no_proxy=tei-embedding-service + export EMBEDDING_MODEL_ID="BAAI/bge-base-en-v1.5" + export TEI_EMBEDDING_ENDPOINT="http://${ip_address}:80" + export MILVUS_HOST=${ip_address} + export MILVUS_PORT=19530 # wget https://raw.githubusercontent.com/milvus-io/milvus/v2.4.9/configs/milvus.yaml # wget https://github.com/milvus-io/milvus/releases/download/v2.4.9/milvus-standalone-docker-compose.yml -O docker-compose.yml # sed '/- \${DOCKER_VOLUME_DIRECTORY:-\.}\/volumes\/milvus:\/var\/lib\/milvus/a \ \ \ \ \ \ - \${DOCKER_VOLUME_DIRECTORY:-\.}\/milvus.yaml:\/milvus\/configs\/milvus.yaml' -i docker-compose.yml + # start dataprep and TEI embedding service by compose docker compose up -d - # set service ports - mosec_embedding_port=5021 - dataprep_service_port=5022 - - # start mosec embedding service - docker run -d --name="test-comps-dataprep-milvus-mosec-server" -p $mosec_embedding_port:8000 -e http_proxy=$http_proxy -e https_proxy=$https_proxy opea/langchain-mosec:comps - - # start dataprep service - MOSEC_EMBEDDING_ENDPOINT="http://${ip_address}:${mosec_embedding_port}" - MILVUS_HOST=${ip_address} - docker run -d --name="test-comps-dataprep-milvus-server" -p ${dataprep_service_port}:6010 -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e MOSEC_EMBEDDING_ENDPOINT=${MOSEC_EMBEDDING_ENDPOINT} -e MILVUS_HOST=${MILVUS_HOST} -e LOGFLAG=true --ipc=host opea/dataprep-milvus:comps + #docker run -d --name="test-comps-dataprep-milvus-server" -p ${dataprep_service_port}:6007 -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e TEI_EMBEDDING_ENDPOINT=${TEI_EMBEDDING_ENDPOINT} -e MILVUS_HOST=${MILVUS_HOST} -e LOGFLAG=true --ipc=host opea/dataprep-milvus:comps sleep 1m } @@ -99,7 +88,7 @@ function validate_service() { function validate_microservice() { cd $LOG_PATH - dataprep_service_port=5022 + dataprep_service_port=6010 # test /v1/dataprep/delete_file validate_service \