Skip to content

feat(ml): build Python ML pipeline against FeatureVector and ModelResult contract (#364) - #369

Draft
s6pa1rta3n-lab wants to merge 1 commit into
nexoraorg:mainfrom
s6pa1rta3n-lab:fix-issue-364
Draft

s6pa1rta3n-lab wants to merge 1 commit into
nexoraorg:mainfrom
s6pa1rta3n-lab:fix-issue-364

Conversation

@s6pa1rta3n-lab

Copy link
Copy Markdown

Summary

Implements the Python ML pipeline against the existing FeatureVector and ModelResult contract, closing #364.

Key Components Implemented

  • Contract Layer (ml/contract.py): Dynamically extracts NUMERIC_FEATURE_SPECS directly from packages/chenai-mlflow/src/index.ts to preserve a single source of truth across languages. Implements strict validation and missing-value imputation adhering to FeatureVector and ModelResult schemas.
  • Horizon Ingest (ml/ingest.py): StellarHorizonClient consuming Stellar Horizon REST API for accounts, operations, payments, and transactions.
  • Feature Builder (ml/features.py): Transforms raw Horizon ledger history into contract-compliant FeatureVector payloads.
  • Scoring Models (ml/models.py):
    • CreditScoreModel: Gradient Boosting classifier producing calibrated risk scores in [0, 1] with risk labels (low, medium, high) and confidence values.
    • FraudDetectModel: Isolation Forest anomaly detector producing calibrated anomaly risk scores in [0, 1].
    • Computes 32-byte SHA-256 artifact digests matching Soroban BytesN<32> in contracts/model-attestation.
  • ModelResult Emitter (ml/emitter.py): Scores vectors, tracks imputedFields, and formats contract-compliant ModelResult payloads and Soroban model-attestation records.
  • Sinks (ml/sinks.py): Supports FileDropSink (.jsonl or atomic per-account JSON), SqliteSink (indexed SQLite database), and StdoutSink.
  • Pipeline Runner (ml/pipeline.py): CLI and programmatic interface for single-subject Horizon scoring and batch file processing.
  • Reproducible Training (ml/train.py): Trains models against synthetic dataset ml/data/sample_dataset.json, emits tamper-evident signed evaluation reports (ml/evaluation_report.py), and writes ml/artifacts/manifest.json.
  • Bidirectional Verification (ml/tests/): 49 unit tests covering all modules, plus cross-language tests validating Python outputs in @chenaikit/chenai-mlflow's Node harness and vice versa.
  • CI Workflow (.github/workflows/backend.yml): Adds automated Python ML testing job to GitHub Actions CI.

Testing done

  • pytest ml/tests: 49 passed.
  • pnpm --filter @chenaikit/chenai-mlflow run build and pnpm --filter @chenaikit/chenai-mlflow run test: 53 passed.
  • pnpm run test:integration: 11 passed.
  • Tested CLI single mode: python3 ml/pipeline.py --mode single --subject-id GACC123 --sink stdout
  • Tested CLI batch mode: python3 ml/pipeline.py --mode batch --input-file ml/data/sample_vectors.jsonl --sink sqlite --output ml/output/scores.db
  • Ran Node PR checklist validator: checkPullRequest returned ok: true.

Checklist

  • Branch named fix-issue-364
  • Follows conventional commit format
  • Implements strict contract validation against FeatureVector and ModelResult (schema version 1.0.0)
  • All unit and integration tests pass locally
  • Documentation updated in ml/README.md
  • CI workflow updated in .github/workflows/backend.yml

Payout Routing

  • EVM (Base/Arbitrum/Polygon/ETH): 0xF46C9F6d70C50BF81ef3588AB523a90a594a2F89
  • Stellar: GCL6OXAMLD75BMTINA6EMRUDWK5THQUSHMYNLSNBCJAPZJHNYJTUNIBC

…lResult contract

- Extract NUMERIC_FEATURE_SPECS dynamically from packages/chenai-mlflow
- Implement contract validation and missing-value imputation
- Implement Stellar Horizon REST ingestion client
- Implement FeatureBuilder transforming ledger history to contract-compliant vectors
- Implement CreditScoreModel (GBM) and FraudDetectModel (IForest) with SHA-256 digests
- Implement ModelResultEmitter with Soroban model-attestation compatibility
- Implement FileDropSink, SqliteSink, and StdoutSink
- Implement CLI and programmatic PipelineRunner
- Add unit tests and bidirectional cross-language contract verification tests
- Add GitHub Actions CI workflow for Python ML pipeline

Closes nexoraorg#364
@vercel

vercel Bot commented Sep 8, 2026

Copy link
Copy Markdown

@s6pa1rta3n-lab is attempting to deploy a commit to the Isaac Gellu's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant