Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.

Commit d45aa38

Browse files
authored
(EAI-1119) add category, clearer logging, cron runs on dev db too (#838)
* add category, clearer logging, cron runs on dev db too * better variable name and description
1 parent 74fde3a commit d45aa38

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

packages/scripts/environments/production.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ cronJobs:
5757
backoffLimit: 2
5858

5959
- name: process-citations-for-metrics
60-
schedule: "0 3 * * *" # every day at 3 AM UTC
60+
schedule: "1 0 * * *" # every day at 00:01 (12:01 AM) UTC
6161
command: ["npm", "run", "scripts:getLLMAnswers"]
6262
env:
6363
MONGODB_DATABASE_NAME: docs-chatbot-prod

packages/scripts/environments/staging.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,27 @@ cronJobs:
8686
memory: 5Gi
8787
backoffLimit: 2
8888

89+
- name: process-citations-for-metrics-dev
90+
schedule: "30 0 * * *" # every day at 00:30 (12:30 AM) UTC
91+
command: ["npm", "run", "scripts:getLLMAnswers"]
92+
env:
93+
MONGODB_DATABASE_NAME: docs-chatbot-dev
94+
PROFOUND_API_URL: https://api.tryprofound.com/v1
95+
BRAINTRUST_ENDPOINT: https://api.braintrust.dev/v1/proxy
96+
envSecrets:
97+
MONGODB_CONNECTION_URI: docs-chatbot-scripts-admin-dev
98+
PROFOUND_API_KEY: docs-chatbot-staging
99+
PROFOUND_CATALOG_ID_EDU: docs-chatbot-staging
100+
BRAINTRUST_API_KEY: docs-chatbot-staging
101+
resources:
102+
requests:
103+
cpu: 100m
104+
memory: 2Gi
105+
limits:
106+
cpu: 500m
107+
memory: 5Gi
108+
backoffLimit: 2
109+
89110
# Alerts
90111
defaultAlerts:
91112
enabled: true

packages/scripts/src/profound/getAndProcessAnswers.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ interface CaseByProfoundPromptId {
7575
expected: string;
7676
tags: string[];
7777
caseId: ObjectId;
78+
metadata: {
79+
category: string;
80+
}
7881
};
7982
}
8083
const casesByPromptId = async (
@@ -86,6 +89,7 @@ const casesByPromptId = async (
8689
expected: doc.expected,
8790
tags: doc.tags,
8891
caseId: doc._id,
92+
metadata: doc.metadata,
8993
};
9094
return map;
9195
}, {} as CaseByProfoundPromptId);
@@ -189,6 +193,7 @@ export const main = async (startDateArg?: string, endDateArg?: string) => {
189193
};
190194
const referenceAlignmentFn = makeReferenceAlignment(openAiClient, config);
191195
const answerRecords: any[] = [];
196+
const promptsWithNoAssociatedCase = new Set()
192197
const { results, errors } = await PromisePool.for(answers)
193198
.withConcurrency(model.maxConcurrency ?? 5)
194199
.process(async (currentAnswer) => {
@@ -204,7 +209,7 @@ export const main = async (startDateArg?: string, endDateArg?: string) => {
204209
const currentPromptId = currentAnswer.prompt_id;
205210
const currentCase = casesByPromptMap[currentPromptId];
206211
if (!currentCase) {
207-
console.log(`No case found for ${currentPrompt}`);
212+
promptsWithNoAssociatedCase.add(`${currentPromptId} - ${currentPrompt}`);
208213
}
209214

210215
// calculate reference alignment score
@@ -239,8 +244,8 @@ export const main = async (startDateArg?: string, endDateArg?: string) => {
239244
} catch (err) {
240245
console.error("Error in referenceAlignmentFn:", {
241246
prompt: currentAnswer.prompt,
242-
response: currentAnswer.response,
243-
expected: currentCase?.expected,
247+
profoundPromptId: currentAnswer.prompt_id,
248+
profoundRunId: currentAnswer.run_id,
244249
error: err,
245250
});
246251
referenceAlignment = {
@@ -283,12 +288,17 @@ export const main = async (startDateArg?: string, endDateArg?: string) => {
283288
expectedResponse: currentCase?.expected,
284289
profoundPromptId: currentAnswer.prompt_id,
285290
profoundRunId: currentAnswer.run_id,
286-
dataset: currentCase ? getDataset(currentCase.tags, datasetsByTagMap) : null
291+
dataset: currentCase ? getDataset(currentCase.tags, datasetsByTagMap) : null,
292+
category: currentCase ? currentCase.metadata.category : null
287293
};
288294
answerRecords.push(answerEngineRecord);
289295
return answerEngineRecord;
290296
});
291297

298+
console.log(`Found ${promptsWithNoAssociatedCase.size} prompts with no associated case:`)
299+
promptsWithNoAssociatedCase.forEach((promptInfo: any) => {
300+
console.log(` - ${promptInfo}`);
301+
});
292302
// update the llm_answers collection
293303
if (answerRecords.length > 0) {
294304
const bulkOps = answerRecords.map((record) => ({
@@ -306,7 +316,7 @@ export const main = async (startDateArg?: string, endDateArg?: string) => {
306316
const inserted = result.upsertedCount || 0;
307317
const updated = result.modifiedCount || 0;
308318
console.log(
309-
`BulkWrite to llm_answers collection completed: ${inserted} inserted, ${updated} updated (out of ${answerRecords.length} records).`
319+
`BulkWrite to llm_answers collection completed: ${inserted} inserted, ${updated} updated (out of ${answerRecords.length} records between ${start.toISOString()} and ${end.toISOString()}).`
310320
);
311321
} catch (err) {
312322
console.error("BulkWrite to llm_answers collection failed:", err);

0 commit comments

Comments
 (0)