Expand description
§sevensense-embedding
Embedding bounded context for 7sense bioacoustics platform.
This crate provides Perch 2.0 ONNX integration for generating 1536-dimensional embeddings from preprocessed audio segments. It handles model loading, inference, normalization, and quantization for efficient storage and retrieval.
§Architecture
The crate follows Domain-Driven Design (DDD) principles:
- Domain Layer: Core entities (
Embedding,EmbeddingModel) and repository traits - Application Layer: Services for embedding generation and batch processing
- Infrastructure Layer: ONNX Runtime integration and model management
§Usage
ⓘ
use sevensense_embedding::{
EmbeddingService, ModelManager, ModelConfig,
domain::Embedding,
};
// Initialize model manager
let config = ModelConfig::default();
let model_manager = ModelManager::new(config)?;
// Create embedding service
let service = EmbeddingService::new(model_manager, 8);
// Generate embedding from spectrogram
let embedding = service.embed_segment(&spectrogram).await?;§Features
- Perch 2.0 Integration: Full support for EfficientNet-B3 bioacoustic embeddings
- Batch Processing: Efficient batch inference with configurable batch sizes
- Model Hot-Swap: Update models without service restart
- Quantization: F16 and INT8 quantization for reduced storage
- Validation: Comprehensive embedding validation (NaN detection, dimension checks)
Re-exports§
pub use domain::entities::Embedding;pub use domain::entities::EmbeddingId;pub use domain::entities::EmbeddingModel;pub use domain::entities::EmbeddingMetadata;pub use domain::entities::StorageTier;pub use domain::entities::ModelVersion;pub use domain::entities::InputSpecification;pub use domain::repository::EmbeddingRepository;pub use application::services::EmbeddingService;pub use infrastructure::model_manager::ModelManager;pub use infrastructure::model_manager::ModelConfig;pub use infrastructure::onnx_inference::OnnxInference;
Modules§
- application
- Application layer for embedding bounded context.
- domain
- Domain layer for embedding bounded context.
- infrastructure
- Infrastructure layer for embedding bounded context.
- normalization
- Normalization utilities for embedding vectors.
- quantization
- Quantization utilities for embedding storage optimization.
Enums§
- Embedding
Error - Unified error type for embedding operations
Constants§
- EMBEDDING_
DIM - Embedding dimension for Perch 2.0 model
- MEL_
BINS - Mel spectrogram bins for Perch 2.0
- MEL_
FRAMES - Mel spectrogram frames for Perch 2.0
- TARGET_
SAMPLE_ RATE - Target sample rate for Perch 2.0 (32kHz)
- TARGET_
WINDOW_ SAMPLES - Target window samples (160,000 = 5s at 32kHz)
- TARGET_
WINDOW_ SECONDS - Target window duration in seconds (5s)
- VERSION
- Crate version information
Type Aliases§
- Result
- Common result type for embedding operations