Skip to content

Commit

Permalink
Added support for Unified Port, GET/DELETE endpoints in pgvector (ope…
Browse files Browse the repository at this point in the history
…a-project#444)

Signed-off-by: Yogesh <[email protected]>
Co-authored-by: Yogesh <[email protected]>
  • Loading branch information
2 people authored and BaoHuiling committed Aug 15, 2024
1 parent e385e38 commit 1e56634
Show file tree
Hide file tree
Showing 5 changed files with 294 additions and 42 deletions.
75 changes: 66 additions & 9 deletions comps/dataprep/pgvector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
pip install -r requirements.txt
```

## 1.2 Start PGVector

Please refer to this [readme](../../../vectorstores/langchain/pgvcetor/README.md).

## 1.3 Setup Environment Variables
## 1.2 Setup Environment Variables

```bash
export PG_CONNECTION_STRING=postgresql+psycopg2://testuser:testpwd@${your_ip}:5432/vectordb
Expand All @@ -22,6 +18,10 @@ export LANGCHAIN_API_KEY=${your_langchain_api_key}
export LANGCHAIN_PROJECT="opea/gen-ai-comps:dataprep"
```

## 1.3 Start PGVector

Please refer to this [readme](../../vectorstores/langchain/pgvector/README.md).

## 1.4 Start Document Preparation Microservice for PGVector with Python Script

Start document preparation microservice for PGVector with below command.
Expand All @@ -34,7 +34,7 @@ python prepare_doc_pgvector.py

## 2.1 Start PGVector

Please refer to this [readme](../../../vectorstores/langchain/pgvector/README.md).
Please refer to this [readme](../../vectorstores/langchain/pgvector/README.md).

## 2.2 Setup Environment Variables

Expand All @@ -49,14 +49,14 @@ export LANGCHAIN_PROJECT="opea/dataprep"
## 2.3 Build Docker Image

```bash
cd comps/dataprep/langchain/pgvector/docker
docker build -t opea/dataprep-pgvector:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/dataprep/langchain/pgvector/docker/Dockerfile .
cd GenAIComps
docker build -t opea/dataprep-pgvector:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/dataprep/pgvector/langchain/docker/Dockerfile .
```

## 2.4 Run Docker with CLI (Option A)

```bash
docker run -d --name="dataprep-pgvector" -p 6007:6007 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e PG_CONNECTION_STRING=$PG_CONNECTION_STRING -e INDEX_NAME=$INDEX_NAME -e TEI_ENDPOINT=$TEI_ENDPOINT opea/dataprep-pgvector:latest
docker run --name="dataprep-pgvector" -p 6007:6007 --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e PG_CONNECTION_STRING=$PG_CONNECTION_STRING -e INDEX_NAME=$INDEX_NAME -e TEI_ENDPOINT=$TEI_ENDPOINT opea/dataprep-pgvector:latest
```

## 2.5 Run with Docker Compose (Option B)
Expand All @@ -68,6 +68,8 @@ docker compose -f docker-compose-dataprep-pgvector.yaml up -d

# 🚀3. Consume Microservice

## 3.1 Consume Upload API

Once document preparation microservice for PGVector is started, user can use below command to invoke the microservice to convert the document to embedding and save to the database.

```bash
Expand All @@ -76,3 +78,58 @@ curl -X POST \
-d '{"path":"/path/to/document"}' \
http://localhost:6007/v1/dataprep
```

## 3.2 Consume get_file API

To get uploaded file structures, use the following command:

```bash
curl -X POST \
-H "Content-Type: application/json" \
http://localhost:6007/v1/dataprep/get_file
```

Then you will get the response JSON like this:

```json
[
{
"name": "uploaded_file_1.txt",
"id": "uploaded_file_1.txt",
"type": "File",
"parent": ""
},
{
"name": "uploaded_file_2.txt",
"id": "uploaded_file_2.txt",
"type": "File",
"parent": ""
}
]
```

## 4.3 Consume delete_file API

To delete uploaded file/link, use the following command.

The `file_path` here should be the `id` get from `/v1/dataprep/get_file` API.

```bash
# delete link
curl -X POST \
-H "Content-Type: application/json" \
-d '{"file_path": "https://www.ces.tech/.txt"}' \
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:6007/v1/dataprep/delete_file

# delete all files and links
curl -X POST \
-H "Content-Type: application/json" \
-d '{"file_path": "all"}' \
http://localhost:6007/v1/dataprep/delete_file
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ services:
- POSTGRES_USER=testuser
- POSTGRES_PASSWORD=testpwd
- POSTGRES_HOST_AUTH_METHOD=trust
- no_proxy= ${no_proxy}
- http_proxy= ${http_proxy}
- https_proxy= ${https_proxy}
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql

Expand Down
Loading

0 comments on commit 1e56634

Please sign in to comment.