Skip to content

Commit 2d27cd6

Browse files
Support Redis for ChatHistory, Feedback Management, Prompt Registry (#1925)
* Support Redis 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 0473fb5 commit 2d27cd6

File tree

19 files changed

+1644
-210
lines changed

19 files changed

+1644
-210
lines changed

comps/chathistory/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ To get detailed, step-by-step instructions on deploying the `chathistory` micros
1919

2020
| Platform | Deployment Method | Database | Link |
2121
| -------- | ----------------- | -------- | ---------------------------------------------------------------- |
22-
| CPU | Docker | MongoDB | [Deployment Guide](./deployment/docker_compose/README.md) |
2322
| CPU | Docker | ArangoDB | [Deployment Guide](./deployment/docker_compose/README_arango.md) |
24-
| CPU | Docker Compose | MongoDB | [Deployment Guide](./deployment/docker_compose/README.md) |
23+
| CPU | Docker | MongoDB | [Deployment Guide](./deployment/docker_compose/README.md) |
24+
| CPU | Docker | Redis | [Deployment Guide](./deployment/docker_compose/README_redis.md) |
2525
| CPU | Docker Compose | ArangoDB | [Deployment Guide](./deployment/docker_compose/README_arango.md) |
26+
| CPU | Docker Compose | MongoDB | [Deployment Guide](./deployment/docker_compose/README.md) |
27+
| CPU | Docker Compose | Redis | [Deployment Guide](./deployment/docker_compose/README_redis.md) |
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# 📝 Chat History Microservice with Redis
2+
3+
This README provides setup guides and all the necessary information about the Chat History microservice with Redis 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="redis"
13+
export REDIS_URL="${REDIS_URL-redis://localhost:6379}"
14+
export INDEX_NAME="${INDEX_NAME-opea:index}"
15+
export DOC_PREFIX="${DOC_PREFIX-doc:}"
16+
export AUTO_CREATE_INDEX="${AUTO_CREATE_INDEX-true}"
17+
export ENABLE_MCP=false # Set to true to enable MCP support
18+
```
19+
20+
---
21+
22+
## 🚀 Start Microservice with Docker (Option 1)
23+
24+
### Build Docker Image
25+
26+
```bash
27+
cd ../../../../
28+
docker build -t opea/chathistory:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/chathistory/src/Dockerfile .
29+
```
30+
31+
### Run Docker with CLI
32+
33+
- Run Redis image container
34+
35+
```bash
36+
docker run -d -p 6379:6379 --name=redis-kv-store redis/redis-stack:latest
37+
```
38+
39+
- Run the Chat History microservice
40+
41+
```bash
42+
docker run -d --name="chathistory-redis-server" -p 6012:6012 -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy -e OPEA_STORE_NAME=redis -e REDIS_URL=${REDIS_URL} -e INDEX_NAME=${INDEX_NAME} -e DOC_PREFIX=${DOC_PREFIX} -e AUTO_CREATE_INDEX=${AUTO_CREATE_INDEX} -e ENABLE_MCP=${ENABLE_MCP} opea/chathistory:latest
43+
```
44+
45+
---
46+
47+
## 🚀 Start Microservice with Docker Compose (Option 2)
48+
49+
```bash
50+
docker compose -f ../deployment/docker_compose/compose.yaml up -d chathistory-redis
51+
```
52+
53+
---
54+
55+
## ✅ Invoke Microservice
56+
57+
The Chat History microservice exposes the following API endpoints:
58+
59+
- Create new chat conversation
60+
61+
```bash
62+
curl -X 'POST' \
63+
http://${host_ip}:6012/v1/chathistory/create \
64+
-H 'accept: application/json' \
65+
-H 'Content-Type: application/json' \
66+
-d '{
67+
"data": {
68+
"messages": "test Messages", "user": "test"
69+
}
70+
}'
71+
```
72+
73+
- Get all the Conversations for a user
74+
75+
```bash
76+
curl -X 'POST' \
77+
http://${host_ip}:6012/v1/chathistory/get \
78+
-H 'accept: application/json' \
79+
-H 'Content-Type: application/json' \
80+
-d '{
81+
"user": "test"}'
82+
```
83+
84+
- Get a specific conversation by id.
85+
86+
```bash
87+
curl -X 'POST' \
88+
http://${host_ip}:6012/v1/chathistory/get \
89+
-H 'accept: application/json' \
90+
-H 'Content-Type: application/json' \
91+
-d '{
92+
"user": "test", "id":"YOU_COLLECTION_NAME/YOU_DOC_KEY"}'
93+
```
94+
95+
- Update the conversation by id.
96+
97+
```bash
98+
curl -X 'POST' \
99+
http://${host_ip}:6012/v1/chathistory/create \
100+
-H 'accept: application/json' \
101+
-H 'Content-Type: application/json' \
102+
-d '{
103+
"data": {
104+
"messages": "test Messages Update", "user": "test"
105+
},
106+
"id":"YOU_COLLECTION_NAME/YOU_DOC_KEY"
107+
}'
108+
```
109+
110+
- Delete a stored conversation.
111+
112+
```bash
113+
curl -X 'POST' \
114+
http://${host_ip}:6012/v1/chathistory/delete \
115+
-H 'accept: application/json' \
116+
-H 'Content-Type: application/json' \
117+
-d '{
118+
"user": "test", "id":"YOU_COLLECTION_NAME/YOU_DOC_KEY"}'
119+
```

comps/chathistory/deployment/docker_compose/compose.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,43 @@ services:
7777
ENABLE_MCP: ${ENABLE_MCP:-false}
7878
restart: unless-stopped
7979

80+
redis-kv-store:
81+
image: redis/redis-stack:7.2.0-v9
82+
container_name: redis-kv-store
83+
ports:
84+
- "${REDIS_PORT3:-6379}:6379"
85+
- "${REDIS_PORT4:-8001}:8001"
86+
environment:
87+
- no_proxy=${no_proxy}
88+
- http_proxy=${http_proxy}
89+
- https_proxy=${https_proxy}
90+
healthcheck:
91+
test: ["CMD", "redis-cli", "ping"]
92+
timeout: 10s
93+
retries: 3
94+
start_period: 10s
95+
96+
chathistory-redis:
97+
image: ${REGISTRY:-opea}/chathistory:${TAG:-latest}
98+
container_name: chathistory-redis-server
99+
depends_on:
100+
redis-kv-store:
101+
condition: service_healthy
102+
ports:
103+
- "${CHATHISTORY_PORT:-6012}:6012"
104+
ipc: host
105+
environment:
106+
http_proxy: ${http_proxy}
107+
no_proxy: ${no_proxy}
108+
https_proxy: ${https_proxy}
109+
OPEA_STORE_NAME: "redis"
110+
REDIS_URL: ${REDIS_URL-redis://localhost:6379}
111+
INDEX_NAME: ${INDEX_NAME-opea:index}
112+
DOC_PREFIX: ${DOC_PREFIX-doc:}
113+
AUTO_CREATE_INDEX: ${AUTO_CREATE_INDEX-true}
114+
ENABLE_MCP: ${ENABLE_MCP:-false}
115+
restart: unless-stopped
116+
80117
networks:
81118
default:
82119
driver: bridge

comps/cores/storages/arangodb.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ async def asearch_by_keyword(self, keyword: str, max_results: int = 5, **kwargs)
370370

371371
# Check if a collection with the same name exists (which would conflict)
372372
if await self.db.has_collection(view_name):
373-
logger.error(f"A collection named '{view_name}' exists, cannot create view with same name.")
374373
raise Exception(f"A collection named '{view_name}' exists, cannot create view with same name.")
375374

376375
# Check if view already exists and delete it to recreate with fresh settings

0 commit comments

Comments
 (0)