From eb5c7383edf1f39bbaf5f5969ea6daa72e83025e Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Mon, 4 May 2026 17:43:16 -0700 Subject: [PATCH] fix(search): defensive _get_bm25 guard, null-safe text_snippet --- app/api/search.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/api/search.py b/app/api/search.py index bb4563f..e6d7ce0 100644 --- a/app/api/search.py +++ b/app/api/search.py @@ -34,8 +34,11 @@ class SearchResult(BaseModel): def _get_bm25() -> BM25Index: - from app.main import _bm25 - return _bm25 + import app.main as _main + bm25 = getattr(_main, "_bm25", None) + if bm25 is None: + raise RuntimeError("BM25 index not initialised — app.main not loaded") + return bm25 def _get_db_path() -> str: @@ -57,7 +60,7 @@ def search( chunk_id=h.chunk_id, doc_id=h.doc_id, page_number=h.page_number, - text_snippet=h.text[:300], + text_snippet=(h.text or "")[:300], bm25_score=h.score, ) for h in hits