Skip to content

Commit 2909e8a

Browse files
committed
Replace the matcher framework
1 parent 3491a3b commit 2909e8a

16 files changed

+499
-421
lines changed

src/tools/mongodb/create/createIndex.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class CreateIndexTool extends MongoDBToolBase {
99
protected description = "Create an index for a collection";
1010
protected argsShape = {
1111
...DbOperationArgs,
12-
keys: z.record(z.string(), z.custom<IndexDirection>()).describe("The index definition"),
12+
keys: z.object({}).catchall(z.custom<IndexDirection>()).describe("The index definition"),
1313
name: z.string().optional().describe("The name of the index"),
1414
};
1515

src/tools/mongodb/create/insertMany.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class InsertManyTool extends MongoDBToolBase {
99
protected argsShape = {
1010
...DbOperationArgs,
1111
documents: z
12-
.array(z.record(z.string(), z.unknown()).describe("An individual MongoDB document"))
12+
.array(z.object({}).passthrough().describe("An individual MongoDB document"))
1313
.describe(
1414
"The array of documents to insert, matching the syntax of the document argument of db.collection.insertMany()"
1515
),

src/tools/mongodb/delete/deleteMany.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export class DeleteManyTool extends MongoDBToolBase {
1010
protected argsShape = {
1111
...DbOperationArgs,
1212
filter: z
13-
.record(z.string(), z.unknown())
13+
.object({})
14+
.passthrough()
1415
.optional()
1516
.describe(
1617
"The query filter, specifying the deletion criteria. Matches the syntax of the filter argument of db.collection.deleteMany()"

src/tools/mongodb/update/updateMany.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ export class UpdateManyTool extends MongoDBToolBase {
1010
protected argsShape = {
1111
...DbOperationArgs,
1212
filter: z
13-
.record(z.string(), z.unknown())
13+
.object({})
14+
.passthrough()
1415
.optional()
1516
.describe(
1617
"The selection criteria for the update, matching the syntax of the filter argument of db.collection.updateOne()"
1718
),
1819
update: z
19-
.record(z.string(), z.unknown())
20+
.object({})
21+
.passthrough()
2022
.describe("An update document describing the modifications to apply using update operator expressions"),
2123
upsert: z
2224
.boolean()

tests/accuracy/aggregate.test.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
import { describeAccuracyTests } from "./sdk/describeAccuracyTests.js";
2-
import { ParameterScorers, withParameterScorer } from "./sdk/parameterScorer.js";
2+
import { Matcher } from "./sdk/matcher.js";
33

44
describeAccuracyTests([
55
{
66
prompt: "Group all the movies in 'mflix.movies' namespace by 'release_year' and give me a count of them",
77
expectedToolCalls: [
88
{
99
toolName: "aggregate",
10-
parameters: withParameterScorer(
11-
{
12-
database: "mflix",
13-
collection: "movies",
14-
pipeline: [{ $group: { _id: "$release_year", count: { $sum: 1 } } }],
15-
},
16-
// There should not be a $match at all hence the custom matcher
17-
ParameterScorers.noAdditionsAllowedForPaths(["pipeline.0.$match"])
18-
),
10+
parameters: {
11+
database: "mflix",
12+
collection: "movies",
13+
pipeline: [
14+
{ $group: { _id: "$release_year", count: { $sum: 1 } } },
15+
// For the sake of accuracy, we allow any sort order
16+
Matcher.composite(
17+
Matcher.undefined,
18+
Matcher.unknown({
19+
$sort: Matcher.anyValue,
20+
})
21+
),
22+
],
23+
},
1924
},
2025
],
2126
},

tests/accuracy/count.test.ts

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import { describeAccuracyTests } from "./sdk/describeAccuracyTests.js";
2-
import { ParameterScorers, withParameterScorer } from "./sdk/parameterScorer.js";
2+
import { Matcher } from "./sdk/matcher.js";
33

44
describeAccuracyTests([
55
{
66
prompt: "Count number of documents in 'mflix.movies' namespace.",
77
expectedToolCalls: [
88
{
99
toolName: "count",
10-
parameters: withParameterScorer(
11-
{
12-
database: "mflix",
13-
collection: "movies",
14-
},
15-
ParameterScorers.emptyAdditionsAllowedForPaths(["query"])
16-
),
10+
parameters: {
11+
database: "mflix",
12+
collection: "movies",
13+
query: Matcher.emptyObjectOrUndefined,
14+
},
1715
},
1816
],
1917
},
@@ -22,13 +20,11 @@ describeAccuracyTests([
2220
expectedToolCalls: [
2321
{
2422
toolName: "count",
25-
parameters: withParameterScorer(
26-
{
27-
database: "comics",
28-
collection: "characters",
29-
},
30-
ParameterScorers.emptyAdditionsAllowedForPaths(["query"])
31-
),
23+
parameters: {
24+
database: "comics",
25+
collection: "characters",
26+
query: Matcher.emptyObjectOrUndefined,
27+
},
3228
},
3329
],
3430
},
@@ -37,14 +33,11 @@ describeAccuracyTests([
3733
expectedToolCalls: [
3834
{
3935
toolName: "count",
40-
parameters: withParameterScorer(
41-
{
42-
database: "mflix",
43-
collection: "movies",
44-
query: { runtime: { $lt: 100 } },
45-
},
46-
ParameterScorers.noAdditionsAllowedForPaths(["query"])
47-
),
36+
parameters: {
37+
database: "mflix",
38+
collection: "movies",
39+
query: { runtime: { $lt: 100 } },
40+
},
4841
},
4942
],
5043
},

tests/accuracy/createIndex.test.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
import { describeAccuracyTests } from "./sdk/describeAccuracyTests.js";
2-
import { ParameterScorers, withParameterScorer } from "./sdk/parameterScorer.js";
2+
import { Matcher } from "./sdk/matcher.js";
33

44
describeAccuracyTests([
55
{
66
prompt: "Create an index that covers the following query on 'mflix.movies' namespace - { \"release_year\": 1992 }",
77
expectedToolCalls: [
88
{
99
toolName: "create-index",
10-
parameters: withParameterScorer(
11-
{
12-
database: "mflix",
13-
collection: "movies",
14-
keys: {
15-
release_year: 1,
16-
},
10+
parameters: {
11+
database: "mflix",
12+
collection: "movies",
13+
name: Matcher.composite(Matcher.undefined, Matcher.string()),
14+
keys: {
15+
release_year: 1,
1716
},
18-
ParameterScorers.noAdditionsAllowedForPaths(["keys"])
19-
),
17+
},
2018
},
2119
],
2220
},
@@ -25,16 +23,14 @@ describeAccuracyTests([
2523
expectedToolCalls: [
2624
{
2725
toolName: "create-index",
28-
parameters: withParameterScorer(
29-
{
30-
database: "mflix",
31-
collection: "movies",
32-
keys: {
33-
title: "text",
34-
},
26+
parameters: {
27+
database: "mflix",
28+
collection: "movies",
29+
name: Matcher.composite(Matcher.undefined, Matcher.string()),
30+
keys: {
31+
title: "text",
3532
},
36-
ParameterScorers.noAdditionsAllowedForPaths(["keys"])
37-
),
33+
},
3834
},
3935
],
4036
},

tests/accuracy/deleteMany.test.ts

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import { describeAccuracyTests } from "./sdk/describeAccuracyTests.js";
2-
import { ParameterScorers, withParameterScorer } from "./sdk/parameterScorer.js";
2+
import { Matcher } from "./sdk/matcher.js";
33

44
describeAccuracyTests([
55
{
66
prompt: "Delete all the documents from 'mflix.movies' namespace",
77
expectedToolCalls: [
88
{
99
toolName: "delete-many",
10-
parameters: withParameterScorer(
11-
{
12-
database: "mflix",
13-
collection: "movies",
14-
},
15-
ParameterScorers.emptyAdditionsAllowedForPaths(["filter"])
16-
),
10+
parameters: {
11+
database: "mflix",
12+
collection: "movies",
13+
filter: Matcher.emptyObjectOrUndefined,
14+
},
1715
},
1816
],
1917
},
@@ -22,13 +20,11 @@ describeAccuracyTests([
2220
expectedToolCalls: [
2321
{
2422
toolName: "delete-many",
25-
parameters: withParameterScorer(
26-
{
27-
database: "mflix",
28-
collection: "movies",
29-
},
30-
ParameterScorers.emptyAdditionsAllowedForPaths(["filter"])
31-
),
23+
parameters: {
24+
database: "mflix",
25+
collection: "movies",
26+
filter: Matcher.emptyObjectOrUndefined,
27+
},
3228
},
3329
],
3430
},
@@ -37,14 +33,11 @@ describeAccuracyTests([
3733
expectedToolCalls: [
3834
{
3935
toolName: "delete-many",
40-
parameters: withParameterScorer(
41-
{
42-
database: "mflix",
43-
collection: "movies",
44-
filter: { runtime: { $lt: 100 } },
45-
},
46-
ParameterScorers.noAdditionsAllowedForPaths(["filter"])
47-
),
36+
parameters: {
37+
database: "mflix",
38+
collection: "movies",
39+
filter: { runtime: { $lt: 100 } },
40+
},
4841
},
4942
],
5043
},

tests/accuracy/explain.test.ts

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { describeAccuracyTests } from "./sdk/describeAccuracyTests.js";
2-
import { ParameterScorers, withParameterScorer } from "./sdk/parameterScorer.js";
32

43
/**
54
* None of these tests score a parameter match on any of the models, likely
@@ -12,22 +11,18 @@ describeAccuracyTests([
1211
expectedToolCalls: [
1312
{
1413
toolName: "explain",
15-
parameters: withParameterScorer(
16-
{
17-
database: "mflix",
18-
collection: "movies",
19-
method: [
20-
{
21-
name: "find",
22-
arguments: {
23-
filter: { release_year: 2020 },
24-
},
14+
parameters: {
15+
database: "mflix",
16+
collection: "movies",
17+
method: [
18+
{
19+
name: "find",
20+
arguments: {
21+
filter: { release_year: 2020 },
2522
},
26-
],
27-
},
28-
// Any addition to method itself will essentially change the explain output
29-
ParameterScorers.noAdditionsAllowedForPaths(["method"])
30-
),
23+
},
24+
],
25+
},
3126
},
3227
],
3328
},
@@ -36,25 +31,22 @@ describeAccuracyTests([
3631
expectedToolCalls: [
3732
{
3833
toolName: "explain",
39-
parameters: withParameterScorer(
40-
{
41-
database: "mflix",
42-
collection: "movies",
43-
method: [
44-
{
45-
name: "aggregate",
46-
arguments: {
47-
pipeline: [
48-
{
49-
$match: { release_year: 2020 },
50-
},
51-
],
52-
},
34+
parameters: {
35+
database: "mflix",
36+
collection: "movies",
37+
method: [
38+
{
39+
name: "aggregate",
40+
arguments: {
41+
pipeline: [
42+
{
43+
$match: { release_year: 2020 },
44+
},
45+
],
5346
},
54-
],
55-
},
56-
ParameterScorers.noAdditionsAllowedForPaths(["method"])
57-
),
47+
},
48+
],
49+
},
5850
},
5951
],
6052
},
@@ -63,21 +55,18 @@ describeAccuracyTests([
6355
expectedToolCalls: [
6456
{
6557
toolName: "explain",
66-
parameters: withParameterScorer(
67-
{
68-
database: "mflix",
69-
collection: "movies",
70-
method: [
71-
{
72-
name: "count",
73-
arguments: {
74-
query: { release_year: 2020 },
75-
},
58+
parameters: {
59+
database: "mflix",
60+
collection: "movies",
61+
method: [
62+
{
63+
name: "count",
64+
arguments: {
65+
query: { release_year: 2020 },
7666
},
77-
],
78-
},
79-
ParameterScorers.noAdditionsAllowedForPaths(["method"])
80-
),
67+
},
68+
],
69+
},
8170
},
8271
],
8372
},

0 commit comments

Comments
 (0)