fix(search): defensive _get_bm25 guard, null-safe text_snippet
This commit is contained in:
parent
6869f32392
commit
eb5c7383ed
1 changed files with 6 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue