Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions helm/templates/policies/postgres.policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ spec:
- podSelector:
matchLabels:
lies.exposed/name: worker

- podSelector:
matchLabels:
lies.exposed/name: db-dump
egress:
- to:
- podSelector:
Expand All @@ -40,3 +44,7 @@ spec:
- podSelector:
matchLabels:
lies.exposed/name: worker

- podSelector:
matchLabels:
lies.exposed/name: db-dump
2 changes: 1 addition & 1 deletion helm/templates/services/ai-bot/ai-bot.configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data:
"apiKey": "{{ .Values.localai.openAIApiKey }}",
"models": {
"summarize": "gpt-4o",
"chat": "qwen3-embedding-8b",
"chat": "qwen3-8b",
"embeddings": "qwen3-embedding-8b"
}
}
Expand Down
59 changes: 59 additions & 0 deletions helm/templates/services/db/db-dump-prune.job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: db-dump-prune
namespace: {{ .Release.Namespace }}
{{ tuple . "db-dump-prune" | include "db.labels" | indent 2 }}
spec:
schedule: {{ .Values.db.pruneSchedule | default "0 1 * * 1" | quote }} # Monday 01:00 UTC
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 1
jobTemplate:
spec:
backoffLimit: 1
activeDeadlineSeconds: 900
template:
metadata:
{{ tuple . "db-dump-prune" | include "db.labels" | indent 10 }}
spec:
imagePullSecrets:
- name: ghcr-io-registry-auth
containers:
- name: db-dump-prune
image: alpine:3.18
command:
- sh
- -c
- |
set -e -x
cd /dump || { echo "Dump dir not present"; exit 0; }
pattern="lies-exposed-db-*.sql"
# list files most-recent-first, keep first 10, remove the rest
files=$(ls -1t $pattern 2>/dev/null || true)
if [ -z "$files" ]; then
echo "No dump files found"
exit 0
fi
to_delete=$(echo "$files" | tail -n +11 || true)
if [ -z "$to_delete" ]; then
echo "Nothing to prune; <=10 dumps present"
exit 0
fi
echo "Pruning the following files:"
echo "$to_delete"
echo "$to_delete" | while read -r f; do rm -f -- "$f"; done
echo "Prune completed"
imagePullPolicy: IfNotPresent
resources:
limits:
memory: "128Mi"
volumeMounts:
- name: dump-host
mountPath: /dump
restartPolicy: Never
volumes:
- name: dump-host
hostPath:
path: {{ .Values.db.dumpHostPath | quote }}
type: DirectoryOrCreate
51 changes: 51 additions & 0 deletions helm/templates/services/db/db-dump.job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: db-dump
namespace: {{ .Release.Namespace }}
{{ tuple . "db-dump" | include "db.labels" | indent 2 }}
spec:
schedule: {{ .Values.db.dumpSchedule | default "0 23 * * 0" | quote }} # Every Sunday, 11pm UTC
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 1
jobTemplate:
spec:
backoffLimit: 1
activeDeadlineSeconds: 1800
template:
metadata:
{{ tuple . "db-dump" | include "db.labels" | indent 10 }}
spec:
imagePullSecrets:
- name: ghcr-io-registry-auth
containers:
- name: db-dump
image: postgres:17
envFrom:
- configMapRef:
name: db-env
command:
- sh
- -c
- |
set -e -x
TIMESTAMP="$(date +%Y%m%d%H%M%S)"
FILE="/dump/lies-exposed-db-${TIMESTAMP}.sql"
echo "Starting pg_dump -> ${FILE}"
host={{ .Values.db.host }}
pg_dump "user=$POSTGRES_USER password=$POSTGRES_PASSWORD port=5432 host=$host dbname=$POSTGRES_DB connect_timeout=30" -v -O -f "${FILE}"
echo "Dump written to ${FILE}"
imagePullPolicy: IfNotPresent
resources:
limits:
memory: "256Mi"
volumeMounts:
- name: dump-host
mountPath: /dump
restartPolicy: Never
volumes:
- name: dump-host
hostPath:
path: {{ .Values.db.dumpHostPath | quote }}
type: DirectoryOrCreate
10 changes: 5 additions & 5 deletions helm/templates/services/localai/localai.deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ spec:
volumeMounts:
- name: localai-models-pv
mountPath: /models
- name: localai-backends-pv
mountPath: /backends
# - name: localai-backends-pv
# mountPath: /backends
resources:
limits:
memory: 8Gi
Expand All @@ -54,6 +54,6 @@ spec:
- name: localai-models-pv
persistentVolumeClaim:
claimName: localai-models-pv-claim
- name: localai-backends-pv
persistentVolumeClaim:
claimName: localai-backends-pv-claim
# - name: localai-backends-pv
# persistentVolumeClaim:
# claimName: localai-backends-pv-claim
1 change: 1 addition & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ aiBot:
db:
host: db.liexp.dev
port: 8432
dumpHostPath: /home/node/db/dump

redis:
host: redis.liexp-dev.svc.cluster.local
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
"typescript-eslint": "^8.42.0",
"vitest": "^3.2.3"
},
"packageManager": "pnpm@10.15.1+sha512.34e538c329b5553014ca8e8f4535997f96180a1d0f614339357449935350d924e22f8614682191264ec33d1462ac21561aff97f6bb18065351c162c7e8f6de67",
"packageManager": "pnpm@10.17.1+sha512.17c560fca4867ae9473a3899ad84a88334914f379be46d455cbf92e5cf4b39d34985d452d2583baf19967fa76cb5c17bc9e245529d0b98745721aa7200ecaf7a",
"engines": {
"node": ">= 24",
"npm": "please use pnpm >= 9",
"npm": "please use pnpm >= 10",
"pnpm": ">= 9",
"yarn": "please use pnpm >= 9"
"yarn": "please use pnpm >= 10"
},
"resolutions": {
"minimist": "^1.2.8",
Expand Down
10 changes: 5 additions & 5 deletions packages/@liexp/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"src/**/*.(ts|tsx|js|jsx)": "eslint --fix"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.879.0",
"@aws-sdk/lib-storage": "^3.879.0",
"@aws-sdk/s3-request-presigner": "^3.879.0",
"@aws-sdk/client-s3": "^3.895.0",
"@aws-sdk/lib-storage": "^3.895.0",
"@aws-sdk/s3-request-presigner": "^3.895.0",
"@databases/escape-identifier": "^1.0.3",
"@databases/sql": "^3.3.0",
"@liexp/core": "workspace:*",
Expand All @@ -42,7 +42,7 @@
"typeorm": "^0.3.24"
},
"devDependencies": {
"@aws-sdk/types": "^3.804.0",
"@aws-sdk/types": "^3.893.0",
"@langchain/core": "^0.3.77",
"@langchain/openai": "^0.6.13",
"@liexp/test": "workspace:*",
Expand Down Expand Up @@ -93,5 +93,5 @@
"wink-nlp": "^2.3.0",
"wink-nlp-utils": "^2.1.0"
},
"packageManager": "pnpm@10.15.1+sha512.34e538c329b5553014ca8e8f4535997f96180a1d0f614339357449935350d924e22f8614682191264ec33d1462ac21561aff97f6bb18065351c162c7e8f6de67"
"packageManager": "pnpm@10.17.1+sha512.17c560fca4867ae9473a3899ad84a88334914f379be46d455cbf92e5cf4b39d34985d452d2583baf19967fa76cb5c17bc9e245529d0b98745721aa7200ecaf7a"
}
43 changes: 31 additions & 12 deletions packages/@liexp/backend/src/flows/ai/runRagChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,49 @@ export const runRagChain =
}, toAPIError);
};

export const runRagChainStream =
export const runRagChainStream = <
C extends LangchainContext & LoggerContext = LangchainContext & LoggerContext,
>(
inputs: RunnableLike,
chain: RunnableLike,
question: string,
mode: "stream" | "invoke" = "stream",
): ReaderTaskEither<C, APIError, string> => {
return runRunnableSequence(
RunnableSequence.from([
{ ...inputs, question: new RunnablePassthrough() },
chain,
]),
question,
mode,
);
};

export const runRunnableSequence =
<
C extends LangchainContext & LoggerContext = LangchainContext &
LoggerContext,
>(
inputs: RunnableLike,
chain: RunnableLike,
inputs: RunnableSequence,
question: string,
mode: "stream" | "invoke" = "stream",
): ReaderTaskEither<C, APIError, string> =>
(ctx) => {
return fp.TE.tryCatch(async () => {
const ragChain = RunnableSequence.from([
{ ...inputs, question: new RunnablePassthrough() },
chain,
]);

const stream = await ragChain.stream(question);
ctx.logger.debug.log("Running sequence in mode %s", mode);

let output = "";
for await (const chunk of stream) {
output += chunk;
if (mode === "stream") {
const stream = await inputs.stream(question);

for await (const chunk of stream) {
output += chunk;
}
} else {
output = await inputs.invoke(question);
}

ctx.logger.debug.log("RAG chain stream output %O", output);
ctx.logger.debug.log("Output %s", output);

return output;
}, toAPIError);
Expand Down
5 changes: 5 additions & 0 deletions packages/@liexp/backend/src/flows/ai/storeRetriever.flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export const getStoreRetriever =
});
const splits = await textSplitter.splitDocuments(documents);

ctx.logger.debug.log(
`Split documents into %d sub-documents.`,
splits.length,
);

const vectorStore = await MemoryVectorStore.fromDocuments(
splits,
ctx.langchain.embeddings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const updateEventFromDocuments = <
"model",
() => (ctx) =>
fp.TE.right(
ctx.langchain.chat.bind({
ctx.langchain.chat.withConfig({
response_format: {
type: "json_object",
},
Expand Down
Loading
Loading