Skip to content

Commit 8ff842a

Browse files
committed
add support for entry point prompts (just explain for now)
1 parent e525587 commit 8ff842a

File tree

3 files changed

+114
-1
lines changed

3 files changed

+114
-1
lines changed

packages/compass-assistant/test/assistant.eval.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { OpenAI } from 'openai';
88
import { evalCases } from './eval-cases';
99
import { fuzzyLinkMatch } from './fuzzylinkmatch';
1010
import { binaryNdcgAtK } from './binaryndcgatk';
11+
import { makeEntrypointCases } from './entrypoints';
1112

1213
const client = new OpenAI({
1314
baseURL: 'https://api.braintrust.dev/v1/proxy',
@@ -78,7 +79,9 @@ function getScorerTemperature(): number | undefined {
7879
}
7980

8081
function makeEvalCases(): ConversationEvalCase[] {
81-
return evalCases.map((c) => {
82+
const entrypointCases: ConversationEvalCase[] = makeEntrypointCases();
83+
84+
const userCases: ConversationEvalCase[] = evalCases.map((c) => {
8285
return {
8386
name: c.name ?? c.input,
8487
input: {
@@ -90,6 +93,8 @@ function makeEvalCases(): ConversationEvalCase[] {
9093
metadata: {},
9194
};
9295
});
96+
97+
return [...entrypointCases, ...userCases];
9398
}
9499

95100
async function makeAssistantCall(
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { buildExplainPlanPrompt } from '../../src/prompts';
2+
3+
const defaultExplainPlan = {
4+
queryPlanner: {
5+
plannerVersion: 1,
6+
namespace: 'account.users',
7+
indexFilterSet: false,
8+
parsedQuery: {},
9+
winningPlan: {
10+
stage: 'COLLSCAN',
11+
direction: 'forward',
12+
},
13+
rejectedPlans: [],
14+
},
15+
executionStats: {
16+
executionSuccess: true,
17+
nReturned: 1,
18+
executionTimeMillis: 0,
19+
totalKeysExamined: 0,
20+
totalDocsExamined: 1,
21+
executionStages: {
22+
stage: 'COLLSCAN',
23+
nReturned: 1,
24+
executionTimeMillisEstimate: 0,
25+
works: 3,
26+
advanced: 1,
27+
needTime: 1,
28+
needYield: 0,
29+
saveState: 0,
30+
restoreState: 0,
31+
isEOF: 1,
32+
direction: 'forward',
33+
docsExamined: 1,
34+
},
35+
},
36+
serverInfo: {
37+
host: 'M-LKXPQX2JRY',
38+
port: 27017,
39+
version: '4.4.24',
40+
gitVersion: '0b86b9b7b42ad9970c5f818c527dd86c0634243a',
41+
},
42+
ok: 1,
43+
$clusterTime: {
44+
clusterTime: {
45+
$timestamp: '7541009763346153473',
46+
},
47+
signature: {
48+
hash: 'AAAAAAAAAAAAAAAAAAAAAAAAAAA=',
49+
keyId: 0,
50+
},
51+
},
52+
operationTime: {
53+
$timestamp: '7541009763346153473',
54+
},
55+
};
56+
57+
export function buildPrompt(): string {
58+
return buildExplainPlanPrompt({
59+
explainPlan: JSON.stringify(defaultExplainPlan),
60+
}).prompt;
61+
}
62+
63+
export function buildExpected(): string {
64+
return `**Human-Readable Explanation:**
65+
66+
This query performed a collection scan (\`COLLSCAN\`) on the \`account.users\` collection, reading documents sequentially without using any indexes. The query returned one result and examined one document, completing very quickly.
67+
68+
**Performance Impact:**
69+
70+
- For small collections, a collection scan is fast and does not present a performance issue.
71+
- For large collections, collection scans can become slow because every document must be read, especially if queries become frequent or the result set grows.
72+
73+
**Optimization Suggestion:**
74+
75+
- If there are no filters in your query (i.e., it retrieves all documents), creating an index is unnecessary and provides no performance benefit.
76+
- If you add query filters in the future (e.g., searching by username or email), consider creating an index on those fields to enhance performance.
77+
- In MongoDB Compass, you can create indexes using the "Indexes" tab for your collection.
78+
79+
**Summary:**
80+
No index is needed for this query as written, but be aware collection scans do not scale well with large data. Monitor query performance as your collection grows or your query changes, and add indexes only if your query includes a filter or sort.
81+
82+
If you'd like to see how your query performs as your data grows, MongoDB Compass provides performance tools like the "Explain Plan" feature to visualize query execution and index usage.`;
83+
}
84+
85+
export function buildExpectedSources(): string[] {
86+
return [];
87+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as explainPlan from './explain-plan';
2+
3+
export function makeEntrypointCases() {
4+
return [
5+
{
6+
name: 'Explain plan',
7+
input: {
8+
messages: [{ text: explainPlan.buildPrompt() }],
9+
},
10+
expected: {
11+
messages: [
12+
{
13+
text: explainPlan.buildExpected(),
14+
sources: explainPlan.buildExpectedSources(),
15+
},
16+
],
17+
},
18+
metadata: {},
19+
},
20+
];
21+
}

0 commit comments

Comments
 (0)