trainModel
Improve statistical model generation quality by updating it with additional sample documents for more realistic data simulation.
Instructions
Update an existing statistical model with additional sample documents to improve generation quality
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| model | Yes | Model name | |
| documents | Yes | Documents to train with |
Implementation Reference
- src/mcp/index.js:410-423 (handler)Primary MCP tool handler for trainModel: infers JSON schema from input documents and persists it as a DataFlood model using storage.case 'trainModel': // For incremental training, merge with existing samples if available const newSchema = schemaInferrer.inferSchema(args.documents); // Save pure DataFlood schema await storage.saveModel(config.storage.defaultDatabase, args.model, newSchema); models.set(args.model, newSchema); return { content: [{ type: 'text', text: `Model '${args.model}' updated with ${args.documents.length} new documents\n\nSchema fields: ${Object.keys(newSchema.properties || {}).join(', ')}` }] };
- src/mcp/index.js:184-195 (schema)Input schema definition for the trainModel MCP tool.{ name: 'trainModel', description: 'Update an existing statistical model with additional sample documents to improve generation quality', inputSchema: { type: 'object', properties: { model: { type: 'string', description: 'Model name' }, documents: { type: 'array', description: 'Documents to train with', items: { type: 'object' } } }, required: ['model', 'documents'] } },
- src/mcp/mcp-server.js:1033-1048 (handler)Handler method in MCPServerEnhanced class that delegates trainModel execution to storage layer and updates in-memory cache.async trainModel(args) { const { model, documents } = args; if (!documents || documents.length === 0) { throw new Error('No documents provided'); } const trained = await this.storage.trainModel(config.storage.defaultDatabase, model, documents); this.models.set(model, trained); return { success: true, message: `Model '${model}' trained with ${documents.length} documents`, properties: Object.keys(trained.properties || {}) }; }
- src/mcp/mcp-server.js:115-126 (schema)Input schema for trainModel in MCPServerEnhanced.tools array.{ name: 'trainModel', description: 'Train or update a model with new data', inputSchema: { type: 'object', properties: { model: { type: 'string', description: 'Model name' }, documents: { type: 'array', description: 'Documents to train with', items: { type: 'object' } } }, required: ['model', 'documents'] } },
- Core storage layer trainModel method that handles model inference, incremental updates, and persistence to JSON files.async trainModel(modelName, data) { const existingModel = await this.loadModel(modelName); let model; if (existingModel) { // Update existing model const trainer = new IncrementalTrainer(); model = trainer.updateModel(existingModel, data); } else { // Create new model const inferrer = new SchemaInferrer(); model = inferrer.inferSchema(data); } // Save the model const modelPath = join(this.basePath, this.defaultDatabase, `${modelName}.json`); const dir = path.dirname(modelPath); // Ensure directory exists if (!existsSync(dir)) { mkdirSync(dir, { recursive: true }); } // Save to disk writeFileSync(modelPath, JSON.stringify(model, null, 2), 'utf8'); // Update cache const cacheKey = `mcp:${modelName}`; this.addToCache(cacheKey, model); this.logger.info(`Trained model '${modelName}' with ${data.length} samples`); return model; }