diff --git a/semantic_router/hybrid_layer.py b/semantic_router/hybrid_layer.py index a5e6bd4b5a5fa8b7c381a9fafeef124ee9b560d4..853fb33208929903c61152efd31c098e6ba868ee 100644 --- a/semantic_router/hybrid_layer.py +++ b/semantic_router/hybrid_layer.py @@ -36,7 +36,7 @@ class HybridRouteLayer: else: self.score_threshold = 0.82 # if routes list has been passed, we initialize index now - if isinstance(sparse_encoder, TfidfEncoder): + if isinstance(self.sparse_encoder, TfidfEncoder) and hasattr(self.sparse_encoder, 'fit'): self.sparse_encoder.fit(routes) if routes: # initialize index now @@ -54,7 +54,7 @@ class HybridRouteLayer: return None def add(self, route: Route): - if isinstance(self.sparse_encoder, TfidfEncoder): + if isinstance(self.sparse_encoder, TfidfEncoder) and hasattr(self.sparse_encoder, 'fit'): self.sparse_encoder.fit(self.routes + [route]) self.sparse_index = None for r in self.routes: