Skip to content

Commit cf5827b

Browse files
committed
Search: Replace AI JSON generation with enum classification
- New architecture: LLM classifies into predefined enums (type, time, size, scope, exclude, folders) + extracts filename keywords. Rust handles all computation — regex construction, date math, size thresholds, pattern merging. Key-value line output, not JSON. - `ai_response_parser.rs`: line-by-line parser with enum validation, fallback keyword extraction (3 longest words) - `ai_query_builder.rs`: 22-type lookup table, 14 time enums (incl. `last_3_months`, `last_6_months`), size/scope/keyword mappers, `merge_keyword_and_type()` combining keywords + type into single regex, redundant keyword detection - Delete: `AiSearchQuery`, `PreflightContext`, `SEARCH_PROMPT_TEMPLATE`, `REFINEMENT_RULES`, two-pass refinement, JSON parser, backslash escape fixer, regex validator, preflight table formatter - Single-pass flow: one LLM call → parse → build → search (was: translate → search → build preflight → refine → search) - Frontend: remove preflight row, generation counter, pass-2 orchestration. `executeAiSearch` is now translate → search - MCP executor: single translate → search, delete preflight/refinement orchestration - Remove `.key` from presentations type (was matching TLS certs, not Keynote files) - Prompt rules: time-only-when-explicit, singular keywords, type-over-keywords, stronger exclude handling - 57 new Rust tests for parser, builder, and merge logic - R7 eval: 2B local model improved from 23% Great to 43% Great, Bad down from 43% to 20%. Cloud model at 67% Great. Zero parse errors on both (was 13% on 2B with old pipeline)
1 parent 1d588f8 commit cf5827b

15 files changed

Lines changed: 2816 additions & 1637 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/desktop/src-tauri/src/commands/CLAUDE.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ immediately to business-logic modules. No significant logic lives here.
2424
| `licensing.rs` | Licensing | Status query, activation, expiry, reminder, key validation |
2525
| `indexing.rs` | Drive index | `start_drive_index`, `stop_drive_index`, `get_index_status`, `get_dir_stats`, `get_dir_stats_batch`, `clear_drive_index`, `set_indexing_enabled`, `get_index_debug_status` (dev-only extended stats). Uses `State<IndexManagerState>`. |
2626
| `clipboard.rs` | Clipboard file ops | `copy_files_to_clipboard`, `cut_files_to_clipboard`, `read_clipboard_files`, `clear_clipboard_cut_state`. macOS uses NSPasteboard via `clipboard::pasteboard`; non-macOS stubs return errors. |
27-
| `search.rs` | Drive search | `prepare_search_index`, `search_files`, `release_search_index`, `translate_search_query`, `parse_search_scope`. Thin wrappers over `indexing::search` module. Post-filters directory sizes after `fill_directory_sizes`. |
27+
| `search.rs` | Drive search | `prepare_search_index`, `search_files`, `release_search_index`, `translate_search_query`, `parse_search_scope`. Thin wrappers over `indexing::search` module. Post-filters directory sizes after `fill_directory_sizes`. AI search uses single-pass classification prompt → `ai_response_parser``ai_query_builder` pipeline. |
28+
| `ai_response_parser.rs` | AI search parser | Key-value line parser for LLM classification responses. Validates enum fields, extracts keywords. Fallback keyword extraction when LLM fails. |
29+
| `ai_query_builder.rs` | AI search builder | Maps parsed LLM enums (type, time, size, scope) into `SearchQuery` fields. Merges keywords + type into single regex pattern. Deterministic date/size computation. |
2830
| `sync_status.rs` | Cloud sync status | `get_sync_status` — macOS delegates to `file_system::sync_status`; non-macOS returns empty map via `#[cfg]` on the function itself (not the module). |
2931

3032
## Key decisions

0 commit comments

Comments
 (0)