Skip to content
Snippets Groups Projects
Commit 78a4bef1 authored by Vits's avatar Vits
Browse files

Fixing PyTest errors

parent 09c3a74c
No related branches found
No related tags found
No related merge requests found
...@@ -204,27 +204,6 @@ class PineconeIndex(BaseIndex): ...@@ -204,27 +204,6 @@ class PineconeIndex(BaseIndex):
def _sync_index(self, local_routes: dict): def _sync_index(self, local_routes: dict):
remote_routes = self.get_routes() remote_routes = self.get_routes()
if not local_routes["routes"]:
if self.sync != "remote":
raise ValueError(
"Local routes must be provided to sync the index if the sync setting is not 'remote'."
)
else:
if not remote_routes:
raise ValueError("No routes found in the index.")
if (
(self.sync in ["remote", "merge-force-remote"] and not remote_routes)
or (
self.sync in ["error", "local", "merge-force-local"]
and not local_routes["routes"]
)
or (
self.sync == "merge"
and not remote_routes
and not local_routes["routes"]
)
):
raise ValueError("No routes found in the index.")
remote_dict: dict = {route: set() for route, _ in remote_routes} remote_dict: dict = {route: set() for route, _ in remote_routes}
for route, utterance in remote_routes: for route, utterance in remote_routes:
...@@ -244,13 +223,17 @@ class PineconeIndex(BaseIndex): ...@@ -244,13 +223,17 @@ class PineconeIndex(BaseIndex):
local_utterances = local_dict.get(route, set()) local_utterances = local_dict.get(route, set())
remote_utterances = remote_dict.get(route, set()) remote_utterances = remote_dict.get(route, set())
if not local_utterances and not remote_utterances:
continue
if self.sync == "error": if self.sync == "error":
if local_utterances != remote_utterances: if local_utterances != remote_utterances:
raise ValueError( raise ValueError(
f"Synchronization error: Differences found in route '{route}'" f"Synchronization error: Differences found in route '{route}'"
) )
utterances_to_include: set = set() utterances_to_include: set = set()
layer_routes[route] = list(local_utterances) if local_utterances:
layer_routes[route] = list(local_utterances)
elif self.sync == "remote": elif self.sync == "remote":
utterances_to_include = set() utterances_to_include = set()
if remote_utterances: if remote_utterances:
...@@ -264,7 +247,8 @@ class PineconeIndex(BaseIndex): ...@@ -264,7 +247,8 @@ class PineconeIndex(BaseIndex):
if utterance not in local_utterances if utterance not in local_utterances
] ]
) )
layer_routes[route] = list(local_utterances) if local_utterances:
layer_routes[route] = list(local_utterances)
elif self.sync == "merge-force-remote": elif self.sync == "merge-force-remote":
if route in local_dict and route not in remote_dict: if route in local_dict and route not in remote_dict:
utterances_to_include = local_utterances utterances_to_include = local_utterances
...@@ -292,7 +276,8 @@ class PineconeIndex(BaseIndex): ...@@ -292,7 +276,8 @@ class PineconeIndex(BaseIndex):
layer_routes[route] = list(remote_utterances) layer_routes[route] = list(remote_utterances)
elif self.sync == "merge": elif self.sync == "merge":
utterances_to_include = local_utterances - remote_utterances utterances_to_include = local_utterances - remote_utterances
layer_routes[route] = list(remote_utterances.union(local_utterances)) if local_utterances or remote_utterances:
layer_routes[route] = list(remote_utterances.union(local_utterances))
else: else:
raise ValueError("Invalid sync mode specified") raise ValueError("Invalid sync mode specified")
......
...@@ -220,7 +220,7 @@ class RouteLayer: ...@@ -220,7 +220,7 @@ class RouteLayer:
if len(self.routes) > 0: if len(self.routes) > 0:
# initialize index now # initialize index now
self._add_routes(routes=self.routes) self._add_routes(routes=self.routes)
elif self.index.sync in ["merge", "remote", "merge-force-remote"]: elif self.index.sync:
dummy_embedding = self.encoder(["dummy"]) dummy_embedding = self.encoder(["dummy"])
layer_routes = self.index._add_and_sync( layer_routes = self.index._add_and_sync(
...@@ -229,10 +229,6 @@ class RouteLayer: ...@@ -229,10 +229,6 @@ class RouteLayer:
utterances=[], utterances=[],
) )
self._set_layer_routes(layer_routes) self._set_layer_routes(layer_routes)
else:
raise ValueError(
"No routes provided for RouteLayer. Please provide routes or set sync to 'remote' if you want to use only remote routes."
)
def check_for_matching_routes(self, top_class: str) -> Optional[Route]: def check_for_matching_routes(self, top_class: str) -> Optional[Route]:
matching_routes = [route for route in self.routes if route.name == top_class] matching_routes = [route for route in self.routes if route.name == top_class]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment