Skip to content

Latest commit

 

History

History
143 lines (102 loc) · 4.01 KB

File metadata and controls

143 lines (102 loc) · 4.01 KB

PrisML

CI

Compiler-first machine learning library for TypeScript + Prisma applications.

Overview

PrisML treats ML model training as a compile-time step, generating immutable ONNX artifacts that provide type-safe, in-process predictions at runtime.

Philosophy:

  • Training = compilation (build-time)
  • Artifacts = immutable binaries (committed to git)
  • Predictions = synchronous function calls (in-process)

Requirements

Node.js: 18 or higher

Python 3.9+ is required for the prisml train command. The training backend uses the following packages (pinned in packages/cli/python/requirements.txt):

numpy==1.26.4
scikit-learn==1.5.2
skl2onnx==1.16.0
onnx==1.16.0

Install them in your environment before running prisml train:

pip install -r node_modules/@vncsleal/prisml-cli/python/requirements.txt

Note: Python is a build-time dependency only — it is not required at runtime. Prediction via PredictionSession runs entirely in Node.js against the compiled ONNX artifact.

Quick Start

Installation

# Runtime (application dependency)
npm install @vncsleal/prisml

# CLI (dev/build-time only)
npm install --save-dev @vncsleal/prisml-cli

@vncsleal/prisml contains only the runtime prediction engine (core types + PredictionSession). The CLI — which shells out to Python to produce ONNX artifacts — is a build-time tool and should not be a runtime dependency of your application.

1. Define Models

Create prisml.config.ts:

import { defineModel } from '@vncsleal/prisml';

export const salesModel = defineModel<Product>({
  name: 'ProductSales',
  modelName: 'Product',
  output: { field: 'sales', taskType: 'regression' },
  features: {
    price: (p) => p.price,
    stock: (p) => p.stock,
  },
  algorithm: { name: 'forest', version: '1.0.0' },
});

2. Train Models

npx prisml train --config ./prisml.config.ts --schema ./prisma/schema.prisma

Generates immutable artifacts:

  • ProductSales.onnx - Model binary
  • ProductSales.metadata.json - Schema contract

3. Run Predictions

import { PredictionSession } from '@vncsleal/prisml';

const session = new PredictionSession();
await session.initializeModel(
  './.prisml/ProductSales.metadata.json',
  './.prisml/ProductSales.onnx',
  schemaHash
);

const result = await session.predict('ProductSales', product, {
  price: (p) => p.price,
  stock: (p) => p.stock,
});

Features

✓ Type-safe model definitions
✓ Prisma schema binding with drift detection
✓ Schema-only contract validation (prisml check)
✓ ONNX Runtime integration
✓ Deterministic feature encoding
✓ Quality gates for build-time validation
✓ Typed error handling

Packages

Package Install as Purpose
@vncsleal/prisml dependency Runtime entry point — re-exports core types and PredictionSession
@vncsleal/prisml-core dependency Model definitions, types, encoding, schema hashing
@vncsleal/prisml-runtime dependency ONNX inference engine (PredictionSession)
@vncsleal/prisml-cli devDependency prisml train and prisml check commands
@vncsleal/prisml-generator devDependency Prisma generator for schema annotations

Documentation

Development

# Install dependencies
pnpm install

# Build all packages
pnpm -r build

# Run tests
pnpm test

# Run tests in watch mode
pnpm test:watch

License

MIT © Vinicius Leal