JavaScript SDK

Official JavaScript/TypeScript SDK for Sematryx. Works in Node.js, browsers, and modern JavaScript environments.

Install the JavaScript SDK
npm install @sematryx/javascript-sdk

The SDK requires Node.js 16+ or a modern browser with ES6+ support.

Initialize the SDK with your API key and start optimizing:

Basic usage example
import { Sematryx } from '@sematryx/javascript-sdk'

const sematryx = new Sematryx('your-api-key')

// Define objective function
const sphere = (x) => {
  return x.reduce((sum, val) => sum + val * val, 0)
}

// Run optimization
const result = await sematryx.optimize({
  objective_function: sphere,
  bounds: [[-5, 5], [-5, 5]],
  max_evaluations: 1000
})

console.log('Best solution:', result.best_solution)
console.log('Best fitness:', result.best_fitness)

Configure the four pillars of AEAO intelligence:

Tetrad configuration examples
import { Sematryx } from '@sematryx/javascript-sdk'

const sematryx = new Sematryx('your-api-key')

// Option 1: Use preset configuration
const result = await sematryx.optimize({
  objective_function: sphere,
  bounds: [[-5, 5], [-5, 5]],
  preset: 'production'  // development, production, research, enterprise, minimal
})

// Option 2: Enable specific tetrad pillars
const result = await sematryx.optimize({
  objective_function: sphere,
  bounds: [[-5, 5], [-5, 5]],
  use_agentic_intelligence: true,      // Multi-agent coordination
  use_autodidactic_intelligence: true,  // Self-improvement
  explanation_level: 3                   // Detailed explanations
})

// Option 3: Complete custom configuration
const config = {
  tetrad: {
    use_agentic_intelligence: true,
    use_expository_intelligence: true,
    use_autodidactic_intelligence: true,
    use_domain_extension: true
  },
  expository: {
    explanation_level: 4
  },
  agentic: {
    max_agents_per_problem: 5
  }
}
const result = await sematryx.optimize({
  objective_function: sphere,
  bounds: [[-5, 5], [-5, 5]],
  config: config
})

The AEAO Tetrad

  • 🤖 Agentic Intelligence: Multi-agent coordination for strategy selection
  • đź“– Expository Intelligence: Explainable results (levels 0-5)
  • đź§  Autodidactic Intelligence: Self-improvement through learning
  • 🏗️ Domain Extension: Business domain libraries (enabled by default)

Use specialized domain libraries for industry-specific problems:

Domain-specific optimization
import { Sematryx } from '@sematryx/javascript-sdk'

const sematryx = new Sematryx('your-api-key')

// Financial portfolio optimization
const portfolioResult = await sematryx.financial.optimize({
  problem_type: 'portfolio',
  config: {
    assets: ['AAPL', 'GOOGL', 'MSFT', 'TSLA'],
    risk_tolerance: 0.15,
    expected_returns: [0.12, 0.15, 0.10, 0.20]
  },
  max_evaluations: 2000
})

// Healthcare drug discovery
const drugResult = await sematryx.healthcare.optimize({
  problem_type: 'drug_discovery',
  config: {
    target_protein: 'protein_id_123',
    constraints: { toxicity: '< 0.1', solubility: '> 0.5' }
  }
})

Enable advanced capabilities for complex optimization problems:

Advanced features
import { Sematryx } from '@sematryx/javascript-sdk'

const sematryx = new Sematryx('your-api-key')

// GPU acceleration
const gpuResult = await sematryx.optimize({
  objective_function: complexFunction,
  bounds: Array(100).fill([-10, 10]),  // High-dimensional
  use_gpu_acceleration: true
})

// Visual intelligence
const visualResult = await sematryx.optimize({
  objective_function: landscapeFunction,
  bounds: [[-5, 5], [-5, 5]],
  use_visual_intelligence: true,
  explanation_level: 4
})

// Neural-symbolic reasoning
const neuralResult = await sematryx.optimize({
  objective_function: hybridFunction,
  bounds: [[-5, 5], [-5, 5]],
  use_neural_symbolic: true
})

Run multiple optimizations in parallel:

Batch optimization
import { Sematryx } from '@sematryx/javascript-sdk'

const sematryx = new Sematryx('your-api-key')

// Run multiple optimizations in parallel
const problems = [
  { objective: sphere1, bounds: [[-5, 5], [-5, 5]] },
  { objective: sphere2, bounds: [[-10, 10], [-10, 10]] },
  { objective: sphere3, bounds: [[-3, 3], [-3, 3]] }
]

const results = await Promise.all(
  problems.map(p => 
    sematryx.optimize({
      objective_function: p.objective,
      bounds: p.bounds,
      max_evaluations: 1000
    })
  )
)

The SDK throws errors for failed requests. Always handle errors appropriately:

Error handling
try {
  const result = await sematryx.optimize({
    objective_function: sphere,
    bounds: [[-5, 5], [-5, 5]],
    max_evaluations: 1000
  })
} catch (error) {
  if (error.status === 401) {
    console.error('Invalid API key')
  } else if (error.status === 429) {
    console.error('Rate limit exceeded. Please wait and retry.')
  } else if (error.code === 'OPTIMIZATION_ERROR') {
    console.error('Optimization failed:', error.message)
  } else {
    console.error('Error:', error.message)
  }
}

The SDK includes full TypeScript definitions for type safety:

TypeScript usage
import { Sematryx, OptimizationResult, TetradConfig } from '@sematryx/javascript-sdk'

const sematryx = new Sematryx(process.env.SEMATRYX_API_KEY!)

const result: OptimizationResult = await sematryx.optimize({
  objective_function: (x: number[]) => x.reduce((s, v) => s + v * v, 0),
  bounds: [[-5, 5], [-5, 5]],
  max_evaluations: 1000,
  preset: 'production'
})

const config: TetradConfig = {
  tetrad: {
    use_agentic_intelligence: true,
    use_expository_intelligence: true
  },
  expository: {
    explanation_level: 3
  }
}

Manage client identity, privacy settings, and usage quotas:

Identity management examples
import { Sematryx } from '@sematryx/javascript-sdk'

const sematryx = new Sematryx('your-api-key')

// Create client identity
const identity = await sematryx.identity.create({
  email: 'user@example.com',
  organization_id: 'org_123',
  privacy_level: 'aggregated',
  subscription_tier: 'professional'
})

// Get privacy status
const privacyStatus = await sematryx.identity.getPrivacyStatus(identity.client_id)
console.log('Privacy level:', privacyStatus.privacy_level)

// Get usage quotas
const quotas = await sematryx.identity.getQuotas(identity.client_id)
console.log('Optimizations used:', quotas.current_usage.optimizations_per_day)
console.log('Quota:', quotas.api_quotas.optimizations_per_day)

// Configure data sharing
await sematryx.identity.configureSharing(identity.client_id, {
  optimization_results: true,
  performance_metrics: true,
  problem_signatures: false
})

Submit and manage batch optimization jobs:

Batch operations examples
import { Sematryx } from '@sematryx/javascript-sdk'

const sematryx = new Sematryx('your-api-key')

// Submit batch optimization job
const batchJob = await sematryx.batch.submit({
  batch_name: 'portfolio_analysis',
  optimizations: [
    {
      job_name: 'portfolio_1',
      objective_function: 'sphere',
      bounds: [[-5, 5], [-5, 5]],
      max_evaluations: 1000
    },
    {
      job_name: 'portfolio_2',
      objective_function: 'rosenbrock',
  bounds: [[-5, 5], [-5, 5]],
  max_evaluations: 1000
    }
  ],
  parallel_workers: 2
})

// Check batch status
const status = await sematryx.batch.getStatus(batchJob.batch_id)
console.log('Progress:', status.progress_percentage + '%')

// Get batch results
const results = await sematryx.batch.getResults(batchJob.batch_id)
results.job_results.forEach(job => {
  console.log(job.job_name + ':', job.optimal_value)
})

Train models and get learning insights:

Learning system examples
import { Sematryx } from '@sematryx/javascript-sdk'

const sematryx = new Sematryx('your-api-key')

// Train learning model
const trainingData = [
  { problem_type: 'sphere', strategy: 'differential_evolution', success: true },
  { problem_type: 'rosenbrock', strategy: 'shgo', success: true }
]

const trainingResult = await sematryx.learning.train({
  training_data: trainingData,
  model_type: 'cross_problem',
  max_epochs: 100
})

// List trained models
const models = await sematryx.learning.listModels()
models.forEach(model => {
  console.log('Model:', model.model_name, 'Type:', model.model_type)
})

// Get learning insights
const insights = await sematryx.learning.getInsights()
console.log('Total models:', insights.total_models)
console.log('Learning enabled:', insights.learning_enabled)

Multi-objective optimization and sensitivity analysis:

Advanced optimization examples
import { Sematryx } from '@sematryx/javascript-sdk'

const sematryx = new Sematryx('your-api-key')

// Multi-objective optimization
const multiObjResult = await sematryx.advanced.multiObjective({
  objectives: ['sphere', 'rosenbrock'],
  bounds: [[-5, 5], [-5, 5]],
  method: 'nsga2',
  max_evaluations: 2000
})

// Get Pareto frontier
multiObjResult.pareto_frontier.forEach(point => {
  console.log('Solution:', point.solution, 'Objectives:', point.objectives)
})

// Sensitivity analysis
const sensitivityResult = await sematryx.advanced.sensitivityAnalysis({
  objective_function: 'sphere',
  bounds: [[-5, 5], [-5, 5]],
  reference_point: [0.0, 0.0],
  analysis_type: 'global'
})

console.log('Sensitivity scores:', sensitivityResult.sensitivity_scores)

Analyze problem context and get recommendations:

Context intelligence examples
import { Sematryx } from '@sematryx/javascript-sdk'

const sematryx = new Sematryx('your-api-key')

// Analyze problem context
const context = {
  problem_id: 'prob_123',
  problem_type: 'portfolio_optimization',
  domain: 'financial',
  description: 'Optimize portfolio allocation for risk-return tradeoff',
  parameters: { risk_tolerance: 0.15 }
}

const analysis = await sematryx.context.analyze({
  target_context: context,
  similarity_threshold: 0.7,
  include_recommendations: true
})

// Get similar problems
analysis.similar_problems.forEach(similar => {
  console.log('Similar problem:', similar.problem_id, 'Score:', similar.similarity_score)
})

// Get optimization recommendations
analysis.optimization_recommendations.forEach(rec => {
  console.log('Recommendation:', rec)
})

Store and query optimization data:

Data lake examples
import { Sematryx } from '@sematryx/javascript-sdk'

const sematryx = new Sematryx('your-api-key')

// Create data connection
const connection = await sematryx.dataLake.createConnection({
  connection_type: 's3',
  endpoint_url: 'https://s3.amazonaws.com/bucket',
  credentials: { access_key: '...', secret_key: '...' }
})

// Upload dataset
const dataset = await sematryx.dataLake.uploadDataset({
  dataset_name: 'optimization_results',
  data_type: 'optimization_results',
  data: [...],  // Your data
  description: 'Historical optimization results'
})

// Store optimization data
await sematryx.dataLake.storeOptimizationData({
  experiment_id: 'exp_123',
  problem_definition: { bounds: [[-5, 5], [-5, 5]] },
  optimization_results: [...],
  performance_metrics: { duration: 2.5, evaluations: 1000 }
})

// Query data lake
const queryResult = await sematryx.dataLake.query({
  query_type: 'filter',
  dataset_ids: [dataset.dataset_id],
  filters: { experiment_id: 'exp_123' }
})

Submit metrics and generate performance reports:

Analytics examples
import { Sematryx } from '@sematryx/javascript-sdk'

const sematryx = new Sematryx('your-api-key')

// Submit performance metrics
await sematryx.analytics.submitMetrics({
  metrics: [
    {
      metric_name: 'optimization_duration',
      metric_value: 2.5,
      metric_type: 'time'
    },
    {
      metric_name: 'solution_quality',
      metric_value: 0.95,
      metric_type: 'quality'
    }
  ],
  source_system: 'production'
})

// Generate performance report
const report = await sematryx.analytics.generateReport({
  report_type: 'comprehensive',
  metric_categories: ['time', 'quality', 'efficiency'],
  time_range: { start: '2024-01-01', end: '2024-01-31' }
})

// Get performance insights
const insights = await sematryx.analytics.getInsights()
insights.forEach(insight => {
  console.log(insight.insight_type + ':', insight.description)
})

// Get metrics summary
const summary = await sematryx.analytics.getMetricsSummary()
console.log('Average duration:', summary.average_duration)
console.log('Success rate:', summary.success_rate)

Get API configuration and check system health:

Configuration examples
import { Sematryx } from '@sematryx/javascript-sdk'

const sematryx = new Sematryx('your-api-key')

// Get API configuration
const config = await sematryx.config.get()
console.log('API Version:', config.version)
console.log('Environment:', config.environment)

// Get available features
const features = await sematryx.config.getFeatures()
console.log('Optimization available:', features.optimization.available)
console.log('Learning system:', features.ai_capabilities.learning_system)

// Get operational limits
const limits = await sematryx.config.getLimits()
console.log('Max evaluations:', limits.optimization.max_evaluations)
console.log('Max variables:', limits.optimization.max_variables)
Health check examples
import { Sematryx } from '@sematryx/javascript-sdk'

const sematryx = new Sematryx('your-api-key')

// Basic health check
const health = await sematryx.health.check()
console.log('Status:', health.status)
console.log('Uptime:', health.uptime, 'seconds')

// Detailed health check
const detailedHealth = await sematryx.health.detailed()
console.log('Memory usage:', detailedHealth.memory_usage + '%')
console.log('CPU usage:', detailedHealth.cpu_usage + '%')
console.log('Components:', detailedHealth.components)

Sematryx Class

  • new Sematryx(apiKey, options?) - Initialize the SDK
  • sematryx.optimize(config) - Run an optimization
  • sematryx.financial - Financial domain optimization
  • sematryx.healthcare - Healthcare domain optimization
  • sematryx.supplyChain - Supply chain optimization
  • sematryx.identity - Identity management
  • sematryx.batch - Batch operations
  • sematryx.learning - Learning system
  • sematryx.advanced - Advanced optimization
  • sematryx.context - Context intelligence
  • sematryx.dataLake - Data lake operations
  • sematryx.analytics - Analytics and metrics
  • sematryx.config - Configuration
  • sematryx.health - Health checks

Optimization Config

  • objective_function - Function to optimize (required)
  • bounds - Search bounds (required)
  • max_evaluations - Max function evaluations
  • preset - Preset configuration
  • use_agentic_intelligence - Enable agentic pillar
  • use_expository_intelligence - Enable expository pillar
  • use_autodidactic_intelligence - Enable autodidactic pillar
  • explanation_level - Explanation detail (0-5)
  • use_gpu_acceleration - Enable GPU
  • use_visual_intelligence - Enable visual analysis

Configuration Options

  • apiUrl - Custom API base URL (default: https://api.sematryx.com)
  • timeout - Request timeout in milliseconds (default: 30000)
  • retries - Number of retry attempts (default: 3)
  • retryDelay - Delay between retries in milliseconds (default: 1000)