rgenai - Rust AWS Bedrock Client Library
RGenAi is a comprehensive Rust library for AWS Bedrock that provides easy-to-use clients for text generation, image generation, embeddings, and vector storage. Built with performance, type safety, and developer experience in mind.
🚀 Features
🤖 AI Model Support
- Text Generation: Support for 20+ models including Amazon Titan, Anthropic Claude, Meta Llama, Mistral, AI21, and Cohere
- Image Generation: Amazon Titan Image Generator and Stability AI Stable Diffusion XL
- Embeddings: Amazon Titan Embed and Cohere Embed models
- Streaming: Real-time text generation with async streams
🗄️ Vector Storage Backends
- PostgreSQL with pgvector extension
- Pinecone vector database
- Upstash vector service
- Unified storage interface with automatic client management
🔧 Advanced Features
- RAG (Retrieval Augmented Generation): Built-in context retrieval and generation
- Semantic Search: Vector similarity search across storage backends
- Batch Operations: Efficient bulk insert/update/delete operations
- Beautiful Logging: Structured logging with emojis and colors
- Configuration Management: Environment-based configuration with validation
⚡ Performance & Reliability
- Async/await throughout with Tokio
- Connection pooling for database backends
- Comprehensive error handling and recovery
- Type-safe API with Rust's type system
- Memory efficient streaming for large responses
📦 Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
# Optional features
= { = "0.1.0", = ["postgres", "pinecone", "upstash"] }
Feature Flags
postgres- Enable PostgreSQL with pgvector supportpinecone- Enable Pinecone vector database supportupstash- Enable Upstash vector service support
🏁 Quick Start
Basic Text Generation
use ;
async
Streaming Text Generation
use StreamExt;
use ;
async
Image Generation
use ;
use fs;
async
Vector Storage and RAG
use ;
use HashMap;
async
🎛️ Configuration
Environment Variables
# AWS Configuration
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
# PostgreSQL Configuration
USE_PSQL=true
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_USERNAME=postgres
POSTGRES_PASSWORD=password
POSTGRES_DATABASE=vectordb
# Pinecone Configuration
USE_PINECONE=true
PINECONE_API_KEY=your_api_key
PINECONE_ENVIRONMENT=us-east-1-aws
PINECONE_INDEX_NAME=your_index
# Upstash Configuration
USE_UPSTASH=true
UPSTASH_URL=https://your-endpoint.upstash.io
UPSTASH_TOKEN=your_token
# Application Configuration
PORT=8080
Programmatic Configuration
use ;
let bedrock_config = new
.with_region
.with_credentials;
let storage_config = new
.with_port
.with_postgres
.with_pinecone;
🤖 Supported Models
Text Generation Models
| Provider | Model ID | Model Name |
|---|---|---|
| Amazon | amazon.titan-text-express-v1 |
Titan Text Express |
| Amazon | amazon.titan-text-lite-v1 |
Titan Text Lite |
| Amazon | amazon.titan-text-premier-v1:0 |
Titan Text Premier |
| Anthropic | anthropic.claude-3-5-sonnet-20241022-v2:0 |
Claude 3.5 Sonnet |
| Anthropic | anthropic.claude-3-sonnet-20240229-v1:0 |
Claude 3 Sonnet |
| Anthropic | anthropic.claude-3-haiku-20240307-v1:0 |
Claude 3 Haiku |
| Anthropic | anthropic.claude-3-opus-20240229-v1:0 |
Claude 3 Opus |
| Meta | meta.llama3-8b-instruct-v1:0 |
Llama 3 8B Instruct |
| Meta | meta.llama3-70b-instruct-v1:0 |
Llama 3 70B Instruct |
| Meta | meta.llama3-1-405b-instruct-v1:0 |
Llama 3.1 405B Instruct |
| Mistral | mistral.mistral-7b-instruct-v0:2 |
Mistral 7B Instruct |
| Mistral | mistral.mixtral-8x7b-instruct-v0:1 |
Mixtral 8x7B Instruct |
| AI21 | ai21.jamba-instruct-v1:0 |
Jamba Instruct |
| Cohere | cohere.command-r-plus-v1:0 |
Command R+ |
Image Generation Models
| Provider | Model ID | Model Name |
|---|---|---|
| Amazon | amazon.titan-image-generator-v1 |
Titan Image Generator |
| Amazon | amazon.titan-image-generator-v2:0 |
Titan Image Generator V2 |
| Stability AI | stability.stable-diffusion-xl-v1:0 |
Stable Diffusion XL |
Embedding Models
| Provider | Model ID | Model Name |
|---|---|---|
| Amazon | amazon.titan-embed-text-v2:0 |
Titan Text Embeddings V2 |
| Cohere | cohere.embed-english-v3 |
Cohere English Embeddings |
📊 Vector Storage
PostgreSQL with pgvector
use ;
let config = new
.with_postgres;
let storage = new.await?;
// Insert vectors
let insert = VectorInsert ;
let result = storage.insert.await?;
Pinecone
use ;
let config = new
.with_pinecone;
let storage = new.await?;
Upstash
use ;
let config = new
.with_upstash;
let storage = new.await?;
🔍 Semantic Search
use VectorSearch;
let search_query = VectorSearch ;
let results = storage.search.await?;
for result in results.results
📝 Logging
rgenai includes a beautiful, structured logging system:
use ;
// Initialize with custom configuration
let logger_config = new
.with_level
.with_colors
.with_file_output;
init_with_config?;
// Use throughout your application
info!;
debug!;
error!;
🛠️ Error Handling
rgenai provides comprehensive error handling:
use ;
match client.text.generate.await
📚 Examples
Check out the examples/ directory for complete examples:
basic_text_generation.rs- Simple text generationstreaming_chat.rs- Real-time streaming responsesimage_generation.rs- Generate and save imagesrag_system.rs- Complete RAG implementationvector_operations.rs- Vector storage operationsmulti_model_comparison.rs- Compare responses across models
🏗️ Architecture
rgenai/
├── src/
│ ├── bedrock/ # AWS Bedrock clients
│ │ ├── text_client.rs
│ │ ├── image_client.rs
│ │ └── vector_client.rs
│ ├── storage/ # Vector storage backends
│ │ ├── postgres.rs
│ │ ├── pinecone.rs
│ │ └── upstash.rs
│ ├── models/ # Data structures
│ ├── config/ # Configuration management
│ ├── logger/ # Logging system
│ └── error/ # Error handling
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
# Clone the repository
# Install dependencies
# Run tests
# Run examples
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- AWS Bedrock team for the excellent AI model APIs
- The Rust community for amazing crates and tools
- Contributors to pgvector, Pinecone, and Upstash for vector storage solutions
📞 Support
- Documentation: docs.rs/rgenai
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Created by DevMaan707 - Building the future of AI applications in Rust 🦀