Log FTS index build failures at WARNING
This commit is contained in:
parent
2fd025951c
commit
b61134b747
3 changed files with 36 additions and 2 deletions
|
|
@ -1,6 +1,10 @@
|
|||
# Changelog
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- A failed FTS index build is logged at `WARNING` instead of `DEBUG`, so silent full-text search degradation is visible.
|
||||
|
||||
### Changed
|
||||
|
||||
- A bare `${VAR}` in YAML config now raises `MissingEnvVarError` when the variable is set but empty, matching the unset case. Use `${VAR:-default}` to allow an empty/absent value.
|
||||
|
|
|
|||
|
|
@ -33,8 +33,7 @@ class ChunkRepository:
|
|||
replace=True,
|
||||
)
|
||||
except Exception as e:
|
||||
# Log the error but don't fail - FTS might already exist
|
||||
logger.debug(f"FTS index creation skipped: {e}")
|
||||
logger.warning(f"FTS index build failed; full-text search degraded: {e}")
|
||||
|
||||
def _contextualize_content(self, chunk: Chunk) -> str:
|
||||
"""Generate contextualized content for FTS by prepending headings."""
|
||||
|
|
|
|||
|
|
@ -510,3 +510,34 @@ async def test_chunk_content_fts_without_headings(temp_db_path):
|
|||
# Both should be the same when no headings
|
||||
assert record["content"] == "Plain content without headings."
|
||||
assert record["content_fts"] == "Plain content without headings."
|
||||
|
||||
|
||||
async def test_ensure_fts_index_warns_on_failure(temp_db_path):
|
||||
"""A failed FTS index build is surfaced at WARNING, not swallowed silently."""
|
||||
import logging
|
||||
|
||||
from haiku.rag.store.repositories import chunk as chunk_module
|
||||
|
||||
async with HaikuRAG(db_path=temp_db_path, config=Config, create=True) as client:
|
||||
repo = client.chunk_repository
|
||||
|
||||
async def _boom(*_args, **_kwargs):
|
||||
raise RuntimeError("index build failed")
|
||||
|
||||
repo.store.chunks_table.create_index = _boom
|
||||
|
||||
records: list[logging.LogRecord] = []
|
||||
|
||||
class _Capture(logging.Handler):
|
||||
def emit(self, record: logging.LogRecord) -> None:
|
||||
records.append(record)
|
||||
|
||||
handler = _Capture(level=logging.WARNING)
|
||||
chunk_module.logger.addHandler(handler)
|
||||
try:
|
||||
await repo._ensure_fts_index()
|
||||
finally:
|
||||
chunk_module.logger.removeHandler(handler)
|
||||
|
||||
assert [r for r in records if r.levelno == logging.WARNING]
|
||||
assert any("index build failed" in r.getMessage() for r in records)
|
||||
|
|
|
|||
Loading…
Reference in a new issue