Skip to content

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

Merged
merged 7 commits into from
May 14, 2025

Conversation

edgarw19
Copy link
Collaborator

@edgarw19 edgarw19 commented May 13, 2025

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.

@edgarw19 edgarw19 requested a review from a team as a code owner May 13, 2025 20:59
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, {
Copy link
Collaborator Author

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"),
Copy link
Collaborator Author

@edgarw19 edgarw19 May 13, 2025

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."
Copy link
Collaborator

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/

Copy link
Collaborator

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
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

@fmenezes fmenezes requested a review from Copilot May 14, 2025 08:55
Copy link
Contributor

@Copilot Copilot AI left a 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}"`,
Copy link
Preview

Copilot AI May 14, 2025

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.

@edgarw19 edgarw19 changed the title Create/Update Search Index feat: create and update Search Index May 14, 2025
@edgarw19 edgarw19 merged commit b6ff2cc into search-skunkworks-2025 May 14, 2025
9 checks passed
@edgarw19 edgarw19 deleted the edgar/create-update-functionality branch May 14, 2025 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants