|
| 1 | +# Dataprep Microservice with VDMS |
| 2 | + |
| 3 | +For dataprep microservice, we currently provide one framework: `Langchain`. |
| 4 | + |
| 5 | +<!-- We also provide `Langchain_ray` which uses ray to parallel the data prep for multi-file performance improvement(observed 5x - 15x speedup by processing 1000 files/links.). --> |
| 6 | + |
| 7 | +We organized the folders in the same way, so you can use either framework for dataprep microservice with the following constructions. |
| 8 | + |
| 9 | +# 🚀1. Start Microservice with Python (Option 1) |
| 10 | + |
| 11 | +## 1.1 Install Requirements |
| 12 | + |
| 13 | +Install Single-process version (for 1-10 files processing) |
| 14 | + |
| 15 | +```bash |
| 16 | +apt-get update |
| 17 | +apt-get install -y default-jre tesseract-ocr libtesseract-dev poppler-utils |
| 18 | +cd langchain |
| 19 | +pip install -r requirements.txt |
| 20 | +``` |
| 21 | + |
| 22 | +<!-- - option 2: Install multi-process version (for >10 files processing) |
| 23 | +
|
| 24 | +```bash |
| 25 | +cd langchain_ray; pip install -r requirements_ray.txt |
| 26 | +``` --> |
| 27 | + |
| 28 | +## 1.2 Start VDMS Server |
| 29 | + |
| 30 | +Please refer to this [readme](../../vectorstores/langchain/vdms/README.md). |
| 31 | + |
| 32 | +## 1.3 Setup Environment Variables |
| 33 | + |
| 34 | +```bash |
| 35 | +export http_proxy=${your_http_proxy} |
| 36 | +export https_proxy=${your_http_proxy} |
| 37 | +export VDMS_HOST=${host_ip} |
| 38 | +export VDMS_PORT=55555 |
| 39 | +export COLLECTION_NAME=${your_collection_name} |
| 40 | +export LANGCHAIN_TRACING_V2=true |
| 41 | +export LANGCHAIN_PROJECT="opea/gen-ai-comps:dataprep" |
| 42 | +export PYTHONPATH=${path_to_comps} |
| 43 | +``` |
| 44 | + |
| 45 | +## 1.4 Start Document Preparation Microservice for VDMS with Python Script |
| 46 | + |
| 47 | +Start document preparation microservice for VDMS with below command. |
| 48 | + |
| 49 | +Start single-process version (for 1-10 files processing) |
| 50 | + |
| 51 | +```bash |
| 52 | +python prepare_doc_vdms.py |
| 53 | +``` |
| 54 | + |
| 55 | +<!-- - option 2: Start multi-process version (for >10 files processing) |
| 56 | +
|
| 57 | +```bash |
| 58 | +python prepare_doc_redis_on_ray.py |
| 59 | +``` --> |
| 60 | + |
| 61 | +# 🚀2. Start Microservice with Docker (Option 2) |
| 62 | + |
| 63 | +## 2.1 Start VDMS Server |
| 64 | + |
| 65 | +Please refer to this [readme](../../vectorstores/langchain/vdms/README.md). |
| 66 | + |
| 67 | +## 2.2 Setup Environment Variables |
| 68 | + |
| 69 | +```bash |
| 70 | +export http_proxy=${your_http_proxy} |
| 71 | +export https_proxy=${your_http_proxy} |
| 72 | +export VDMS_HOST=${host_ip} |
| 73 | +export VDMS_PORT=55555 |
| 74 | +export TEI_ENDPOINT=${your_tei_endpoint} |
| 75 | +export COLLECTION_NAME=${your_collection_name} |
| 76 | +export SEARCH_ENGINE="FaissFlat" |
| 77 | +export DISTANCE_STRATEGY="L2" |
| 78 | +export PYTHONPATH=${path_to_comps} |
| 79 | +``` |
| 80 | + |
| 81 | +## 2.3 Build Docker Image |
| 82 | + |
| 83 | +- Build docker image with langchain |
| 84 | + |
| 85 | +Start single-process version (for 1-10 files processing) |
| 86 | + |
| 87 | +```bash |
| 88 | +cd ../../../ |
| 89 | +docker build -t opea/dataprep-vdms:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/dataprep/vdms/langchain/Dockerfile . |
| 90 | +``` |
| 91 | + |
| 92 | +<!-- - option 2: Start multi-process version (for >10 files processing) |
| 93 | +
|
| 94 | +```bash |
| 95 | +cd ../../../../ |
| 96 | +docker build -t opea/dataprep-on-ray-vdms:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/dataprep/vdms/langchain_ray/Dockerfile . --> |
| 97 | + |
| 98 | +## 2.4 Run Docker with CLI |
| 99 | + |
| 100 | +Start single-process version (for 1-10 files processing) |
| 101 | + |
| 102 | +```bash |
| 103 | +docker run -d --name="dataprep-vdms-server" -p 6007:6007 --runtime=runc --ipc=host \ |
| 104 | +-e http_proxy=$http_proxy -e https_proxy=$https_proxy -e TEI_ENDPOINT=$TEI_ENDPOINT \ |
| 105 | +-e COLLECTION_NAME=$COLLECTION_NAME -e VDMS_HOST=$VDMS_HOST -e VDMS_PORT=$VDMS_PORT \ |
| 106 | +opea/dataprep-vdms:latest |
| 107 | +``` |
| 108 | + |
| 109 | +<!-- - option 2: Start multi-process version (for >10 files processing) |
| 110 | +
|
| 111 | +```bash |
| 112 | +docker run -d --name="dataprep-vdms-server" -p 6007:6007 --runtime=runc --ipc=host \ |
| 113 | +-e http_proxy=$http_proxy -e https_proxy=$https_proxy \ |
| 114 | +-e COLLECTION_NAME=$COLLECTION_NAME -e VDMS_HOST=$VDMS_HOST -e VDMS_PORT=$VDMS_PORT \ |
| 115 | +-e TIMEOUT_SECONDS=600 opea/dataprep-on-ray-vdms:latest |
| 116 | +``` --> |
| 117 | + |
| 118 | +# 🚀3. Status Microservice |
| 119 | + |
| 120 | +```bash |
| 121 | +docker container logs -f dataprep-vdms-server |
| 122 | +``` |
| 123 | + |
| 124 | +# 🚀4. Consume Microservice |
| 125 | + |
| 126 | +Once document preparation microservice for VDMS is started, user can use below command to invoke the microservice to convert the document to embedding and save to the database. |
| 127 | + |
| 128 | +Make sure the file path after `files=@` is correct. |
| 129 | + |
| 130 | +- Single file upload |
| 131 | + |
| 132 | +```bash |
| 133 | +curl -X POST \ |
| 134 | + -H "Content-Type: multipart/form-data" \ |
| 135 | + -F "files=@./file1.txt" \ |
| 136 | + http://localhost:6007/v1/dataprep |
| 137 | +``` |
| 138 | + |
| 139 | +You can specify chunk_size and chunk_size by the following commands. |
| 140 | + |
| 141 | +```bash |
| 142 | +curl -X POST \ |
| 143 | + -H "Content-Type: multipart/form-data" \ |
| 144 | + -F "files=@./LLAMA2_page6.pdf" \ |
| 145 | + -F "chunk_size=1500" \ |
| 146 | + -F "chunk_overlap=100" \ |
| 147 | + http://localhost:6007/v1/dataprep |
| 148 | +``` |
| 149 | + |
| 150 | +- Multiple file upload |
| 151 | + |
| 152 | +```bash |
| 153 | +curl -X POST \ |
| 154 | + -H "Content-Type: multipart/form-data" \ |
| 155 | + -F "files=@./file1.txt" \ |
| 156 | + -F "files=@./file2.txt" \ |
| 157 | + -F "files=@./file3.txt" \ |
| 158 | + http://localhost:6007/v1/dataprep |
| 159 | +``` |
| 160 | + |
| 161 | +- Links upload (not supported for llama_index now) |
| 162 | + |
| 163 | +```bash |
| 164 | +curl -X POST \ |
| 165 | + -F 'link_list=["https://www.ces.tech/"]' \ |
| 166 | + http://localhost:6007/v1/dataprep |
| 167 | +``` |
| 168 | + |
| 169 | +or |
| 170 | + |
| 171 | +```python |
| 172 | +import requests |
| 173 | +import json |
| 174 | + |
| 175 | +proxies = {"http": ""} |
| 176 | +url = "http://localhost:6007/v1/dataprep" |
| 177 | +urls = [ |
| 178 | + "https://towardsdatascience.com/no-gpu-no-party-fine-tune-bert-for-sentiment-analysis-with-vertex-ai-custom-jobs-d8fc410e908b?source=rss----7f60cf5620c9---4" |
| 179 | +] |
| 180 | +payload = {"link_list": json.dumps(urls)} |
| 181 | + |
| 182 | +try: |
| 183 | + resp = requests.post(url=url, data=payload, proxies=proxies) |
| 184 | + print(resp.text) |
| 185 | + resp.raise_for_status() # Raise an exception for unsuccessful HTTP status codes |
| 186 | + print("Request successful!") |
| 187 | +except requests.exceptions.RequestException as e: |
| 188 | + print("An error occurred:", e) |
| 189 | +``` |
0 commit comments