Skip to content
Snippets Groups Projects
Commit 1d777b0f authored by James Briggs's avatar James Briggs
Browse files

fix: init index logic

parent 0c734168
No related branches found
No related tags found
No related merge requests found
......@@ -236,7 +236,12 @@ class PineconeIndex(BaseIndex):
else:
# if the index doesn't exist and we don't have the dimensions
# we return None
logger.warning("Index could not be initialized.")
logger.warning(
"Index could not be initialized. Init parameters: "
f"{self.index_name=}, {self.dimensions=}, {self.metric=}, "
f"{self.cloud=}, {self.region=}, {self.host=}, {self.namespace=}, "
f"{force_create=}"
)
index = None
if index is not None:
self.host = self.client.describe_index(self.index_name)["host"]
......@@ -272,7 +277,12 @@ class PineconeIndex(BaseIndex):
else:
# if the index doesn't exist and we don't have the dimensions
# we raise warning
logger.warning("Index could not be initialized.")
logger.warning(
"Index could not be initialized. Init parameters: "
f"{self.index_name=}, {self.dimensions=}, {self.metric=}, "
f"{self.cloud=}, {self.region=}, {self.host=}, {self.namespace=}, "
f"{force_create=}"
)
self.host = index_stats["host"] if index_stats else ""
def _batch_upsert(self, batch: List[Dict]):
......
......@@ -351,6 +351,8 @@ class BaseRouter(BaseModel):
for route in self.routes:
if route.score_threshold is None:
route.score_threshold = self.score_threshold
# initialize index
self._init_index_state()
def _get_index(self, index: Optional[BaseIndex]) -> BaseIndex:
if index is None:
......@@ -370,6 +372,7 @@ class BaseRouter(BaseModel):
def _init_index_state(self):
"""Initializes an index (where required) and runs auto_sync if active."""
print("JBTEMP _init_index_state")
# initialize index now, check if we need dimensions
if self.index.dimensions is None:
dims = len(self.encoder(["test"])[0])
......@@ -862,6 +865,7 @@ class BaseRouter(BaseModel):
The name must exist within the local SemanticRouter, if not a
KeyError will be raised.
"""
# TODO JB: should modify update to take a Route object
current_local_hash = self._get_hash()
current_remote_hash = self.index._read_hash()
if current_remote_hash.value == "":
......
......@@ -62,9 +62,6 @@ class HybridRouter(BaseRouter):
and self.routes
):
self.sparse_encoder.fit(self.routes)
# run initialize index now if auto sync is active
if self.auto_sync:
self._init_index_state()
def _set_score_threshold(self):
"""Set the score threshold for the HybridRouter. Unlike the base router the
......
......@@ -32,9 +32,6 @@ class SemanticRouter(BaseRouter):
aggregation=aggregation,
auto_sync=auto_sync,
)
# run initialize index now if auto sync is active
if self.auto_sync:
self._init_index_state()
def _encode(self, text: list[str]) -> Any:
"""Given some text, encode it."""
......
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