pub struct EmbeddingService { /* private fields */ }Expand description
High-level embedding service with comprehensive provider management
The embedding service provides a unified interface for embedding generation with advanced features like automatic batching, retry logic, parallel processing, and comprehensive error handling.
§Features
- Provider Abstraction: Work with any embedding provider through a common interface
- Intelligent Batching: Automatically batches requests for optimal performance
- Retry Logic: Configurable retry with exponential backoff for transient failures
- Parallel Processing: Concurrent processing for improved throughput
- Order Preservation: Maintains document order in batch operations
- Metadata Propagation: Preserves metadata through processing pipeline
§Example
use rrag::prelude::*;
use std::sync::Arc;
let provider = Arc::new(OpenAIEmbeddingProvider::new("api-key"));
let service = EmbeddingService::with_config(
provider,
EmbeddingConfig {
batch_size: 100,
parallel_processing: true,
max_retries: 3,
retry_delay_ms: 1000,
}
);
// Process multiple documents efficiently
let documents = vec![
Document::new("First document"),
Document::new("Second document"),
];
let embeddings = service.embed_documents(&documents).await?;
println!("Generated {} embeddings", embeddings.len());§Configuration Options
batch_size: Number of items to process in each batch (default: 50)parallel_processing: Whether to enable concurrent batch processing (default: true)max_retries: Maximum retry attempts for failed requests (default: 3)retry_delay_ms: Initial delay between retries, increases exponentially (default: 1000ms)
Implementations§
Source§impl EmbeddingService
impl EmbeddingService
Sourcepub fn new(provider: Arc<dyn EmbeddingProvider>) -> Self
pub fn new(provider: Arc<dyn EmbeddingProvider>) -> Self
Create embedding service with provider
Sourcepub fn with_config(
provider: Arc<dyn EmbeddingProvider>,
config: EmbeddingConfig,
) -> Self
pub fn with_config( provider: Arc<dyn EmbeddingProvider>, config: EmbeddingConfig, ) -> Self
Create service with configuration
Sourcepub async fn embed_document(&self, document: &Document) -> RragResult<Embedding>
pub async fn embed_document(&self, document: &Document) -> RragResult<Embedding>
Embed a single document
Sourcepub async fn embed_documents(
&self,
documents: &[Document],
) -> RragResult<Vec<Embedding>>
pub async fn embed_documents( &self, documents: &[Document], ) -> RragResult<Vec<Embedding>>
Embed multiple documents with batching
Sourcepub async fn embed_chunks(
&self,
chunks: &[DocumentChunk],
) -> RragResult<Vec<Embedding>>
pub async fn embed_chunks( &self, chunks: &[DocumentChunk], ) -> RragResult<Vec<Embedding>>
Embed document chunks efficiently
Sourcepub fn provider_info(&self) -> ProviderInfo
pub fn provider_info(&self) -> ProviderInfo
Get provider information
Auto Trait Implementations§
impl Freeze for EmbeddingService
impl !RefUnwindSafe for EmbeddingService
impl Send for EmbeddingService
impl Sync for EmbeddingService
impl Unpin for EmbeddingService
impl !UnwindSafe for EmbeddingService
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more