diff --git a/semantic_router/index/local.py b/semantic_router/index/local.py index 8f674c62a58820b1cfa6e1b55aa19eb766b7074c..76d44d82b50108136f5a6776621d75aca428c451 100644 --- a/semantic_router/index/local.py +++ b/semantic_router/index/local.py @@ -52,7 +52,10 @@ class LocalIndex(BaseIndex): for route, utterances in routes_to_delete.items(): # TODO JB: we should be able to vectorize this? for utterance in utterances: - mask &= ~((route_utterances[:, 0] == route) & (route_utterances[:, 1] == utterance)) + mask &= ~( + (route_utterances[:, 0] == route) + & (route_utterances[:, 1] == utterance) + ) # apply the mask to index, routes, and utterances self.index = self.index[mask] self.routes = self.routes[mask] diff --git a/semantic_router/index/postgres.py b/semantic_router/index/postgres.py index 4cdd94f39f613c0e3b8988ea81e950dc37af1006..6d445f2bedabeba63a24712db955d6d4757647a2 100644 --- a/semantic_router/index/postgres.py +++ b/semantic_router/index/postgres.py @@ -140,8 +140,10 @@ class PostgresIndex(BaseIndex): try: import psycopg2 except ImportError: - raise ImportError("Please install psycopg2 to use PostgresIndex. " - "You can install it with: `pip install 'semantic-router[postgres]'`") + raise ImportError( + "Please install psycopg2 to use PostgresIndex. " + "You can install it with: `pip install 'semantic-router[postgres]'`" + ) if connection_string: self.connection_string = connection_string else: diff --git a/tests/unit/test_sync.py b/tests/unit/test_sync.py index 3a640f0246b2cadb99db668c74dd33bd89ff22f4..2f19236b5e8063f1768e4f26eb43cc9f480db377 100644 --- a/tests/unit/test_sync.py +++ b/tests/unit/test_sync.py @@ -103,6 +103,7 @@ routes: - how are things going? """ + # not all indexes support metadata, so we map the feature here INCLUDE_METADATA_MAP = { PineconeIndex: True, @@ -111,9 +112,12 @@ INCLUDE_METADATA_MAP = { QdrantIndex: False, PostgresIndex: False, } + + def include_metadata(index_cls): return INCLUDE_METADATA_MAP.get(index_cls, False) + MERGE_FORCE_LOCAL_RESULT_WITH_METADATA = [ Utterance(route="Route 1", utterance="Hello"), Utterance(route="Route 1", utterance="Hi"), @@ -132,6 +136,7 @@ MERGE_FORCE_LOCAL_RESULT_WITHOUT_METADATA = [ Utterance(route="Route 2", utterance="Hi"), ] + @pytest.fixture def base_encoder(): return DenseEncoder(name="test-encoder", score_threshold=0.5) @@ -367,9 +372,7 @@ class TestSemanticRouter: local_utterances = route_layer.index.get_utterances() # we sort to ensure order is the same # TODO JB: there is a bug here where if we include_metadata=True it fails - local_utterances.sort( - key=lambda x: x.to_str(include_metadata=False) - ) + local_utterances.sort(key=lambda x: x.to_str(include_metadata=False)) assert local_utterances == [ Utterance(route="Route 1", utterance="Hello"), Utterance(route="Route 1", utterance="Hi"),