-
Notifications
You must be signed in to change notification settings - Fork 43
feat: create and update Search Index #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: create and update Search Index #244
Conversation
const provider = await this.ensureConnected(); | ||
// @ts-expect-error: Interface expects a SearchIndexDefinition. However, | ||
// passing analyzer/mappings at the root for the definition is necessary for the call to succeed. | ||
await provider.updateSearchIndex(database, collection, name, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the index does not exist, MCP inspector shows a descriptive error message
"Error running update-search-index: Search index sample_mflix.comments.test3 cannot be found"
@@ -10,6 +10,61 @@ export const DbOperationArgs = { | |||
collection: z.string().describe("Collection name"), | |||
}; | |||
|
|||
export const SearchIndexArgs = { | |||
name: z.string().describe("The name of the index"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This currently includes a few common arguments as a starting point.
It excludes custom analyzers/synonyms/storedsource since but we can add those if needed
.optional() | ||
.default("lucene.standard") | ||
.describe( | ||
"The analyzer to use for the index. Can be one of the built-in lucene analyzers (`lucene.standard`, `lucene.simple`, `lucene.whitespace`, `lucene.keyword`), a language-specific analyzer, such as `lucene.cjk` or `lucene.czech`, or a custom analyzer defined in the Atlas UI." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to link the docs page instead of saying defined in the Atlas UI
.
https://www.mongodb.com/docs/atlas/atlas-search/analyzers/language/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mihirmpatil consider that those are used to infer user generic queries. Best to make relevant context clear for machines and users.
.describe( | ||
"The analyzer to use for the index. Can be one of the built-in lucene analyzers (`lucene.standard`, `lucene.simple`, `lucene.whitespace`, `lucene.keyword`), a language-specific analyzer, such as `lucene.cjk` or `lucene.czech`, or a custom analyzer defined in the Atlas UI." | ||
), | ||
mappings: z |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The vector search index definition is different compared to this. See https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-type/
I think we'll be better off with a new type for vector search index definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this PR is specific to search indexes. I've opened a vector index PR here #252
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces two new tools to manage Atlas Search indexes: one for creating and another for updating search indexes. Key changes include the addition of CreateSearchIndexTool and UpdateSearchIndexTool files, the export of new SearchIndexArgs for defining index parameters, and updating the tools registry to include the new index management tools.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/tools/mongodb/update/updateSearchIndex.ts | Adds tool for updating a search index with adjustments for type expectations |
src/tools/mongodb/create/createSearchIndex.ts | Implements creation of a search index using a new tool class |
src/tools/mongodb/mongodbTool.ts | Introduces SearchIndexArgs for index configuration |
src/tools/mongodb/tools.ts | Updates tool registry to include the new search index tools |
Comments suppressed due to low confidence (1)
src/tools/mongodb/update/updateSearchIndex.ts:25
- Consider refining the type definitions for updateSearchIndex so that passing analyzer and mappings at the root is properly supported without needing to suppress TypeScript errors, thereby improving type safety.
// @ts-expect-error: Interface expects a SearchIndexDefinition. However, passing analyzer/mappings at the root for the definition is necessary for the call to succeed.
return { | ||
content: [ | ||
{ | ||
text: `Created the search index "${indexes[0]}" on collection "${collection}" in database "${database}"`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before using indexes[0] in the success message, add a runtime check to ensure that the indexes array is not empty. This change will help prevent potential runtime errors if index creation unexpectedly fails.
Copilot uses AI. Check for mistakes.
…ar/create-update-functionality
This is specifically for search indexes. The create vector index definition seems sufficiently different that I think it's worth separating.
VSCode copilot at least from my testing does better at distinguishing the two and understanding the fields to set when they are separate.
Tests will be added in a separate PR.