Skip to content

Repository files navigation

πŸš€ AINative Go SDK

High-performance Go client library for AINative Studio APIs with advanced concurrency, observability, and enterprise features.

✨ Features

  • High-Performance HTTP Client: Optimized for concurrent operations with connection pooling
  • Advanced Retry Logic: Exponential backoff with jitter and circuit breaker
  • Full API Coverage: Complete support for ZeroDB, Agent Swarm, and Memory APIs
  • Type Safety: Comprehensive struct definitions with JSON tags
  • Context Propagation: Proper Go context handling throughout
  • Observability: OpenTelemetry integration for metrics and tracing
  • Enterprise Ready: Connection pooling, timeouts, and resource management

πŸš€ Quick Start

Installation

go mod init your-project
go get github.com/AINative-Studio/Go-SDK

Basic Usage

package main

import (
    "context"
    "fmt"
    "log"
    
    "github.com/AINative-Studio/Go-SDK/ainative"
)

func main() {
    // Create client with API key
    client, err := ainative.NewClient(&ainative.Config{
        APIKey: "your-api-key",
        BaseURL: "https://api.ainative.studio",
    })
    if err != nil {
        log.Fatal(err)
    }
    
    ctx := context.Background()
    
    // List projects
    projects, err := client.ZeroDB.Projects.List(ctx, &ainative.ListProjectsRequest{
        Limit: 10,
    })
    if err != nil {
        log.Fatal(err)
    }
    
    fmt.Printf("Found %d projects\n", len(projects.Projects))
}

Vector Operations

// Search vectors
results, err := client.ZeroDB.Vectors.Search(ctx, "project-id", &ainative.VectorSearchRequest{
    Vector: []float64{0.1, 0.2, 0.3},
    TopK:   5,
})
if err != nil {
    log.Fatal(err)
}

fmt.Printf("Found %d similar vectors\n", len(results.Matches))

Agent Swarm

// Start an agent swarm
swarm, err := client.AgentSwarm.Start(ctx, &ainative.StartSwarmRequest{
    ProjectID: "project-id",
    Objective: "Analyze codebase and suggest improvements",
    Agents: []ainative.AgentConfig{
        {Type: "code_analyzer", Count: 2},
        {Type: "security_scanner", Count: 1},
    },
})
if err != nil {
    log.Fatal(err)
}

fmt.Printf("Started swarm: %s\n", swarm.ID)

πŸ“‹ API Coverage

ZeroDB Operations

  • βœ… Projects: Create, list, get, update, suspend, delete
  • βœ… Vectors: Upsert, search, get statistics, manage namespaces
  • βœ… Memory: Store, search, list, tag management
  • βœ… Analytics: Usage statistics, cost analysis, performance metrics

Agent Swarm Operations

  • βœ… Swarms: Start, stop, get status, list active swarms
  • βœ… Orchestration: Task assignment, agent coordination
  • βœ… Monitoring: Real-time metrics, agent health checks
  • βœ… Configuration: Agent types, custom prompts, resource limits

Core Features

  • βœ… Authentication: API key management, JWT tokens
  • βœ… Error Handling: Structured error responses with retry logic
  • βœ… Rate Limiting: Automatic backoff and retry strategies
  • βœ… Observability: OpenTelemetry metrics and tracing

πŸ”§ Advanced Configuration

Custom HTTP Client

import (
    "net/http"
    "time"
    
    "github.com/AINative-Studio/Go-SDK/ainative"
)

client, err := ainative.NewClient(&ainative.Config{
    APIKey:  "your-api-key",
    BaseURL: "https://api.ainative.studio",
    HTTPClient: &http.Client{
        Timeout: 30 * time.Second,
        Transport: &http.Transport{
            MaxIdleConns:        100,
            MaxIdleConnsPerHost: 10,
            IdleConnTimeout:     90 * time.Second,
        },
    },
})

OpenTelemetry Integration

import (
    "go.opentelemetry.io/otel"
    "go.opentelemetry.io/otel/trace"
)

client, err := ainative.NewClient(&ainative.Config{
    APIKey:  "your-api-key",
    BaseURL: "https://api.ainative.studio",
    Tracer:  otel.Tracer("ainative-client"),
})

Retry Configuration

client, err := ainative.NewClient(&ainative.Config{
    APIKey:  "your-api-key",
    BaseURL: "https://api.ainative.studio",
    RetryConfig: &ainative.RetryConfig{
        MaxRetries:      5,
        InitialDelay:    100 * time.Millisecond,
        MaxDelay:        10 * time.Second,
        BackoffMultiplier: 2.0,
        Jitter:         true,
    },
})

πŸ“Š Performance

The Go SDK is optimized for high-performance operations:

  • Connection Pooling: Reuses HTTP connections for efficiency
  • Concurrent Operations: Thread-safe client with goroutine support
  • Memory Efficient: Minimal allocations with object pooling
  • Fast JSON: Optimized JSON marshaling/unmarshaling
  • Benchmarks: 50%+ faster than Python SDK, 30%+ faster than TypeScript

πŸ§ͺ Testing

# Run all tests
go test ./...

# Run tests with coverage
go test -cover ./...

# Run benchmarks
go test -bench=. ./...

# Run integration tests (requires API key)
AINATIVE_API_KEY=your-key go test -tags=integration ./...

πŸ“– Examples

See the examples/ directory for comprehensive examples:

  • Basic Operations: Project management, vector search
  • Advanced Workflows: Agent swarm orchestration, memory management
  • Performance: Concurrent operations, batch processing
  • Observability: Metrics collection, distributed tracing

🀝 Contributing

We welcome contributions! See CONTRIBUTING.md for development setup, style conventions, and the pull request process. Quick version:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-feature
  3. Make changes and add tests
  4. Run tests: go test ./...
  5. Submit a pull request

πŸ“„ License

Licensed under the MIT License. See LICENSE for details.

πŸ”— Links

About

AINative Go SDK

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages