AI Forge Documentation

0G Storage Integration

Integrate 0G Decentralized Storage

Seamlessly integrate 0G Network's high-performance decentralized storage into your AI agents. Store models, persist state, and manage data with enterprise-grade reliability and performance.

99.9%
Uptime SLA
< 100ms
Latency
10GB/s
Throughput
90%
Cost Savings

Quick Integration

1

SDK Installation

Install the 0G Storage SDK and dependencies

npm install @0g/storage-sdk @aiforge/sdk

# Or with yarn
yarn add @0g/storage-sdk @aiforge/sdk
2

Initialize Client

Set up the storage client with your credentials

import { ZeroGStorage } from '@0g/storage-sdk'

const storage = new ZeroGStorage({
  apiKey: process.env.ZEROG_API_KEY,
  network: '0g-mainnet', // or '0g-testnet'
  endpoint: 'https://storage.0g.ai'
})
3

Agent Integration

Connect storage to your AI agent

import { AIForge } from '@aiforge/sdk'

const agent = await AIForge.createAgent({
  name: 'Storage-Enabled Agent',
  storage: storage, // Pass storage instance
  config: {
    persistState: true,
    modelVersioning: true,
    backupInterval: 3600 // 1 hour
  }
})

Common Operations

Store AI Model

Upload and version your AI models

// Store AI model with metadata
const modelHash = await storage.uploadModel({
  file: './my-model.bin',
  metadata: {
    name: 'Trading Bot v2.1',
    type: 'neural-network',
    accuracy: 0.95,
    trainingData: 'crypto-prices-2024',
    description: 'Advanced DeFi trading model'
  },
  tags: ['trading', 'defi', 'arbitrage']
})

console.log('Model stored with hash:', modelHash)

Load Model

Retrieve and load your AI models

// Load model by hash
const model = await storage.loadModel(modelHash)

// Load latest version by name
const latestModel = await storage.loadLatestModel('Trading Bot')

// Initialize agent with stored model
agent.loadModel(model)

State Persistence

Save and restore agent state

// Save agent state
await agent.saveState({
  portfolio: { USDC: 1000, ETH: 0.5 },
  positions: [...currentPositions],
  performance: { totalReturn: 0.15, sharpeRatio: 1.2 }
})

// Restore state on restart
const savedState = await agent.loadState()
agent.restoreState(savedState)

Data Analytics

Store and query historical data

// Store trading data
await storage.storeAnalytics({
  timestamp: Date.now(),
  type: 'trade_executed',
  data: {
    pair: 'ETH/USDC',
    amount: 0.5,
    price: 2500,
    profit: 12.50
  }
})

// Query historical performance
const performance = await storage.queryAnalytics({
  timeRange: '30d',
  metrics: ['profit', 'trades', 'success_rate']
})

Key Features

Automatic Versioning

Track model versions with automatic metadata

  • Git-like versioning
  • Rollback capabilities
  • Change tracking
  • Metadata preservation

High Availability

Distributed storage with 99.9% uptime guarantee

  • Multi-node replication
  • Automatic failover
  • Geographic distribution
  • Data redundancy

Performance Optimized

Fast retrieval with global edge caching

  • < 100ms retrieval
  • Global CDN
  • Intelligent caching
  • Bandwidth optimization

Developer Friendly

Simple APIs with comprehensive documentation

  • RESTful APIs
  • SDK support
  • GraphQL queries
  • WebSocket streams

Best Practices

✅ Do

  • Use meaningful metadata for better organization
  • Implement automatic backup strategies
  • Version your models for rollback capability
  • Use compression for large files
  • Monitor storage usage and costs

❌ Don't

  • Store sensitive data without encryption
  • Ignore storage quotas and limits
  • Skip error handling for storage operations
  • Store frequently changing data without optimization
  • Forget to clean up unused data

Next Steps