Iris Examples
Examples
Section titled “Examples”These examples demonstrate production-ready patterns for building AI-powered applications with Iris. Each example includes complete, runnable code with proper error handling, multiple provider options, and real-world use cases.
What Makes These Examples Different
Section titled “What Makes These Examples Different”Unlike toy demos, these examples show:
- Complete implementations — not snippets, but full working code
- Production patterns — error handling, retries, timeouts, and graceful degradation
- Provider flexibility — each example works with multiple providers
- Real use cases — patterns extracted from production applications
Example Categories
Section titled “Example Categories”Retrieval & Search
Section titled “Retrieval & Search”Build intelligent search and retrieval systems that combine embeddings, vector databases, and language models.
Agents & Tools
Section titled “Agents & Tools”Create autonomous agents that can reason, plan, and execute multi-step workflows using external tools.
Multimodal Applications
Section titled “Multimodal Applications”Process images, documents, and mixed media alongside text for richer AI interactions.
Streaming & Real-Time
Section titled “Streaming & Real-Time”Build responsive applications with streaming responses and real-time processing.
Running the Examples
Section titled “Running the Examples”Each example is a complete Go program. To run any example:
# Clone the examples repositorygit clone https://github.com/petal-labs/iris-examplescd iris-examples
# Set up your API keysiris keys set openaiiris keys set anthropiciris keys set voyageai
# Run an examplego run rag-pipeline/main.goProvider Recommendations
Section titled “Provider Recommendations”Different examples work best with different providers:
| Example | Recommended Provider | Alternatives |
|---|---|---|
| RAG Pipeline | OpenAI + Voyage AI | Anthropic + Gemini |
| Batch Embeddings | Voyage AI | OpenAI, Gemini |
| Agent With Tools | Claude claude-sonnet-4-20250514 | GPT-4o, Gemini Pro |
| Multimodal QA | GPT-4o | Claude claude-sonnet-4-20250514, Gemini Pro |
| Streaming Summaries | GPT-4o | Claude, Gemini |
Example Structure
Section titled “Example Structure”Each example follows a consistent structure:
example-name/├── main.go # Entry point with CLI flags├── config.go # Configuration and environment setup├── types.go # Domain types and interfaces├── tools.go # Tool definitions (if applicable)└── README.md # Usage instructions and requirementsCommon Patterns
Section titled “Common Patterns”Provider Initialization
Section titled “Provider Initialization”All examples use the keystore pattern for secure API key management:
// Primary provider from keystoreprovider, err := openai.NewFromKeystore()if err != nil { // Fall back to environment variable provider, err = openai.NewFromEnv() if err != nil { log.Fatal("No API key found. Run: iris keys set openai") }}Error Handling
Section titled “Error Handling”Examples demonstrate proper error handling with typed errors:
resp, err := client.Chat(model).User(prompt).GetResponse(ctx)if err != nil { var apiErr *core.APIError if errors.As(err, &apiErr) { switch apiErr.StatusCode { case 429: // Handle rate limiting with exponential backoff time.Sleep(calculateBackoff(attempt)) continue case 500, 503: // Retry on server errors continue default: return fmt.Errorf("API error: %w", err) } } return err}Context and Cancellation
Section titled “Context and Cancellation”Examples use context for timeouts and cancellation:
// Create context with timeoutctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)defer cancel()
// Pass context to all operationsresp, err := client.Chat(model).User(prompt).GetResponse(ctx)Retry Policies
Section titled “Retry Policies”Examples show how to configure retry behavior:
client := core.NewClient(provider, core.WithRetryPolicy(&core.RetryPolicy{ MaxRetries: 3, InitialInterval: 1 * time.Second, MaxInterval: 30 * time.Second, BackoffMultiplier: 2.0, RetryOn: []int{429, 500, 503}, }),)