From d13a73cf1ad0db7d8e42634c01a1e6376d6202cd Mon Sep 17 00:00:00 2001 From: "Lumberbot (aka Jack)" <39504233+meeseeksmachine@users.noreply.github.com> Date: Tue, 23 Apr 2024 00:10:17 +0200 Subject: [PATCH] Backport PR #735: Catch embedding model validation errors on extension init (#740) Co-authored-by: david qiu --- .../jupyter_ai/chat_handlers/learn.py | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/jupyter-ai/jupyter_ai/chat_handlers/learn.py b/packages/jupyter-ai/jupyter_ai/chat_handlers/learn.py index 5ae7d0493..4ee28d3a4 100644 --- a/packages/jupyter-ai/jupyter_ai/chat_handlers/learn.py +++ b/packages/jupyter-ai/jupyter_ai/chat_handlers/learn.py @@ -67,17 +67,23 @@ def __init__(self, *args, **kwargs): def _load(self): """Loads the vector store.""" - embeddings = self.get_embedding_model() - if not embeddings: + if self.index is not None: return - if self.index is None: - try: - self.index = FAISS.load_local( - INDEX_SAVE_DIR, embeddings, index_name=self.index_name - ) - self.load_metadata() - except Exception as e: - self.log.error("Could not load vector index from disk.") + + try: + embeddings = self.get_embedding_model() + if not embeddings: + return + + self.index = FAISS.load_local( + INDEX_SAVE_DIR, embeddings, index_name=self.index_name + ) + self.load_metadata() + except Exception as e: + self.log.error( + "Could not load vector index from disk. Full exception details printed below." + ) + self.log.error(e) async def process_message(self, message: HumanChatMessage): # If no embedding provider has been selected