Skip to content

Commit a7c43b6

Browse files
committed
Refactor embedder implementation for Linux platforms to use trait objects
This change modifies the semantic search client to use Box<dyn TextEmbedderTrait> on Linux platforms instead of directly using CandleTextEmbedder. This provides more flexibility and consistency with the implementation on macOS and Windows, allowing for better extensibility and polymorphic behavior across all platforms.
1 parent 0991116 commit a7c43b6

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

crates/semantic_search_client/src/client/embedder_factory.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ pub fn create_embedder(embedding_type: EmbeddingType) -> Result<Box<dyn TextEmbe
4141
///
4242
/// A text embedder instance
4343
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
44-
pub fn create_embedder(embedding_type: EmbeddingType) -> Result<CandleTextEmbedder> {
45-
let embedder = match embedding_type {
46-
EmbeddingType::Candle => CandleTextEmbedder::new()?,
44+
pub fn create_embedder(embedding_type: EmbeddingType) -> Result<Box<dyn TextEmbedderTrait>> {
45+
let embedder: Box<dyn TextEmbedderTrait> = match embedding_type {
46+
EmbeddingType::Candle => Box::new(CandleTextEmbedder::new()?),
4747
#[cfg(test)]
48-
EmbeddingType::Mock => MockTextEmbedder::new(384),
48+
EmbeddingType::Mock => Box::new(MockTextEmbedder::new(384)),
4949
};
5050

5151
Ok(embedder)

crates/semantic_search_client/src/client/implementation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub struct SemanticSearchClient {
7171
embedder: Box<dyn TextEmbedderTrait>,
7272
/// Text embedder for generating embeddings (Linux only)
7373
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
74-
embedder: CandleTextEmbedder,
74+
embedder: Box<dyn TextEmbedderTrait>,
7575
}
7676
impl SemanticSearchClient {
7777
/// Create a new semantic search client

0 commit comments

Comments
 (0)