From c157c37cde509648d88ec45379077fc51d357d80 Mon Sep 17 00:00:00 2001 From: Ryan Chen Date: Fri, 24 Apr 2026 08:49:00 -0400 Subject: [PATCH] Handle missing pgvector tables on first run _get_collection_id now catches the UndefinedTable error that occurs before the first index operation creates the langchain tables. Co-Authored-By: Claude Opus 4.6 --- blueprints/rag/logic.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/blueprints/rag/logic.py b/blueprints/rag/logic.py index 7487411..f281519 100644 --- a/blueprints/rag/logic.py +++ b/blueprints/rag/logic.py @@ -59,13 +59,17 @@ text_splitter = RecursiveCharacterTextSplitter( def _get_collection_id(): """Get the UUID of our collection from the langchain_pg_collection table.""" engine = _get_engine() - with engine.connect() as conn: - result = conn.execute( - text("SELECT uuid FROM langchain_pg_collection WHERE name = :name"), - {"name": "simba_docs"}, - ) - row = result.fetchone() - return row[0] if row else None + try: + with engine.connect() as conn: + result = conn.execute( + text("SELECT uuid FROM langchain_pg_collection WHERE name = :name"), + {"name": "simba_docs"}, + ) + row = result.fetchone() + return row[0] if row else None + except Exception: + # Table doesn't exist yet (first run before any indexing) + return None def date_to_epoch(date_str: str) -> float: