Skip to content

Commit 97810c6

Browse files
chore: accuracy tests for dropping indexes
1 parent d223098 commit 97810c6

File tree

2 files changed

+212
-61
lines changed

2 files changed

+212
-61
lines changed

tests/accuracy/dropIndex.test.ts

Lines changed: 116 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,134 @@
11
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
22
import { describeAccuracyTests } from "./sdk/describeAccuracyTests.js";
33
import { Matcher } from "./sdk/matcher.js";
4+
import { formatUntrustedData } from "../../src/tools/tool.js";
45

56
// We don't want to delete actual indexes
67
const mockedTools = {
78
"drop-index": ({ indexName, database, collection }: Record<string, unknown>): CallToolResult => {
89
return {
9-
content: [
10-
{
11-
text: `Successfully dropped the index with name "${String(indexName)}" from the provided namespace "${String(database)}.${String(collection)}".`,
12-
type: "text",
13-
},
14-
],
10+
content: formatUntrustedData(
11+
"Successfully dropped the index from the provided namespace.",
12+
JSON.stringify({
13+
indexName,
14+
namespace: `${database as string}.${collection as string}`,
15+
})
16+
),
1517
};
1618
},
1719
} as const;
1820

19-
describeAccuracyTests([
20-
{
21-
prompt: "Delete the index called year_1 from mflix.movies namespace",
22-
expectedToolCalls: [
23-
{
24-
toolName: "drop-index",
25-
parameters: {
26-
database: "mflix",
27-
collection: "movies",
28-
indexName: "year_1",
21+
describeAccuracyTests(
22+
[
23+
{
24+
prompt: "Delete the index called year_1 from mflix.movies namespace",
25+
expectedToolCalls: [
26+
{
27+
toolName: "drop-index",
28+
parameters: {
29+
database: "mflix",
30+
collection: "movies",
31+
indexName: "year_1",
32+
type: "classic",
33+
},
2934
},
30-
},
31-
],
32-
mockedTools,
33-
},
34-
{
35-
prompt: "First create a text index on field 'title' in 'mflix.movies' namespace and then drop all the indexes from 'mflix.movies' namespace",
36-
expectedToolCalls: [
37-
{
38-
toolName: "create-index",
39-
parameters: {
40-
database: "mflix",
41-
collection: "movies",
42-
name: Matcher.anyOf(Matcher.undefined, Matcher.string()),
43-
definition: [
44-
{
45-
keys: {
46-
title: "text",
35+
],
36+
mockedTools,
37+
},
38+
{
39+
prompt: "First create a text index on field 'title' in 'mflix.movies' namespace and then drop all the indexes from 'mflix.movies' namespace",
40+
expectedToolCalls: [
41+
{
42+
toolName: "create-index",
43+
parameters: {
44+
database: "mflix",
45+
collection: "movies",
46+
name: Matcher.anyOf(Matcher.undefined, Matcher.string()),
47+
definition: [
48+
{
49+
keys: {
50+
title: "text",
51+
},
52+
type: "classic",
4753
},
48-
type: "classic",
49-
},
50-
],
54+
],
55+
},
5156
},
52-
},
53-
{
54-
toolName: "collection-indexes",
55-
parameters: {
56-
database: "mflix",
57-
collection: "movies",
57+
{
58+
toolName: "collection-indexes",
59+
parameters: {
60+
database: "mflix",
61+
collection: "movies",
62+
},
5863
},
59-
},
60-
{
61-
toolName: "drop-index",
62-
parameters: {
63-
database: "mflix",
64-
collection: "movies",
65-
indexName: Matcher.string(),
64+
{
65+
toolName: "drop-index",
66+
parameters: {
67+
database: "mflix",
68+
collection: "movies",
69+
indexName: Matcher.string(),
70+
type: "classic",
71+
},
6672
},
67-
},
68-
{
69-
toolName: "drop-index",
70-
parameters: {
71-
database: "mflix",
72-
collection: "movies",
73-
indexName: Matcher.string(),
73+
{
74+
toolName: "drop-index",
75+
parameters: {
76+
database: "mflix",
77+
collection: "movies",
78+
indexName: Matcher.string(),
79+
type: "classic",
80+
},
7481
},
75-
},
76-
],
77-
mockedTools,
78-
},
79-
]);
82+
],
83+
mockedTools,
84+
},
85+
{
86+
prompt: "Create a vector search index on 'mflix.movies' namespace on the 'plotSummary' field. The index should use 1024 dimensions. Confirm that its created and then drop the index.",
87+
expectedToolCalls: [
88+
{
89+
toolName: "create-index",
90+
parameters: {
91+
database: "mflix",
92+
collection: "movies",
93+
name: Matcher.anyOf(Matcher.undefined, Matcher.string()),
94+
definition: [
95+
{
96+
type: "vectorSearch",
97+
fields: [
98+
{
99+
type: "vector",
100+
path: "plotSummary",
101+
numDimensions: 1024,
102+
},
103+
],
104+
},
105+
],
106+
},
107+
},
108+
{
109+
toolName: "collection-indexes",
110+
parameters: {
111+
database: "mflix",
112+
collection: "movies",
113+
},
114+
},
115+
{
116+
toolName: "drop-index",
117+
parameters: {
118+
database: "mflix",
119+
collection: "movies",
120+
indexName: Matcher.string(),
121+
type: "search",
122+
},
123+
},
124+
],
125+
mockedTools,
126+
},
127+
],
128+
{
129+
userConfig: {
130+
voyageApiKey: "voyage-api-key",
131+
},
132+
clusterConfig: { search: true },
133+
}
134+
);
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* Accuracy tests for when the vector search feature flag is disabled.
3+
*
4+
* TODO: Remove this file once we permanently enable the vector search feature.
5+
*/
6+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
7+
import { describeAccuracyTests } from "./sdk/describeAccuracyTests.js";
8+
import { Matcher } from "./sdk/matcher.js";
9+
import { formatUntrustedData } from "../../src/tools/tool.js";
10+
11+
// We don't want to delete actual indexes
12+
const mockedTools = {
13+
"drop-index": ({ indexName, database, collection }: Record<string, unknown>): CallToolResult => {
14+
return {
15+
content: formatUntrustedData(
16+
"Successfully dropped the index from the provided namespace.",
17+
JSON.stringify({
18+
indexName,
19+
namespace: `${database as string}.${collection as string}`,
20+
})
21+
),
22+
};
23+
},
24+
} as const;
25+
26+
describeAccuracyTests(
27+
[
28+
{
29+
prompt: "Delete the index called year_1 from mflix.movies namespace",
30+
expectedToolCalls: [
31+
{
32+
toolName: "drop-index",
33+
parameters: {
34+
database: "mflix",
35+
collection: "movies",
36+
indexName: "year_1",
37+
type: Matcher.anyOf(Matcher.undefined, Matcher.value("classic")),
38+
},
39+
},
40+
],
41+
mockedTools,
42+
},
43+
{
44+
prompt: "First create a text index on field 'title' in 'mflix.movies' namespace and then drop all the indexes from 'mflix.movies' namespace",
45+
expectedToolCalls: [
46+
{
47+
toolName: "create-index",
48+
parameters: {
49+
database: "mflix",
50+
collection: "movies",
51+
name: Matcher.anyOf(Matcher.undefined, Matcher.string()),
52+
definition: [
53+
{
54+
keys: {
55+
title: "text",
56+
},
57+
type: "classic",
58+
},
59+
],
60+
},
61+
},
62+
{
63+
toolName: "collection-indexes",
64+
parameters: {
65+
database: "mflix",
66+
collection: "movies",
67+
},
68+
},
69+
{
70+
toolName: "drop-index",
71+
parameters: {
72+
database: "mflix",
73+
collection: "movies",
74+
indexName: Matcher.string(),
75+
type: Matcher.anyOf(Matcher.undefined, Matcher.value("classic")),
76+
},
77+
},
78+
{
79+
toolName: "drop-index",
80+
parameters: {
81+
database: "mflix",
82+
collection: "movies",
83+
indexName: Matcher.string(),
84+
type: Matcher.anyOf(Matcher.undefined, Matcher.value("classic")),
85+
},
86+
},
87+
],
88+
mockedTools,
89+
},
90+
],
91+
{
92+
userConfig: {
93+
voyageApiKey: "",
94+
},
95+
}
96+
);

0 commit comments

Comments
 (0)