fix(search): defensive _get_bm25 guard, null-safe text_snippet

This commit is contained in:
pyr0ball 2026-05-04 17:43:16 -07:00
parent 6869f32392
commit eb5c7383ed

View file

@ -34,8 +34,11 @@ class SearchResult(BaseModel):
def _get_bm25() -> BM25Index: def _get_bm25() -> BM25Index:
from app.main import _bm25 import app.main as _main
return _bm25 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: def _get_db_path() -> str:
@ -57,7 +60,7 @@ def search(
chunk_id=h.chunk_id, chunk_id=h.chunk_id,
doc_id=h.doc_id, doc_id=h.doc_id,
page_number=h.page_number, page_number=h.page_number,
text_snippet=h.text[:300], text_snippet=(h.text or "")[:300],
bm25_score=h.score, bm25_score=h.score,
) )
for h in hits for h in hits