Skip to content

Commit 2a74e9e

Browse files
Support ArangoDB for ChatHistory, Feedback Management, Prompt Registry (#1922)
* Support ArangoDB for ChatHistory, Feedback Management, Prompt Registry Signed-off-by: Yi Yao <[email protected]> --------- Signed-off-by: Yi Yao <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent c595106 commit 2a74e9e

36 files changed

+1601
-118
lines changed

.github/workflows/docker/compose/chathistory-compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# this file should be run in the root of the repo
55
services:
6-
chathistory-mongo:
6+
chathistory:
77
build:
88
dockerfile: comps/chathistory/src/Dockerfile
9-
image: ${REGISTRY:-opea}/chathistory-mongo:${TAG:-latest}
9+
image: ${REGISTRY:-opea}/chathistory:${TAG:-latest}

.github/workflows/docker/compose/feedback_management-compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# this file should be run in the root of the repo
55
services:
6-
feedbackmanagement-mongo:
6+
feedbackmanagement:
77
build:
88
dockerfile: comps/feedback_management/src/Dockerfile
9-
image: ${REGISTRY:-opea}/feedbackmanagement-mongo:${TAG:-latest}
9+
image: ${REGISTRY:-opea}/feedbackmanagement:${TAG:-latest}

.github/workflows/docker/compose/prompt_registry-compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# this file should be run in the root of the repo
55
services:
6-
promptregistry-mongo:
6+
promptregistry:
77
build:
88
dockerfile: comps/prompt_registry/src/Dockerfile
9-
image: ${REGISTRY:-opea}/promptregistry-mongo:${TAG:-latest}
9+
image: ${REGISTRY:-opea}/promptregistry:${TAG:-latest}

comps/chathistory/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ It can be integrated into application by making HTTP requests to the provided AP
1717

1818
To get detailed, step-by-step instructions on deploying the `chathistory` microservice, you should consult the deployment guide. This guide will walk you through all the necessary steps, from building the Docker images to configuring your environment and running the service.
1919

20-
| Platform | Deployment Method | Database | Link |
21-
| -------- | ----------------- | -------- | --------------------------------------------------------- |
22-
| CPU | Docker | MongoDB | [Deployment Guide](./deployment/docker_compose/README.md) |
23-
| CPU | Docker Compose | MongoDB | [Deployment Guide](./deployment/docker_compose/README.md) |
20+
| Platform | Deployment Method | Database | Link |
21+
| -------- | ----------------- | -------- | ---------------------------------------------------------------- |
22+
| CPU | Docker | MongoDB | [Deployment Guide](./deployment/docker_compose/README.md) |
23+
| CPU | Docker | ArangoDB | [Deployment Guide](./deployment/docker_compose/README_arango.md) |
24+
| CPU | Docker Compose | MongoDB | [Deployment Guide](./deployment/docker_compose/README.md) |
25+
| CPU | Docker Compose | ArangoDB | [Deployment Guide](./deployment/docker_compose/README_arango.md) |

comps/chathistory/deployment/docker_compose/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export COLLECTION_NAME=${COLLECTION_NAME}
2424

2525
```bash
2626
cd ../../../../
27-
docker build -t opea/chathistory-mongo:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/chathistory/src/Dockerfile .
27+
docker build -t opea/chathistory:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/chathistory/src/Dockerfile .
2828
```
2929

3030
### Run Docker with CLI
@@ -38,15 +38,15 @@ docker build -t opea/chathistory-mongo:latest --build-arg https_proxy=$https_pro
3838
- Run the Chat History microservice
3939

4040
```bash
41-
docker run -d --name="chathistory-mongo" -p 6012:6012 -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e MONGO_HOST=${MONGO_HOST} -e MONGO_PORT=${MONGO_PORT} -e DB_NAME=${DB_NAME} -e COLLECTION_NAME=${COLLECTION_NAME} opea/chathistory-mongo:latest
41+
docker run -d --name="chathistory-mongo" -p 6012:6012 -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e MONGO_HOST=${MONGO_HOST} -e MONGO_PORT=${MONGO_PORT} -e DB_NAME=${DB_NAME} -e COLLECTION_NAME=${COLLECTION_NAME} opea/chathistory:latest
4242
```
4343

4444
---
4545

4646
## 🚀 Start Microservice with Docker Compose (Option 2)
4747

4848
```bash
49-
docker compose -f ../deployment/docker_compose/compose.yaml up -d
49+
docker compose -f ../deployment/docker_compose/compose.yaml up -d chathistory-mongo
5050
```
5151

5252
---
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# 📝 Chat History Microservice with ArangoDB
2+
3+
This README provides setup guides and all the necessary information about the Chat History microservice with ArangoDB database.
4+
5+
---
6+
7+
## Setup Environment Variables
8+
9+
```bash
10+
export http_proxy=${your_http_proxy}
11+
export https_proxy=${your_http_proxy}
12+
export OPEA_STORE_NAME="arangodb"
13+
export ARANGODB_HOST="http://localhost:8529"
14+
export ARANGODB_USERNAME="root"
15+
export ARANGODB_PASSWORD="${YOUR_ARANGO_PASSWORD}"
16+
export ARANGODB_ROOT_PASSWORD="${YOUR_ARANGO_ROOT_PASSWORD}"
17+
export ARANGODB_DB_NAME="${YOUR_ARANGODB_DB_NAME-_system}"
18+
export ARANGODB_COLLECTION_NAME="${YOUR_ARANGODB_COLLECTION_NAME-default}"
19+
export ENABLE_MCP=false # Set to true to enable MCP support
20+
```
21+
22+
---
23+
24+
## 🚀 Start Microservice with Docker (Option 1)
25+
26+
### Build Docker Image
27+
28+
```bash
29+
cd ../../../../
30+
docker build -t opea/chathistory:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/chathistory/src/Dockerfile .
31+
```
32+
33+
### Run Docker with CLI
34+
35+
- Run ArangoDB image container
36+
37+
```bash
38+
docker run -d -p 8529:8529 --name=arango-vector-db -e ARANGO_ROOT_PASSWORD=${ARANGO_ROOT_PASSWORD} arangodb/arangodb:latest
39+
```
40+
41+
- Run the Chat History microservice
42+
43+
```bash
44+
docker run -d --name="chathistory-arango-server" -p 6012:6012 -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e ARANGODB_HOST=${ARANGODB_HOST} -e ARANGODB_USERNAME=${ARANGODB_USERNAME} -e ARANGODB_PASSWORD=${ARANGODB_PASSWORD} -e ARANGODB_DB_NAME=${ARANGODB_DB_NAME} -e ARANGODB_COLLECTION_NAME=${ARANGODB_COLLECTION_NAME} -e ENABLE_MCP=${ENABLE_MCP} opea/chathistory:latest
45+
```
46+
47+
---
48+
49+
## 🚀 Start Microservice with Docker Compose (Option 2)
50+
51+
```bash
52+
docker compose -f ../deployment/docker_compose/compose.yaml up -d chathistory-arango
53+
```
54+
55+
---
56+
57+
## ✅ Invoke Microservice
58+
59+
The Chat History microservice exposes the following API endpoints:
60+
61+
- Create new chat conversation
62+
63+
```bash
64+
curl -X 'POST' \
65+
http://${host_ip}:6012/v1/chathistory/create \
66+
-H 'accept: application/json' \
67+
-H 'Content-Type: application/json' \
68+
-d '{
69+
"data": {
70+
"messages": "test Messages", "user": "test"
71+
}
72+
}'
73+
```
74+
75+
- Get all the Conversations for a user
76+
77+
```bash
78+
curl -X 'POST' \
79+
http://${host_ip}:6012/v1/chathistory/get \
80+
-H 'accept: application/json' \
81+
-H 'Content-Type: application/json' \
82+
-d '{
83+
"user": "test"}'
84+
```
85+
86+
- Get a specific conversation by id.
87+
88+
```bash
89+
curl -X 'POST' \
90+
http://${host_ip}:6012/v1/chathistory/get \
91+
-H 'accept: application/json' \
92+
-H 'Content-Type: application/json' \
93+
-d '{
94+
"user": "test", "id":"YOU_COLLECTION_NAME/YOU_DOC_KEY"}'
95+
```
96+
97+
- Update the conversation by id.
98+
99+
```bash
100+
curl -X 'POST' \
101+
http://${host_ip}:6012/v1/chathistory/create \
102+
-H 'accept: application/json' \
103+
-H 'Content-Type: application/json' \
104+
-d '{
105+
"data": {
106+
"messages": "test Messages Update", "user": "test"
107+
},
108+
"id":"YOU_COLLECTION_NAME/YOU_DOC_KEY"
109+
}'
110+
```
111+
112+
- Delete a stored conversation.
113+
114+
```bash
115+
curl -X 'POST' \
116+
http://${host_ip}:6012/v1/chathistory/delete \
117+
-H 'accept: application/json' \
118+
-H 'Content-Type: application/json' \
119+
-d '{
120+
"user": "test", "id":"YOU_COLLECTION_NAME/YOU_DOC_KEY"}'
121+
```

comps/chathistory/deployment/docker_compose/compose.yaml

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,70 @@ services:
1313
https_proxy: ${https_proxy}
1414
no_proxy: ${no_proxy}
1515
command: mongod --quiet --logpath /dev/null
16+
healthcheck:
17+
test: echo 'db.runCommand("ping").ok' | mongosh --port 27017 --quiet
18+
interval: 10s
19+
timeout: 5s
20+
retries: 5
21+
start_period: 20s
1622

1723
chathistory-mongo:
18-
image: ${REGISTRY:-opea}/chathistory-mongo:${TAG:-latest}
24+
image: ${REGISTRY:-opea}/chathistory:${TAG:-latest}
1925
container_name: chathistory-mongo-server
26+
depends_on:
27+
mongo:
28+
condition: service_healthy
2029
ports:
2130
- "${CHATHISTORY_PORT:-6012}:6012"
2231
ipc: host
2332
environment:
2433
http_proxy: ${http_proxy}
2534
no_proxy: ${no_proxy}
2635
https_proxy: ${https_proxy}
27-
OPEA_STORE_NAME: ${OPEA_STORE_NAME:-mongodb}
36+
OPEA_STORE_NAME: "mongodb"
2837
MONGO_HOST: ${MONGO_HOST}
2938
MONGO_PORT: ${MONGO_PORT}
3039
COLLECTION_NAME: ${COLLECTION_NAME}
3140
ENABLE_MCP: ${ENABLE_MCP:-false}
3241
restart: unless-stopped
3342

43+
arango-vector-db:
44+
image: arangodb/arangodb:3.12.4
45+
container_name: arango-vector-db
46+
ports:
47+
- "8529:8529"
48+
environment:
49+
ARANGO_ROOT_PASSWORD: ${ARANGODB_ROOT_PASSWORD:-test}
50+
command: ["--experimental-vector-index=true"]
51+
restart: unless-stopped
52+
healthcheck:
53+
test: ["CMD-SHELL", "arangosh --version"]
54+
timeout: 10s
55+
retries: 3
56+
start_period: 10s
57+
58+
chathistory-arango:
59+
image: ${REGISTRY:-opea}/chathistory:${TAG:-latest}
60+
container_name: chathistory-arango-server
61+
depends_on:
62+
arango-vector-db:
63+
condition: service_healthy
64+
ports:
65+
- "${CHATHISTORY_PORT:-6012}:6012"
66+
ipc: host
67+
environment:
68+
http_proxy: ${http_proxy}
69+
no_proxy: ${no_proxy}
70+
https_proxy: ${https_proxy}
71+
OPEA_STORE_NAME: "arangodb"
72+
ARANGODB_HOST: ${ARANGODB_HOST-http://localhost:8529}
73+
ARANGODB_USERNAME: ${ARANGODB_USERNAME-root}
74+
ARANGODB_PASSWORD: ${ARANGODB_PASSWORD-test}
75+
ARANGODB_DB_NAME: ${ARANGODB_DB_NAME-_system}
76+
ARANGODB_COLLECTION_NAME: ${ARANGODB_COLLECTION_NAME-default}
77+
ENABLE_MCP: ${ENABLE_MCP:-false}
78+
restart: unless-stopped
79+
3480
networks:
3581
default:
3682
driver: bridge

comps/chathistory/src/integrations/data_store.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from comps.cores.proto.api_protocol import ChatCompletionRequest
1010
from comps.cores.storages.models import ChatId, ChatMessage
11-
from comps.cores.storages.stores import column_to_id, get_store, id_to_column
11+
from comps.cores.storages.stores import get_store, postget, prepersist
1212

1313

1414
class ChatMessageDto(BaseModel):
@@ -28,7 +28,7 @@ def _prepersist(document: ChatMessage) -> dict:
2828
dict: A dictionary representation of the ChatMessage, ready for persistence.
2929
"""
3030
data_dict = document.model_dump(by_alias=True, mode="json")
31-
data_dict = column_to_id("id", data_dict)
31+
data_dict = prepersist("id", data_dict)
3232
return data_dict
3333

3434

@@ -41,7 +41,7 @@ def _post_getby_id(rs: dict) -> dict:
4141
Returns:
4242
dict: The processed document data, or None if the document doesn't exist.
4343
"""
44-
rs = id_to_column("id", rs)
44+
rs = postget("id", rs)
4545
return rs.get("data") if rs else None
4646

4747

@@ -55,7 +55,7 @@ def _post_getby_user(rss: list) -> list:
5555
list: A list of processed documents with the 'data' field removed.
5656
"""
5757
for rs in rss:
58-
rs = id_to_column("id", rs)
58+
rs = postget("id", rs)
5959
rs.pop("data")
6060
return rss
6161

comps/chathistory/src/opea_chathistory_microservice.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def get_first_string(value):
3030

3131

3232
@register_microservice(
33-
name="opea_service@chathistory_mongo",
33+
name=f"opea_service@chathistory_{get_store_name()}",
3434
endpoint="/v1/chathistory/create",
3535
host="0.0.0.0",
3636
input_datatype=ChatMessage,
@@ -64,7 +64,7 @@ async def create_documents(document: ChatMessage):
6464

6565

6666
@register_microservice(
67-
name="opea_service@chathistory_mongo",
67+
name=f"opea_service@chathistory_{get_store_name()}",
6868
endpoint="/v1/chathistory/get",
6969
host="0.0.0.0",
7070
input_datatype=ChatId,
@@ -96,7 +96,7 @@ async def get_documents(document: ChatId):
9696

9797

9898
@register_microservice(
99-
name="opea_service@chathistory_mongo",
99+
name=f"opea_service@chathistory_{get_store_name()}",
100100
endpoint="/v1/chathistory/delete",
101101
host="0.0.0.0",
102102
input_datatype=ChatId,
@@ -128,4 +128,4 @@ async def delete_documents(document: ChatId):
128128

129129

130130
if __name__ == "__main__":
131-
opea_microservices["opea_service@chathistory_mongo"].start()
131+
opea_microservices[f"opea_service@chathistory_{get_store_name()}"].start()

0 commit comments

Comments
 (0)