Skip to content

Commit c6a6e72

Browse files
committed
Add chromadb
1 parent ef5f603 commit c6a6e72

21 files changed

+251
-169
lines changed

deploy/docker/docker-compose.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,16 @@ services:
167167
- MONGO_DB_PASSWORD=crapisecretpassword
168168
- MONGO_DB_NAME=crapi
169169
- DEFAULT_MODEL=gpt-4o-mini
170-
- CHROMA_PERSIST_DIRECTORY=/app/vectorstore
170+
- CHROMA_HOST=chromadb
171+
- CHROMA_PORT=8000
171172
# - CHATBOT_OPENAI_API_KEY=
172-
volumes:
173-
- chatbot-vectors:/app/vectorstore
174173
depends_on:
175174
mongodb:
176175
condition: service_healthy
177176
crapi-identity:
178177
condition: service_healthy
178+
chromadb:
179+
condition: service_healthy
179180
# ports:
180181
# - "${LISTEN_IP:-127.0.0.1}:5002:5002"
181182

@@ -257,6 +258,16 @@ services:
257258
cpus: '0.3'
258259
memory: 128M
259260

261+
chromadb:
262+
container_name: chromadb
263+
image: 'chromadb/chroma:latest'
264+
environment:
265+
IS_PERSISTENT: 'TRUE'
266+
volumes:
267+
- chromadb-data:/data
268+
# ports:
269+
# - "${LISTEN_IP:-127.0.0.1}:8000:8000"
270+
260271
mailhog:
261272
user: root
262273
container_name: mailhog
@@ -298,4 +309,4 @@ services:
298309
volumes:
299310
mongodb-data:
300311
postgresql-data:
301-
chatbot-vectors:
312+
chromadb-data:

deploy/helm/templates/chatbot/config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ data:
2222
MONGO_DB_NAME: {{ .Values.mongodb.config.mongoDbName }}
2323
CHATBOT_OPENAI_API_KEY: {{ .Values.openAIApiKey }}
2424
DEFAULT_MODEL: {{ .Values.chatbot.config.defaultModel | quote }}
25-
CHROMA_PERSIST_DIRECTORY: {{ .Values.chatbot.config.chromaPersistDirectory | quote }}
25+
CHROMA_HOST: {{ .Values.chromadb.service.name }}
26+
CHROMA_PORT: {{ .Values.chromadb.port | quote }}

deploy/helm/templates/chatbot/deployment.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,3 @@ spec:
5757
port: {{ .Values.chatbot.port }}
5858
initialDelaySeconds: 15
5959
periodSeconds: 10
60-
volumeMounts:
61-
- name: chatbot-vectors
62-
mountPath: {{ .Values.chatbot.config.chromaPersistDirectory | quote }}
63-
volumes:
64-
- name: chatbot-vectors
65-
persistentVolumeClaim:
66-
claimName: {{ .Values.chatbot.storage.pvc.name }}

deploy/helm/templates/chatbot/storage.yaml

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ .Values.chromadb.config.name }}
5+
labels:
6+
release: {{ .Release.Name }}
7+
{{- with .Values.chromadb.config.labels }}
8+
{{- toYaml . | nindent 4 }}
9+
{{- end }}
10+
data:
11+
IS_PERSISTENT: {{ .Values.chromadb.config.isPersistent | quote }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ .Values.chromadb.service.name }}
5+
labels:
6+
release: {{ .Release.Name }}
7+
{{- with .Values.chromadb.service.labels }}
8+
{{- toYaml . | nindent 4 }}
9+
{{- end }}
10+
spec:
11+
ports:
12+
- port: {{ .Values.chromadb.port }}
13+
name: chromadb
14+
selector:
15+
{{- toYaml .Values.chromadb.serviceSelectorLabels | nindent 4 }}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apiVersion: apps/v1
2+
kind: StatefulSet
3+
metadata:
4+
name: {{ .Values.chromadb.name }}
5+
labels:
6+
release: {{ .Release.Name }}
7+
{{- with .Values.chromadb.statefulsetLabels }}
8+
{{- toYaml . | nindent 4 }}
9+
{{- end }}
10+
spec:
11+
serviceName: {{ .Values.chromadb.service.name }}
12+
replicas: {{ .Values.chromadb.replicaCount }}
13+
selector:
14+
matchLabels:
15+
{{- toYaml .Values.chromadb.statefulsetSelectorMatchLabels | nindent 6 }}
16+
template:
17+
metadata:
18+
labels:
19+
release: {{ .Release.Name }}
20+
{{- toYaml .Values.chromadb.podLabels | nindent 8 }}
21+
spec:
22+
containers:
23+
- name: {{ .Values.chromadb.name }}
24+
image: {{ .Values.chromadb.image }}:{{ .Values.chromadb.version }}
25+
imagePullPolicy: {{ .Values.chromadb.imagePullPolicy }}
26+
ports:
27+
- containerPort: {{ .Values.chromadb.port }}
28+
envFrom:
29+
- configMapRef:
30+
name: {{ .Values.chromadb.config.name }}
31+
volumeMounts:
32+
- mountPath: /data
33+
name: chromadb-data
34+
volumes:
35+
- name: chromadb-data
36+
persistentVolumeClaim:
37+
claimName: {{ .Values.chromadb.storage.pvc.name }}
38+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{- if eq .Values.chromadb.storage.type "manual" }}
2+
apiVersion: v1
3+
kind: PersistentVolume
4+
metadata:
5+
name: {{ .Values.chromadb.storage.pv.name }}
6+
labels:
7+
release: {{ .Release.Name }}
8+
{{- toYaml .Values.chromadb.storage.pv.labels | nindent 4 }}
9+
spec:
10+
storageClassName: {{ .Values.chromadb.storage.type }}
11+
capacity:
12+
storage: {{ .Values.chromadb.storage.pv.resources.storage }}
13+
accessModes:
14+
- ReadWriteOnce
15+
hostPath:
16+
path: {{ .Values.chromadb.storage.pv.hostPath }}
17+
---
18+
{{- end }}
19+
apiVersion: v1
20+
kind: PersistentVolumeClaim
21+
metadata:
22+
name: {{ .Values.chromadb.storage.pvc.name }}
23+
labels:
24+
release: {{ .Release.Name }}
25+
{{- toYaml .Values.chromadb.storage.pvc.labels | nindent 4 }}
26+
spec:
27+
{{- if ne .Values.chromadb.storage.type "default" }}
28+
storageClassName: {{ .Values.chromadb.storage.type }}
29+
{{- end }}
30+
accessModes:
31+
- ReadWriteOnce
32+
resources:
33+
{{- toYaml .Values.chromadb.storage.pvc.resources | nindent 4 }}
34+

services/chatbot/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ faiss-cpu==1.11.0
1919
psycopg2-binary
2020
uvicorn==0.35.0
2121
fastmcp==2.10.2
22-
chromadb==1.0.15
22+
chromadb-client==1.0.15

services/chatbot/src/chatbot/chat_api.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
get_or_create_session_id,
1111
store_api_key,
1212
store_model_name,
13-
get_user_jwt
13+
get_user_jwt,
1414
)
1515

1616
chat_bp = Blueprint("chat", __name__, url_prefix="/genai")
@@ -38,6 +38,7 @@ async def init():
3838
await store_api_key(session_id, openai_api_key)
3939
return jsonify({"message": "Initialized"}), 200
4040

41+
4142
@chat_bp.route("/model", methods=["POST"])
4243
async def model():
4344
session_id = await get_or_create_session_id()
@@ -49,6 +50,7 @@ async def model():
4950
await store_model_name(session_id, model_name)
5051
return jsonify({"model_used": model_name}), 200
5152

53+
5254
@chat_bp.route("/ask", methods=["POST"])
5355
async def chat():
5456
session_id = await get_or_create_session_id()
@@ -62,7 +64,9 @@ async def chat():
6264
id = data.get("id", uuid4().int & (1 << 63) - 1)
6365
if not message:
6466
return jsonify({"message": "Message is required", "id": id}), 400
65-
reply, response_id = await process_user_message(session_id, message, openai_api_key, model_name, user_jwt)
67+
reply, response_id = await process_user_message(
68+
session_id, message, openai_api_key, model_name, user_jwt
69+
)
6670
return jsonify({"id": response_id, "message": reply}), 200
6771

6872

0 commit comments

Comments
 (0)