-
Notifications
You must be signed in to change notification settings - Fork 163
feat: add ability to specify enabled preview features #686
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,9 @@ import type { Similarity } from "./search/vectorSearchEmbeddingsManager.js"; | |
| import { z } from "zod"; | ||
| const levenshtein = levenshteinModule.default; | ||
|
|
||
| const previewFeatures = z.enum(["vectorSearch"]); | ||
| export type PreviewFeatures = z.infer<typeof previewFeatures>; | ||
|
|
||
| // From: https://github.com/mongodb-js/mongosh/blob/main/packages/cli-repl/src/arg-parser.ts | ||
| export const OPTIONS = { | ||
| number: ["maxDocumentsPerQuery", "maxBytesPerQuery"], | ||
|
|
@@ -81,7 +84,7 @@ export const OPTIONS = { | |
| "tlsFIPSMode", | ||
| "version", | ||
| ], | ||
| array: ["disabledTools", "loggers", "confirmationRequiredTools"], | ||
| array: ["disabledTools", "loggers", "confirmationRequiredTools", "previewFeatures"], | ||
| alias: { | ||
| h: "help", | ||
| p: "password", | ||
|
|
@@ -119,7 +122,7 @@ export const ALL_CONFIG_KEYS = new Set( | |
| .concat(Object.keys(OPTIONS.alias)) | ||
| ); | ||
|
|
||
| export function validateConfigKey(key: string): { valid: boolean; suggestion?: string } { | ||
| function validateConfigKey(key: string): { valid: boolean; suggestion?: string } { | ||
| if (ALL_CONFIG_KEYS.has(key)) { | ||
| return { valid: true }; | ||
| } | ||
|
|
@@ -282,6 +285,7 @@ export const UserConfigSchema = z.object({ | |
| .optional() | ||
| .default("euclidean") | ||
| .describe("Default similarity function for vector search: 'euclidean', 'cosine', or 'dotProduct'."), | ||
| previewFeatures: z.array(previewFeatures).default([]).describe("An array of preview features that are enabled."), | ||
| }); | ||
|
|
||
| export type UserConfig = z.infer<typeof UserConfigSchema> & CliOptions; | ||
|
|
@@ -318,6 +322,7 @@ export const defaultUserConfig: UserConfig = { | |
| disableEmbeddingsValidation: false, | ||
| vectorSearchDimensions: 1024, | ||
| vectorSearchSimilarityFunction: "euclidean", | ||
| previewFeatures: [], | ||
| }; | ||
|
|
||
| export const config = setupUserConfig({ | ||
|
|
@@ -556,7 +561,7 @@ export function setupUserConfig({ | |
| env: Record<string, unknown>; | ||
| defaults: Partial<UserConfig>; | ||
| }): UserConfig { | ||
| const userConfig: UserConfig = { | ||
| const userConfig = { | ||
|
||
| ...defaults, | ||
| ...parseEnvConfig(env), | ||
| ...parseCliConfig(cli), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,15 +2,15 @@ import z from "zod"; | |
| import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js"; | ||
| import type { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver"; | ||
| import { DbOperationArgs, MongoDBToolBase } from "../mongodbTool.js"; | ||
| import { type ToolArgs, type OperationType, formatUntrustedData, FeatureFlags } from "../../tool.js"; | ||
| import { type ToolArgs, type OperationType, formatUntrustedData } from "../../tool.js"; | ||
|
|
||
| export class DropIndexTool extends MongoDBToolBase { | ||
| public name = "drop-index"; | ||
| protected description = "Drop an index for the provided database and collection."; | ||
| protected argsShape = { | ||
| ...DbOperationArgs, | ||
| indexName: z.string().nonempty().describe("The name of the index to be dropped."), | ||
| type: this.isFeatureFlagEnabled(FeatureFlags.VectorSearch) | ||
| type: this.isFeatureEnabled("vectorSearch") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the ultimate nit: why not keep another nit: btw I usually prefer to keeping a tiny file with this logic as it might grow and we could also add some unit tests just while we're here to keep it safe from future changes.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "vectorSearch" is a const in a union type. So when calling Not sure I fully understood the second half of your suggestion - what part of the logic would you suggest we move to a separate file? For context, the enum values are currently defined in
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To add to this: enums in JavaScript are pretty terrible and it's best to avoid them. |
||
| ? z | ||
| .enum(["classic", "search"]) | ||
| .describe( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.