|
| 1 | +# Dataprep Microservice with Elasticsearch |
| 2 | + |
| 3 | +## 🚀1. Start Microservice with Python(Option 1) |
| 4 | + |
| 5 | +### 1.1 Install Requirements |
| 6 | + |
| 7 | +```bash |
| 8 | +pip install -r requirements.txt |
| 9 | +``` |
| 10 | + |
| 11 | +### 1.2 Setup Environment Variables |
| 12 | + |
| 13 | +```bash |
| 14 | +export ES_CONNECTION_STRING=http://localhost:9200 |
| 15 | +export INDEX_NAME=${your_index_name} |
| 16 | +``` |
| 17 | + |
| 18 | +### 1.3 Start Elasticsearch |
| 19 | + |
| 20 | +Please refer to this [readme](../../../vectorstores/elasticsearch/README.md). |
| 21 | + |
| 22 | +### 1.4 Start Document Preparation Microservice for Elasticsearch with Python Script |
| 23 | + |
| 24 | +Start document preparation microservice for Elasticsearch with below command. |
| 25 | + |
| 26 | +```bash |
| 27 | +python prepare_doc_elastic.py |
| 28 | +``` |
| 29 | + |
| 30 | +## 🚀2. Start Microservice with Docker (Option 2) |
| 31 | + |
| 32 | +### 2.1 Start Elasticsearch |
| 33 | + |
| 34 | +Please refer to this [readme](../../../vectorstores/elasticsearch/README.md). |
| 35 | + |
| 36 | +### 2.2 Setup Environment Variables |
| 37 | + |
| 38 | +```bash |
| 39 | +export ES_CONNECTION_STRING=http://localhost:9200 |
| 40 | +export INDEX_NAME=${your_index_name} |
| 41 | +``` |
| 42 | + |
| 43 | +### 2.3 Build Docker Image |
| 44 | + |
| 45 | +```bash |
| 46 | +cd GenAIComps |
| 47 | +docker build -t opea/dataprep-elasticsearch:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/dataprep/elasticsearch/langchain/Dockerfile . |
| 48 | +``` |
| 49 | + |
| 50 | +### 2.4 Run Docker with CLI (Option A) |
| 51 | + |
| 52 | +```bash |
| 53 | +docker run --name="dataprep-elasticsearch" -p 6011:6011 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e ES_CONNECTION_STRING=$ES_CONNECTION_STRING -e INDEX_NAME=$INDEX_NAME -e TEI_ENDPOINT=$TEI_ENDPOINT opea/dataprep-elastic:latest |
| 54 | +``` |
| 55 | + |
| 56 | +### 2.5 Run with Docker Compose (Option B) |
| 57 | + |
| 58 | +```bash |
| 59 | +cd comps/dataprep/elasticsearch/langchain |
| 60 | +docker compose -f docker-compose-dataprep-elastic.yaml up -d |
| 61 | +``` |
| 62 | + |
| 63 | +## 🚀3. Consume Microservice |
| 64 | + |
| 65 | +### 3.1 Consume Upload API |
| 66 | + |
| 67 | +Once document preparation microservice for Elasticsearch is started, user can use below command to invoke the |
| 68 | +microservice to convert the document to embedding and save to the database. |
| 69 | + |
| 70 | +```bash |
| 71 | +curl -X POST \ |
| 72 | + -H "Content-Type: application/json" \ |
| 73 | + -d '{"path":"/path/to/document"}' \ |
| 74 | + http://localhost:6011/v1/dataprep |
| 75 | +``` |
| 76 | + |
| 77 | +### 3.2 Consume get_file API |
| 78 | + |
| 79 | +To get uploaded file structures, use the following command: |
| 80 | + |
| 81 | +```bash |
| 82 | +curl -X POST \ |
| 83 | + -H "Content-Type: application/json" \ |
| 84 | + http://localhost:6011/v1/dataprep/get_file |
| 85 | +``` |
| 86 | + |
| 87 | +Then you will get the response JSON like this: |
| 88 | + |
| 89 | +```json |
| 90 | +[ |
| 91 | + { |
| 92 | + "name": "uploaded_file_1.txt", |
| 93 | + "id": "uploaded_file_1.txt", |
| 94 | + "type": "File", |
| 95 | + "parent": "" |
| 96 | + }, |
| 97 | + { |
| 98 | + "name": "uploaded_file_2.txt", |
| 99 | + "id": "uploaded_file_2.txt", |
| 100 | + "type": "File", |
| 101 | + "parent": "" |
| 102 | + } |
| 103 | +] |
| 104 | +``` |
| 105 | + |
| 106 | +### 4.3 Consume delete_file API |
| 107 | + |
| 108 | +To delete uploaded file/link, use the following command. |
| 109 | + |
| 110 | +The `file_path` here should be the `id` get from `/v1/dataprep/get_file` API. |
| 111 | + |
| 112 | +```bash |
| 113 | +# delete link |
| 114 | +curl -X POST \ |
| 115 | + -H "Content-Type: application/json" \ |
| 116 | + -d '{"file_path": "https://www.ces.tech/.txt"}' \ |
| 117 | + http://localhost:6011/v1/dataprep/delete_file |
| 118 | + |
| 119 | +# delete file |
| 120 | +curl -X POST \ |
| 121 | + -H "Content-Type: application/json" \ |
| 122 | + -d '{"file_path": "uploaded_file_1.txt"}' \ |
| 123 | + http://localhost:6011/v1/dataprep/delete_file |
| 124 | + |
| 125 | +# delete all files and links |
| 126 | +curl -X POST \ |
| 127 | + -H "Content-Type: application/json" \ |
| 128 | + -d '{"file_path": "all"}' \ |
| 129 | + http://localhost:6011/v1/dataprep/delete_file |
| 130 | +``` |
0 commit comments