Skip to content

Commit 9326ed4

Browse files
committed
chore: simplify the api and test
1 parent 9e3ecf1 commit 9326ed4

File tree

2 files changed

+5
-306
lines changed

2 files changed

+5
-306
lines changed

src/tools/mongodb/create/insertMany.ts

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,9 @@ export class InsertManyTool extends MongoDBToolBase {
1919
"The array of documents to insert, matching the syntax of the document argument of db.collection.insertMany(). For fields that have vector search indexes, you can provide raw text strings that will be automatically converted to embeddings if embeddingParameters is provided."
2020
),
2121
embeddingParameters: zSupportedEmbeddingParameters
22-
.extend({
23-
input: z
24-
.array(z.record(z.string(), z.string()).optional())
25-
.describe(
26-
"An array of objects (one per document) that maps field paths to plain-text content for generating embeddings. Each object should have keys matching the vector search index field paths (in dot notation), with string values containing the text to embed. If provided, these texts will be used to generate embeddings instead of looking for raw text in the document fields themselves. Example: [{'content': 'Input text to create embeddings from for first doc'}, {'content': 'Input text to create embeddings from for second doc'}]"
27-
),
28-
})
2922
.optional()
3023
.describe(
31-
"The embedding model and its parameters to use to generate embeddings for fields that have vector search indexes. Required when fields associated with vector search indexes contain raw text strings. Note to LLM: If unsure, ask the user before providing one."
24+
"The embedding model and its parameters to use to generate embeddings for fields that have vector search indexes. When a field has a vector search index and contains a plain text string in the document, embeddings will be automatically generated from that string value. Note to LLM: If unsure which embedding model to use, ask the user before providing one."
3225
),
3326
};
3427
public operationType: OperationType = "create";
@@ -37,7 +30,6 @@ export class InsertManyTool extends MongoDBToolBase {
3730
database,
3831
collection,
3932
documents,
40-
embeddingsInput,
4133
embeddingParameters,
4234
}: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
4335
const provider = await this.ensureConnected();
@@ -54,7 +46,6 @@ export class InsertManyTool extends MongoDBToolBase {
5446
collection,
5547
documents,
5648
vectorIndexes,
57-
embeddingsInput,
5849
embeddingParameters,
5950
});
6051

@@ -98,14 +89,12 @@ export class InsertManyTool extends MongoDBToolBase {
9889
collection,
9990
documents,
10091
vectorIndexes,
101-
embeddingsInput,
10292
embeddingParameters,
10393
}: {
10494
database: string;
10595
collection: string;
10696
documents: Document[];
10797
vectorIndexes: VectorFieldIndexDefinition[];
108-
embeddingsInput?: Array<Record<string, string> | undefined>;
10998
embeddingParameters?: z.infer<typeof zSupportedEmbeddingParameters>;
11099
}): Promise<Document[]> {
111100
// If no vector indexes, return documents as-is
@@ -120,13 +109,11 @@ export class InsertManyTool extends MongoDBToolBase {
120109
if (!document) {
121110
continue;
122111
}
123-
const documentEmbeddingsInput = embeddingsInput?.[i];
124112
const processedDoc = await this.processDocumentForEmbeddings(
125113
database,
126114
collection,
127115
document,
128116
vectorIndexes,
129-
documentEmbeddingsInput,
130117
embeddingParameters
131118
);
132119
processedDocuments.push(processedDoc);
@@ -140,7 +127,6 @@ export class InsertManyTool extends MongoDBToolBase {
140127
collection: string,
141128
document: Document,
142129
vectorIndexes: VectorFieldIndexDefinition[],
143-
embeddingsInput?: Record<string, string>,
144130
embeddingParameters?: z.infer<typeof zSupportedEmbeddingParameters>
145131
): Promise<Document> {
146132
// Find all fields in the document that match vector search indexed fields and need embeddings
@@ -151,20 +137,7 @@ export class InsertManyTool extends MongoDBToolBase {
151137
}> = [];
152138

153139
for (const indexDef of vectorIndexes) {
154-
// First, check if embeddingsInput provides text for this field
155-
if (embeddingsInput && indexDef.path in embeddingsInput) {
156-
const inputText = embeddingsInput[indexDef.path];
157-
if (typeof inputText === "string" && inputText.length > 0) {
158-
fieldsNeedingEmbeddings.push({
159-
path: indexDef.path,
160-
rawValue: inputText,
161-
indexDef,
162-
});
163-
continue;
164-
}
165-
}
166-
167-
// Otherwise, check if the field exists in the document and is a string (raw text)
140+
// Check if the field exists in the document and is a string (raw text)
168141
const fieldValue = this.getFieldValue(document, indexDef.path);
169142
if (typeof fieldValue === "string") {
170143
fieldsNeedingEmbeddings.push({
@@ -185,7 +158,7 @@ export class InsertManyTool extends MongoDBToolBase {
185158
const fieldPaths = fieldsNeedingEmbeddings.map((f) => f.path).join(", ");
186159
throw new MongoDBError(
187160
ErrorCodes.AtlasVectorSearchInvalidQuery,
188-
`Fields [${fieldPaths}] have vector search indexes but ${embeddingsInput ? "embeddingsInput contains text for these fields" : "contain raw text strings"}. The embeddingParameters parameter is required to generate embeddings for these fields.`
161+
`Fields [${fieldPaths}] have vector search indexes and contain raw text strings. The embeddingParameters parameter is required to generate embeddings for these fields.`
189162
);
190163
}
191164

tests/accuracy/insertMany.embeddings.test.ts

Lines changed: 2 additions & 276 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Matcher } from "./sdk/matcher.js";
88
describeAccuracyTests(
99
[
1010
{
11-
prompt: "Insert a document into 'mflix.movies' collection with title 'The Matrix' and a plotSummary field with the text 'A computer hacker learns about the true nature of his reality'. Generate embeddings automatically using the voyage-3 model.",
11+
prompt: "Insert a document into 'mflix.movies' collection with title 'The Matrix' and a plotSummary field with the text 'A computer hacker learns about the true nature of his reality'. Use the plot summary to generate the 'embeddings' field using the voyage-3 model.",
1212
expectedToolCalls: [
1313
{
1414
toolName: "insert-many",
@@ -19,283 +19,9 @@ describeAccuracyTests(
1919
{
2020
title: "The Matrix",
2121
plotSummary: "A computer hacker learns about the true nature of his reality",
22-
},
23-
],
24-
embeddingParameters: {
25-
model: "voyage-3",
26-
},
27-
},
28-
},
29-
],
30-
},
31-
{
32-
prompt: "Add a movie to 'mflix.movies' with title 'Inception', year 2010, and plotSummary 'A thief who steals corporate secrets through dream-sharing technology'. Use voyage-3-lite model for automatic embeddings.",
33-
expectedToolCalls: [
34-
{
35-
toolName: "insert-many",
36-
parameters: {
37-
database: "mflix",
38-
collection: "movies",
39-
documents: [
40-
{
41-
title: "Inception",
42-
year: 2010,
43-
plotSummary: "A thief who steals corporate secrets through dream-sharing technology",
44-
},
45-
],
46-
embeddingParameters: {
47-
model: Matcher.string(),
48-
},
49-
},
50-
},
51-
],
52-
},
53-
{
54-
prompt: "Insert multiple movies into 'mflix.movies' with automatic embeddings using voyage-3 model. Add: 1) 'Avatar' with plot 'A marine on an alien planet', 2) 'Titanic' with plot 'A romance on a doomed ship', 3) 'Jurassic Park' with plot 'Dinosaurs brought back to life'.",
55-
expectedToolCalls: [
56-
{
57-
toolName: "insert-many",
58-
parameters: {
59-
database: "mflix",
60-
collection: "movies",
61-
documents: [
62-
{
63-
title: "Avatar",
64-
plotSummary: Matcher.string(),
65-
},
66-
{
67-
title: "Titanic",
68-
plotSummary: Matcher.string(),
69-
},
70-
{
71-
title: "Jurassic Park",
72-
plotSummary: Matcher.string(),
73-
},
74-
],
75-
embeddingParameters: {
76-
model: "voyage-3",
77-
},
78-
},
79-
},
80-
],
81-
},
82-
{
83-
prompt: "Insert a document into 'mflix.movies' with title 'Interstellar' and use embeddingParameters input to provide custom text for plotSummary field: 'Space exploration and time dilation'. Use voyage-3 model.",
84-
expectedToolCalls: [
85-
{
86-
toolName: "insert-many",
87-
parameters: {
88-
database: "mflix",
89-
collection: "movies",
90-
documents: [
91-
{
92-
title: "Interstellar",
93-
},
94-
],
95-
embeddingParameters: {
96-
model: "voyage-3",
97-
input: [
98-
{
99-
plotSummary: "Space exploration and time dilation",
100-
},
101-
],
102-
},
103-
},
104-
},
105-
],
106-
},
107-
{
108-
prompt: "Add a movie 'The Dark Knight' to 'mflix.movies' with multiple embedding fields. Use raw text 'Batman fights the Joker' for plotSummary and 'Action, Crime, Drama' for genre. Generate embeddings with voyage-3 model.",
109-
expectedToolCalls: [
110-
{
111-
toolName: "insert-many",
112-
parameters: {
113-
database: "mflix",
114-
collection: "movies",
115-
documents: [
116-
{
117-
title: "The Dark Knight",
118-
plotSummary: Matcher.string(),
119-
genre: Matcher.string(),
120-
},
121-
],
122-
embeddingParameters: {
123-
model: "voyage-3",
124-
},
125-
},
126-
},
127-
],
128-
},
129-
{
130-
prompt: "Insert a document into 'mflix.movies' with title 'Pulp Fiction' and nested embedding field 'embeddings.plot' containing text 'Multiple interconnected crime stories'. Use voyage-3 for automatic embeddings.",
131-
expectedToolCalls: [
132-
{
133-
toolName: "insert-many",
134-
parameters: {
135-
database: "mflix",
136-
collection: "movies",
137-
documents: [
138-
{
139-
title: "Pulp Fiction",
14022
embeddings: {
141-
plot: Matcher.string(),
142-
},
143-
},
144-
],
145-
embeddingParameters: {
146-
model: "voyage-3",
147-
},
148-
},
149-
},
150-
],
151-
},
152-
{
153-
prompt: "Insert two documents into 'mflix.movies' using embeddingParameters input for custom text. Add 'Forrest Gump' with input text 'Life is like a box of chocolates' and 'The Godfather' with input text 'An offer you cannot refuse'. Use voyage-3 model.",
154-
expectedToolCalls: [
155-
{
156-
toolName: "insert-many",
157-
parameters: {
158-
database: "mflix",
159-
collection: "movies",
160-
documents: [
161-
{
162-
title: "Forrest Gump",
163-
},
164-
{
165-
title: "The Godfather",
166-
},
167-
],
168-
embeddingParameters: {
169-
model: "voyage-3",
170-
input: [
171-
{
172-
plotSummary: Matcher.string(),
23+
plotSummary: "A computer hacker learns about the true nature of his reality",
17324
},
174-
{
175-
plotSummary: Matcher.string(),
176-
},
177-
],
178-
},
179-
},
180-
},
181-
],
182-
},
183-
{
184-
prompt: "Add a movie 'Star Wars' to 'mflix.movies' with mixed approach: provide raw text 'Space opera saga' in plotSummary field and use embeddingParameters input to provide 'Epic space battles' for genre field. Use voyage-3 model.",
185-
expectedToolCalls: [
186-
{
187-
toolName: "insert-many",
188-
parameters: {
189-
database: "mflix",
190-
collection: "movies",
191-
documents: [
192-
{
193-
title: "Star Wars",
194-
plotSummary: Matcher.string(),
195-
},
196-
],
197-
embeddingParameters: {
198-
model: "voyage-3",
199-
input: [
200-
{
201-
genre: Matcher.string(),
202-
},
203-
],
204-
},
205-
},
206-
},
207-
],
208-
},
209-
{
210-
prompt: "Insert a document into 'mflix.movies' with title 'Blade Runner' and specify voyage-3-lite model with document inputType for automatic embedding generation. Use text 'Dystopian future with replicants' for plotSummary.",
211-
expectedToolCalls: [
212-
{
213-
toolName: "insert-many",
214-
parameters: {
215-
database: "mflix",
216-
collection: "movies",
217-
documents: [
218-
{
219-
title: "Blade Runner",
220-
plotSummary: Matcher.string(),
221-
},
222-
],
223-
embeddingParameters: {
224-
model: Matcher.string(),
225-
inputType: Matcher.anyOf(Matcher.string(), Matcher.undefined),
226-
},
227-
},
228-
},
229-
],
230-
},
231-
{
232-
prompt: "Add multiple movies to 'mflix.movies' with different text lengths for automatic embeddings. Include 'Casablanca' with short text 'Love in wartime', 'Gone with the Wind' with medium text 'Epic tale of the American Civil War and its aftermath', and 'Citizen Kane' with long detailed plot description. Use voyage-3 model.",
233-
expectedToolCalls: [
234-
{
235-
toolName: "insert-many",
236-
parameters: {
237-
database: "mflix",
238-
collection: "movies",
239-
documents: [
240-
{
241-
title: "Casablanca",
242-
plotSummary: Matcher.string(),
243-
},
244-
{
245-
title: "Gone with the Wind",
246-
plotSummary: Matcher.string(),
247-
},
248-
{
249-
title: "Citizen Kane",
250-
plotSummary: Matcher.string(),
251-
},
252-
],
253-
embeddingParameters: {
254-
model: "voyage-3",
255-
},
256-
},
257-
},
258-
],
259-
},
260-
{
261-
prompt: "Insert a document into 'mflix.movies' with title 'The Lord of the Rings' and use embeddingParameters input array to provide different texts for multiple embedding fields: plotSummary='Fantasy epic quest', genre='Fantasy Adventure', themes='Good vs Evil'.",
262-
expectedToolCalls: [
263-
{
264-
toolName: "insert-many",
265-
parameters: {
266-
database: "mflix",
267-
collection: "movies",
268-
documents: [
269-
{
270-
title: "The Lord of the Rings",
271-
},
272-
],
273-
embeddingParameters: {
274-
model: Matcher.string(),
275-
input: [
276-
{
277-
plotSummary: Matcher.string(),
278-
genre: Matcher.string(),
279-
themes: Matcher.string(),
280-
},
281-
],
282-
},
283-
},
284-
},
285-
],
286-
},
287-
{
288-
prompt: "Add a movie 'Dune' to 'mflix.movies' with automatic embeddings. Provide raw text in the document for plotSummary field: 'Desert planet with spice mining'. Use voyage-3 model and ensure the text gets converted to embeddings automatically.",
289-
expectedToolCalls: [
290-
{
291-
toolName: "insert-many",
292-
parameters: {
293-
database: "mflix",
294-
collection: "movies",
295-
documents: [
296-
{
297-
title: "Dune",
298-
plotSummary: Matcher.string(),
29925
},
30026
],
30127
embeddingParameters: {

0 commit comments

Comments
 (0)