From 19c55cf302a46180891a90020f97bf018a597490 Mon Sep 17 00:00:00 2001 From: Ben Perlmutter <90647379+mongodben@users.noreply.github.com> Date: Fri, 4 Oct 2024 13:24:21 -0400 Subject: [PATCH] (EAI-505): Add MongoDB metadata + improve TS structuring (#500) * add metadata + make more structured * remove deprecated products * Update packages/chatbot-server-mongodb-public/src/mongoDbMetadata/products.ts --- .../src/mongoDbMetadata.ts | 248 -------------- .../src/mongoDbMetadata/index.ts | 4 + .../src/mongoDbMetadata/products.ts | 320 ++++++++++++++++++ .../mongoDbMetadata/programmingLanguages.ts | 86 +++++ .../src/mongoDbMetadata/tags.ts | 17 + .../src/mongoDbMetadata/topics.ts | 31 ++ ...ractMongoDbMetadataFromUserMessage.eval.ts | 20 +- .../extractMongoDbMetadataFromUserMessage.ts | 21 +- 8 files changed, 477 insertions(+), 270 deletions(-) delete mode 100644 packages/chatbot-server-mongodb-public/src/mongoDbMetadata.ts create mode 100644 packages/chatbot-server-mongodb-public/src/mongoDbMetadata/index.ts create mode 100644 packages/chatbot-server-mongodb-public/src/mongoDbMetadata/products.ts create mode 100644 packages/chatbot-server-mongodb-public/src/mongoDbMetadata/programmingLanguages.ts create mode 100644 packages/chatbot-server-mongodb-public/src/mongoDbMetadata/tags.ts create mode 100644 packages/chatbot-server-mongodb-public/src/mongoDbMetadata/topics.ts diff --git a/packages/chatbot-server-mongodb-public/src/mongoDbMetadata.ts b/packages/chatbot-server-mongodb-public/src/mongoDbMetadata.ts deleted file mode 100644 index 0f9efb95..00000000 --- a/packages/chatbot-server-mongodb-public/src/mongoDbMetadata.ts +++ /dev/null @@ -1,248 +0,0 @@ -import { z } from "zod"; -import { strict as assert } from "assert"; - -export const MongoDbProductSchema = z.object({ - id: z.string().describe("Unique identifier for the product"), - name: z.string().describe("Human-friendly name of the product"), - description: z - .string() - .optional() - .describe("Brief description of the product"), - versions: z - .array(z.string()) - .optional() - .describe("List of versions of the product"), - parentProductId: z.string().optional().describe("`id` of the parent product"), -}); -export type MongoDbProduct = z.infer; - -export const mongoDbProducts = [ - { - id: "server", - name: "MongoDB", - description: "Core MongoDB server", - }, - { - id: "aggregation", - name: "Aggregation Framework", - description: "Aggregation Framework", - parentProductId: "server", - }, - { - id: "atlas", - name: "MongoDB Atlas", - description: "MongoDB Atlas", - }, - { - id: "atlas_charts", - name: "Atlas Charts", - description: "Atlas Charts", - parentProductId: "atlas", - }, - { - id: "atlas_search", - name: "Atlas Search", - description: "Atlas Search", - parentProductId: "atlas", - }, - { - id: "atlas_vector_search", - name: "Atlas Vector Search", - description: "Atlas Vector Search", - parentProductId: "atlas", - }, - { - id: "atlas_cli", - name: "Atlas CLI", - description: "CLI to interact with MongoDB Atlas", - parentProductId: "atlas", - }, - { - id: "driver", - name: "Driver", - description: "MongoDB Drivers", - parentProductId: "server", - }, - { - id: "change_streams", - name: "Change Streams", - description: "Change Streams", - parentProductId: "server", - }, - { - id: "compass", - name: "MongoDB Compass", - description: "GUI tool for MongoDB", - }, - { - id: "gridfs", - name: "GridFS", - description: "GridFS", - parentProductId: "server", - }, - { - id: "indexes", - name: "Indexes", - description: "Indexes", - parentProductId: "server", - }, - { - id: "bi_connector", - name: "MongoDB Connector for BI", - }, - { - id: "realm_sdk", - name: "Realm SDK", - }, - { - id: "atlas_app_services", - name: "Atlas App Services", - parentProductId: "atlas", - }, - { - id: "atlas_stream_processing", - name: "Atlas Stream Processing", - parentProductId: "atlas", - }, - { - id: "atlas_triggers", - name: "Atlas Triggers", - parentProductId: "atlas", - }, - { - id: "atlas_device_sync", - name: "Atlas Device Sync", - parentProductId: "atlas", - }, - { - id: "atlas_data_api", - name: "Atlas Data API", - parentProductId: "atlas", - }, - { - id: "mongodb_ops_manager", - name: "MongoDB Ops Manager", - }, - { - id: "mongodb_cloud_manager", - name: "MongoDB Cloud Manager", - }, -] as const satisfies MongoDbProduct[]; - -export const MongoDBProgrammingLanguageSchema = z.object({ - id: z.string().describe("Unique identifier for the topic"), - name: z.string().optional().describe("Human-friendly name of the topic"), - description: z.string().optional().describe("Brief description of the topic"), -}); -export type MongoDbProgrammingLanguage = z.infer< - typeof MongoDBProgrammingLanguageSchema ->; - -export const mongoDbProgrammingLanguages = [ - { - id: "shell", - }, - { - id: "javascript", - name: "JavaScript", - }, - { - id: "typescript", - name: "TypeScript", - }, - { - id: "python", - name: "Python", - }, - { - id: "java", - name: "Java", - }, - { - id: "csharp", - name: "C#", - }, - { - id: "cpp", - name: "C++", - }, - { - id: "ruby", - name: "Ruby", - }, - { - id: "kotlin", - name: "Kotlin", - }, - { - id: "c", - name: "C", - }, - { - id: "dart", - name: "Dart", - }, - { - id: "go", - name: "Go", - }, - { - id: "php", - name: "PHP", - }, - { - id: "rust", - name: "Rust", - }, - { - id: "scala", - name: "Scala", - }, - { - id: "swift", - name: "Swift", - }, -] as const satisfies MongoDbProgrammingLanguage[]; - -export const MongoDbTopicSchema = z.object({ - id: z.string().describe("Unique identifier for the topic"), - name: z.string().describe("Human-friendly name of the topic").optional(), - description: z.string().optional().describe("Brief description of the topic"), -}); -export type MongoDbTopic = z.infer; - -export const mongoDbTopics = [ - { - id: "multi_cloud", - }, - { - id: "analytics", - }, - { - id: "security", - }, - { - id: "sharding", - }, - { - id: "replication", - }, - { - id: "performance", - }, -] as const satisfies MongoDbTopic[]; - -// Helpers for constructing the `MongoDbTag` union type -const mongoDbProductIds = mongoDbProducts.map((product) => product.id); -const mongoDbTopicIds = mongoDbTopics.map((topic) => topic.id); -export const mongoDbProgrammingLanguageIds = mongoDbProgrammingLanguages.map( - (language) => language.id -); - -/** - All possible MongoDB tags. Useful for tagging evaluations. - */ -export type MongoDbTag = - | (typeof mongoDbProgrammingLanguageIds)[number] - | (typeof mongoDbProductIds)[number] - | (typeof mongoDbTopicIds)[number]; diff --git a/packages/chatbot-server-mongodb-public/src/mongoDbMetadata/index.ts b/packages/chatbot-server-mongodb-public/src/mongoDbMetadata/index.ts new file mode 100644 index 00000000..27f79b58 --- /dev/null +++ b/packages/chatbot-server-mongodb-public/src/mongoDbMetadata/index.ts @@ -0,0 +1,4 @@ +export * from "./products"; +export * from "./programmingLanguages"; +export * from "./tags"; +export * from "./topics"; diff --git a/packages/chatbot-server-mongodb-public/src/mongoDbMetadata/products.ts b/packages/chatbot-server-mongodb-public/src/mongoDbMetadata/products.ts new file mode 100644 index 00000000..857c90c1 --- /dev/null +++ b/packages/chatbot-server-mongodb-public/src/mongoDbMetadata/products.ts @@ -0,0 +1,320 @@ +import { z } from "zod"; +import { mongoDbProgrammingLanguageIds } from "./programmingLanguages"; + +export const MongoDbProductSchema = z.object({ + id: z.string().describe("Unique identifier for the product"), + name: z.string().describe("Human-friendly name of the product"), + description: z + .string() + .optional() + .describe("Brief description of the product"), + programmingLanguage: z + .enum(mongoDbProgrammingLanguageIds) + .optional() + .describe("The programming language used to interact with the product"), + parentProductId: z.string().optional().describe("`id` of the parent product"), +}); +export type MongoDbProduct = z.infer; + +/** + Available MongoDB drivers. + */ +export const mongodbDrivers = [ + { + id: "c_driver", + name: "C Driver", + description: "MongoDB C Driver", + parentProductId: "driver", + programmingLanguage: "c", + }, + { + id: "cpp_driver", + name: "C++ Driver", + description: "MongoDB C++ Driver", + parentProductId: "driver", + programmingLanguage: "cpp", + }, + { + id: "csharp_driver", + name: "C# Driver", + description: "MongoDB C# Driver", + parentProductId: "driver", + programmingLanguage: "csharp", + }, + { + id: "entity_framework_core", + name: "Entity Framework Core Provider", + description: "MongoDB Entity Framework Core Provider", + parentProductId: "driver", + programmingLanguage: "csharp", + }, + { + id: "go_driver", + name: "Go Driver", + description: "MongoDB Go Driver", + parentProductId: "driver", + programmingLanguage: "go", + }, + { + id: "java_sync_driver", + name: "Java Sync Driver", + description: "MongoDB Java Sync Driver", + parentProductId: "driver", + programmingLanguage: "java", + }, + { + id: "java_reactive_streams_driver", + name: "Java Reactive Streams Driver", + description: "MongoDB Java Reactive Streams Driver", + parentProductId: "driver", + programmingLanguage: "java", + }, + { + id: "kotlin_coroutine_driver", + name: "Kotlin Coroutine Driver", + description: "MongoDB Kotlin Coroutine Driver", + parentProductId: "driver", + programmingLanguage: "kotlin", + }, + { + id: "kotlin_sync_driver", + name: "Kotlin Sync Driver", + description: "MongoDB Kotlin Sync Driver", + parentProductId: "driver", + programmingLanguage: "kotlin", + }, + { + id: "nodejs_driver", + name: "Node.js Driver", + description: "MongoDB Node.js Driver", + parentProductId: "driver", + programmingLanguage: "javascript", + }, + { + id: "laravel_mongodb", + name: "Laravel MongoDB", + description: "Laravel MongoDB integration", + parentProductId: "driver", + programmingLanguage: "php", + }, + { + id: "php_library", + name: "PHP Library", + description: "MongoDB PHP Library", + parentProductId: "driver", + programmingLanguage: "php", + }, + { + id: "pymongo_driver", + name: "PyMongo Driver", + description: "MongoDB PyMongo Driver", + parentProductId: "driver", + programmingLanguage: "python", + }, + { + id: "pymongo_arrow_driver", + name: "PyMongo Arrow Driver", + description: + "MongoDB PyMongo Arrow Driver for Apache Arrow tables, NumPy arrays, and Pandas or Polars DataFrames", + parentProductId: "driver", + programmingLanguage: "python", + }, + { + id: "ruby_driver", + name: "Ruby Driver", + description: "MongoDB Ruby Driver", + parentProductId: "driver", + programmingLanguage: "ruby", + }, + { + id: "mongoid_odm", + name: "Mongoid ODM", + description: "MongoDB Mongoid ODM for Ruby on Rails", + parentProductId: "driver", + programmingLanguage: "ruby", + }, + { + id: "rust_driver", + name: "Rust Driver", + description: "MongoDB Rust Driver", + parentProductId: "driver", + programmingLanguage: "rust", + }, + { + id: "scala_driver", + name: "Scala Driver", + description: "MongoDB Scala Driver", + parentProductId: "driver", + programmingLanguage: "scala", + }, + { + id: "swift_driver", + name: "Swift Driver", + description: "MongoDB Swift Driver", + parentProductId: "driver", + programmingLanguage: "swift", + }, +] as const satisfies MongoDbProduct[]; + +/** + Available MongoDB products. + */ +export const mongoDbProducts = [ + { + id: "server", + name: "MongoDB Server", + description: "Core MongoDB server", + }, + { + id: "aggregation", + name: "Aggregation Framework", + description: "Process multiple documents and return computed results", + parentProductId: "server", + }, + { + id: "atlas", + name: "MongoDB Atlas", + description: "Cloud database platform-as-a-service", + }, + { + id: "atlas_charts", + name: "Atlas Charts", + description: "Visualize data stored in MongoDB Atlas", + parentProductId: "atlas", + }, + { + id: "atlas_search", + name: "Atlas Search", + description: "Full-text search on your data in MongoDB Atlas", + parentProductId: "atlas", + }, + { + id: "atlas_vector_search", + name: "Atlas Vector Search", + description: "Vector search on your data in MongoDB Atlas", + parentProductId: "atlas", + }, + { + id: "data_federation", + name: "Data Federation", + description: + "Query data across multiple MongoDB databases and cloud object stores", + }, + { + id: "atlas_cli", + name: "Atlas CLI", + description: "CLI to interact with MongoDB Atlas", + parentProductId: "atlas", + }, + { + id: "driver", + name: "Drivers", + description: "Client libraries for querying MongoDB", + parentProductId: "server", + }, + { + id: "change_streams", + name: "Change Streams", + description: "Listen to changes in MongoDB data", + parentProductId: "server", + }, + { + id: "compass", + name: "MongoDB Compass", + description: "GUI tool for MongoDB", + }, + { + id: "gridfs", + name: "GridFS", + description: "Store large files across multiple MongoDB documents", + parentProductId: "server", + }, + { + id: "bi_connector", + name: "MongoDB Connector for BI", + description: + "Query MongoDB data with SQL using business intelligence tools.", + }, + { + id: "atlas_stream_processing", + name: "Atlas Stream Processing", + parentProductId: "atlas", + description: "Real-time data processing with MongoDB Atlas", + }, + { + id: "atlas_triggers", + name: "Atlas Triggers", + parentProductId: "atlas", + }, + { + id: "mongodb_ops_manager", + name: "MongoDB Ops Manager", + description: "On-prem management tool for MongoDB", + }, + { + id: "mongodb_cloud_manager", + name: "MongoDB Cloud Manager", + description: "Self-hosted management tool for MongoDB in the cloud", + }, + { + id: "spark_connector", + name: "Spark Connector", + description: "MongoDB Connector for Apache Spark", + }, + { + id: "shell", + name: "MongoDB Shell (mongosh)", + description: + "JavaScript and Node.js REPL for interacting with MongoDB deployments", + }, + { + id: "atlas_gov", + name: "MongoDB Atlas for Government", + description: "MongoDB Atlas for Government", + }, + { + id: "vs_code_extension", + name: "VS Code Extension", + description: "Visual Studio Cod extension for MongoDB", + }, + { + id: "mongodb_cli", + name: "MongoDB CLI", + description: "CLI for interacting with MongoDB deployments", + }, + { + id: "visual_studio_extension", + name: "C# Analyzer", + description: "C# Roslyn Analyzer for MongoDB", + }, + { + id: "kafka_connector", + name: "Kafka Connector", + description: "MongoDB Kafka Connector", + }, + { + id: "cluster_sync", + name: "Cluster-to-Cluster Sync", + description: "Sync data between MongoDB clusters", + }, + { + id: "k8s_operator", + name: "Kubernetes Operator", + description: + "Manage the typical lifecycle events for a MongoDB cluster deployed to Kubernetes", + }, + { + id: "relational_migrator", + name: "Relational Migrator", + description: "Migrates data from relational databases to MongoDB", + }, +] as const satisfies MongoDbProduct[]; + +export type MongoDbProductName = (typeof mongoDbProducts)[number]["name"]; +export type MongoDbProductNameEnum = [ + MongoDbProductName, + ...MongoDbProductName[] +]; +export const mongoDbProductNames = mongoDbProducts.map( + (prod) => prod.name +) as MongoDbProductNameEnum; diff --git a/packages/chatbot-server-mongodb-public/src/mongoDbMetadata/programmingLanguages.ts b/packages/chatbot-server-mongodb-public/src/mongoDbMetadata/programmingLanguages.ts new file mode 100644 index 00000000..47ae6082 --- /dev/null +++ b/packages/chatbot-server-mongodb-public/src/mongoDbMetadata/programmingLanguages.ts @@ -0,0 +1,86 @@ +import { z } from "zod"; + +export const mongoDbProgrammingLanguages = [ + { + id: "shell", + }, + { + id: "javascript", + name: "JavaScript", + }, + { + id: "typescript", + name: "TypeScript", + }, + { + id: "python", + name: "Python", + }, + { + id: "java", + name: "Java", + }, + { + id: "csharp", + name: "C#", + }, + { + id: "cpp", + name: "C++", + }, + { + id: "ruby", + name: "Ruby", + }, + { + id: "kotlin", + name: "Kotlin", + }, + { + id: "c", + name: "C", + }, + { + id: "dart", + name: "Dart", + }, + { + id: "go", + name: "Go", + }, + { + id: "php", + name: "PHP", + }, + { + id: "rust", + name: "Rust", + }, + { + id: "scala", + name: "Scala", + }, + { + id: "swift", + name: "Swift", + }, +] as const satisfies MongoDbProgrammingLanguage[]; + +export type MongoDbProgrammingLanguageId = + (typeof mongoDbProgrammingLanguages)[number]["id"]; +export type MongoDbProgrammingLanguageIdEnum = [ + MongoDbProgrammingLanguageId, + ...MongoDbProgrammingLanguageId[] +]; +export const mongoDbProgrammingLanguageIds = mongoDbProgrammingLanguages.map( + (language) => language.id +) as MongoDbProgrammingLanguageIdEnum; + +export const MongoDBProgrammingLanguageSchema = z.object({ + id: z.string().describe("Unique identifier for the topic"), + name: z.string().optional().describe("Human-friendly name of the topic"), + description: z.string().optional().describe("Brief description of the topic"), +}); +export type MongoDbProgrammingLanguage = z.infer< + typeof MongoDBProgrammingLanguageSchema +>; diff --git a/packages/chatbot-server-mongodb-public/src/mongoDbMetadata/tags.ts b/packages/chatbot-server-mongodb-public/src/mongoDbMetadata/tags.ts new file mode 100644 index 00000000..a4253888 --- /dev/null +++ b/packages/chatbot-server-mongodb-public/src/mongoDbMetadata/tags.ts @@ -0,0 +1,17 @@ +import { mongoDbProducts, mongodbDrivers } from "./products"; +import { mongoDbProgrammingLanguageIds } from "./programmingLanguages"; +import { mongoDbTopics } from "./topics"; + +// Helpers for constructing the `MongoDbTag` union type +const mongoDbProductIds = mongoDbProducts.map((product) => product.id); +const mongoDbDriverIds = mongodbDrivers.map((driver) => driver.id); +const mongoDbTopicIds = mongoDbTopics.map((topic) => topic.id); + +/** + All possible MongoDB tags. Useful for tagging evaluations. + */ +export type MongoDbTag = + | (typeof mongoDbProgrammingLanguageIds)[number] + | (typeof mongoDbProductIds)[number] + | (typeof mongoDbDriverIds)[number] + | (typeof mongoDbTopicIds)[number]; diff --git a/packages/chatbot-server-mongodb-public/src/mongoDbMetadata/topics.ts b/packages/chatbot-server-mongodb-public/src/mongoDbMetadata/topics.ts new file mode 100644 index 00000000..8033aaf2 --- /dev/null +++ b/packages/chatbot-server-mongodb-public/src/mongoDbMetadata/topics.ts @@ -0,0 +1,31 @@ +import { z } from "zod"; +export const MongoDbTopicSchema = z.object({ + id: z.string().describe("Unique identifier for the topic"), + name: z.string().describe("Human-friendly name of the topic").optional(), + description: z.string().optional().describe("Brief description of the topic"), +}); +export type MongoDbTopic = z.infer; + +export const mongoDbTopics = [ + { + id: "multi_cloud", + }, + { + id: "analytics", + }, + { + id: "security", + }, + { + id: "sharding", + }, + { + id: "replication", + }, + { + id: "performance", + }, + { + id: "indexes", + }, +] as const satisfies MongoDbTopic[]; diff --git a/packages/chatbot-server-mongodb-public/src/processors/extractMongoDbMetadataFromUserMessage.eval.ts b/packages/chatbot-server-mongodb-public/src/processors/extractMongoDbMetadataFromUserMessage.eval.ts index caed1d37..1e2897de 100644 --- a/packages/chatbot-server-mongodb-public/src/processors/extractMongoDbMetadataFromUserMessage.eval.ts +++ b/packages/chatbot-server-mongodb-public/src/processors/extractMongoDbMetadataFromUserMessage.eval.ts @@ -38,7 +38,7 @@ const evalCases: ExtractMongoDbMetadataEvalCase[] = [ input: "pymongo insert data", expected: { programmingLanguage: "python", - mongoDbProduct: "Driver", + mongoDbProduct: "Drivers", } satisfies ExtractMongoDbMetadataFunction, tags: ["driver", "python"], }, @@ -71,7 +71,7 @@ const evalCases: ExtractMongoDbMetadataEvalCase[] = [ input: "how to open a change stream watch on a database and filter the stream", expected: { - mongoDbProduct: "Driver", + mongoDbProduct: "Drivers", programmingLanguage: "javascript", } satisfies ExtractMongoDbMetadataFunction, tags: ["change_streams"], @@ -81,7 +81,7 @@ const evalCases: ExtractMongoDbMetadataEvalCase[] = [ input: "how to open a change stream watch on a database and filter the stream pymongo", expected: { - mongoDbProduct: "Driver", + mongoDbProduct: "Drivers", programmingLanguage: "python", } satisfies ExtractMongoDbMetadataFunction, tags: ["change_streams"], @@ -91,7 +91,7 @@ const evalCases: ExtractMongoDbMetadataEvalCase[] = [ input: "How do I choose the order of fields when creating a compound index?", expected: { - mongoDbProduct: "MongoDB", + mongoDbProduct: "MongoDB Server", programmingLanguage: "javascript", } satisfies ExtractMongoDbMetadataFunction, tags: ["indexes"], @@ -108,7 +108,7 @@ const evalCases: ExtractMongoDbMetadataEvalCase[] = [ name: "should recognize MongoDB for analytics", input: "How do I run real-time analytics on my data?", expected: { - mongoDbProduct: "MongoDB", + mongoDbProduct: "MongoDB Server", } satisfies ExtractMongoDbMetadataFunction, tags: ["analytics"], }, @@ -116,7 +116,7 @@ const evalCases: ExtractMongoDbMetadataEvalCase[] = [ name: "should detect transaction management topic", input: "How do I manage multi-document transactions?", expected: { - mongoDbProduct: "MongoDB", + mongoDbProduct: "MongoDB Server", } satisfies ExtractMongoDbMetadataFunction, tags: ["server"], }, @@ -133,7 +133,7 @@ const evalCases: ExtractMongoDbMetadataEvalCase[] = [ input: "How do I connect to MongoDB using the Java driver?", expected: { programmingLanguage: "java", - mongoDbProduct: "Driver", + mongoDbProduct: "Drivers", } satisfies ExtractMongoDbMetadataFunction, tags: ["driver", "java"], }, @@ -142,7 +142,7 @@ const evalCases: ExtractMongoDbMetadataEvalCase[] = [ input: "How do I query a collection using LINQ in C#?", expected: { programmingLanguage: "csharp", - mongoDbProduct: "Driver", + mongoDbProduct: "Drivers", } satisfies ExtractMongoDbMetadataFunction, tags: ["driver", "csharp"], }, @@ -160,7 +160,7 @@ const evalCases: ExtractMongoDbMetadataEvalCase[] = [ input: "How do I handle MongoDB connections in Node.js?", expected: { programmingLanguage: "javascript", - mongoDbProduct: "Driver", + mongoDbProduct: "Drivers", } satisfies ExtractMongoDbMetadataFunction, tags: ["driver", "javascript"], }, @@ -169,7 +169,7 @@ const evalCases: ExtractMongoDbMetadataEvalCase[] = [ input: "How do I insert multiple documents with the MongoDB Go driver?", expected: { programmingLanguage: "go", - mongoDbProduct: "Driver", + mongoDbProduct: "Drivers", } satisfies ExtractMongoDbMetadataFunction, tags: ["driver", "go"], }, diff --git a/packages/chatbot-server-mongodb-public/src/processors/extractMongoDbMetadataFromUserMessage.ts b/packages/chatbot-server-mongodb-public/src/processors/extractMongoDbMetadataFromUserMessage.ts index 448db448..061090cc 100644 --- a/packages/chatbot-server-mongodb-public/src/processors/extractMongoDbMetadataFromUserMessage.ts +++ b/packages/chatbot-server-mongodb-public/src/processors/extractMongoDbMetadataFromUserMessage.ts @@ -6,30 +6,27 @@ import { } from "./makeFewShotUserMessageExtractorFunction"; import { ChatCompletionMessageParam } from "openai/resources"; import { + mongoDbProductNames, mongoDbProducts, mongoDbProgrammingLanguageIds, } from "../mongoDbMetadata"; export const ExtractMongoDbMetadataFunctionSchema = z.object({ programmingLanguage: z - // Need to cast as string array with at least one element - // to satisfy zod's type checking. - .enum(mongoDbProgrammingLanguageIds as [string, ...string[]]) + .enum(mongoDbProgrammingLanguageIds) .default("javascript") .describe( 'Programming language present in the content. If no programming language is present and a code example would answer the question, include "javascript".' ) .optional(), mongoDbProduct: z - .string() + .enum(mongoDbProductNames) .describe( - `One or more MongoDB products present in the content. Order by relevancy. Include "Driver" if the user is asking about a programming language with a MongoDB driver. - Example values: ${mongoDbProducts - .map((p) => `"${p.name}"`) - .join(", ")} ...other MongoDB products. - If the product is ambiguous, say "MongoDB Server".` + `Most important MongoDB products present in the content. +Include "Driver" if the user is asking about a programming language with a MongoDB driver. +If the product is ambiguous, say "MongoDB Server".` ) - .default("MongoDBServer ") + .default("MongoDB Server") .optional(), }); @@ -65,13 +62,13 @@ const fewShotExamples: ChatCompletionMessageParam[] = [ makeUserMessage("pymongo insert data"), makeAssistantFunctionCallMessage(name, { programmingLanguage: "python", - mongoDbProduct: "Driver", + mongoDbProduct: "Drivers", } satisfies ExtractMongoDbMetadataFunction), // Example 5 makeUserMessage("How do I create an index in MongoDB using the Java driver?"), makeAssistantFunctionCallMessage(name, { programmingLanguage: "java", - mongoDbProduct: "Driver", + mongoDbProduct: "Drivers", } satisfies ExtractMongoDbMetadataFunction), // Example 6 makeUserMessage("$lookup"),