diff --git a/src/fabledassistant/services/notes.py b/src/fabledassistant/services/notes.py index b9e65d8..d5a4556 100644 --- a/src/fabledassistant/services/notes.py +++ b/src/fabledassistant/services/notes.py @@ -22,6 +22,17 @@ def _normalize_tags(tags: list[str]) -> list[str]: return out +# Type-nouns the LLM tends to include in search queries. Treating them as +# required ILIKE terms drops literal-title matches; we strip them server-side +# and let the `type` / `project` parameters scope results instead. +_SEARCH_TYPE_NOUNS = {"task", "tasks", "note", "notes", "project", "projects"} + + +def _strip_type_nouns(q: str) -> list[str]: + """Return q's tokens with type-nouns removed (case-insensitive).""" + return [t for t in q.split() if t.lower() not in _SEARCH_TYPE_NOUNS] + + async def _maybe_reactivate_project(project_id: int) -> None: """If a project is paused, reactivate it — activity indicates resumed work.""" from fabledassistant.models.project import Project diff --git a/tests/test_tool_use_fixes.py b/tests/test_tool_use_fixes.py index d763a06..2a9fd49 100644 --- a/tests/test_tool_use_fixes.py +++ b/tests/test_tool_use_fixes.py @@ -28,3 +28,29 @@ async def test_search_projects_tool_returns_success_true(): assert result["success"] is True assert result["type"] == "projects_list" assert len(result["data"]["projects"]) == 1 + + +def test_strip_type_nouns_removes_task_word(): + from fabledassistant.services.notes import _strip_type_nouns + assert _strip_type_nouns("sebring secondary task") == ["sebring", "secondary"] + + +def test_strip_type_nouns_removes_all_variants(): + from fabledassistant.services.notes import _strip_type_nouns + assert _strip_type_nouns("project notes task") == [] + + +def test_strip_type_nouns_case_insensitive(): + from fabledassistant.services.notes import _strip_type_nouns + assert _strip_type_nouns("Sebring Task NOTES") == ["Sebring"] + + +def test_strip_type_nouns_preserves_real_content_words(): + from fabledassistant.services.notes import _strip_type_nouns + assert _strip_type_nouns("circuit configuration") == ["circuit", "configuration"] + + +def test_strip_type_nouns_handles_empty_string(): + from fabledassistant.services.notes import _strip_type_nouns + assert _strip_type_nouns("") == [] + assert _strip_type_nouns(" ") == []