feat: AI Search v3 — FTS5 Full-Text Search, Vectorize Auto-Indexing & Relevance Filtering#647
Open
mmcintosh wants to merge 2 commits intoSonicJs-Org:mainfrom
Open
feat: AI Search v3 — FTS5 Full-Text Search, Vectorize Auto-Indexing & Relevance Filtering#647mmcintosh wants to merge 2 commits intoSonicJs-Org:mainfrom
mmcintosh wants to merge 2 commits intoSonicJs-Org:mainfrom
Conversation
…ce filtering FTS5 Full-Text Search: - BM25-ranked search with porter stemming and unicode61 tokenizer - Field boosting (title 5x, slug 2x, body 1x) and highlighted snippets - Query sanitization to prevent SQL errors from user input - Self-healing auto-index: indexes up to 200 unindexed items on first search - Real-time content sync via waitUntil() on create/update/delete Vectorize Auto-Indexing (AI Mode): - Auto-indexes unindexed collections before searching - Mirrors FTS5 ensureCollectionsIndexed() pattern - Checks ai_search_index_meta for completion with indexed_items > 0 AI Mode Relevance Filtering: - Absolute threshold (0.6 cosine similarity) filters low-quality matches - Score gap detection cuts off when score drops >0.05 between results - Skips stale Vectorize entries not found in D1 FTS5 Admin API: - GET /api/fts5/status, POST /api/fts5/index-collection, POST /api/fts5/reindex-all - FTS5 status section and reindex button on settings page Test Page & Integration: - Clickable result title links to content edit pages - FTS5 mode selector and documentation in integration guide - POST /api/search accepts mode: "fts5" with BM25 and highlights fields
52 new tests across 3 files: - 39-ai-search-fts5.spec.ts (15): FTS5 admin API, search API, test page UI, settings page, content sync, integration guide - 39-ai-search-new-features.spec.ts (15): integration guide, test page, autocomplete, similarity caching, settings navigation - 40-search-v3-comprehensive.spec.ts (37): response structure for all modes, edge cases (SQL injection, XSS, unicode, long queries), autocomplete API, analytics API, settings API, clickable result links, content lifecycle, cross-mode consistency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AI Search v3 — FTS5 Full-Text Search, Vectorize Auto-Indexing & Relevance Filtering
Summary
Adds FTS5 full-text search as a second search tier, implements self-healing auto-indexing for both FTS5 and Vectorize, and introduces intelligent relevance filtering for AI mode. The plugin now offers three production-ready search modes — all working out of the box with zero configuration.
Builds on the similarity caching and autocomplete work from PR #609.
Changes
1. FTS5 Full-Text Search Engine
FTS5Serviceimplementing SQLite FTS5 with BM25 probabilistic ranking<mark>tags around matched terms2. Real-Time FTS5 Content Sync
c.executionCtx.waitUntil()for non-blocking indexing (no user-facing latency)admin-content.tsandapi-content-crud.ts3. Vectorize Auto-Indexing (AI Mode)
ensureCollectionsIndexed()self-healing patternai_search_index_metafor completion status (requiresindexed_items > 0)4. AI Mode Relevance Filtering
5. FTS5 Admin API
GET /admin/plugins/ai-search/api/fts5/status— availability check and index countsPOST /admin/plugins/ai-search/api/fts5/index-collection— index a single collectionPOST /admin/plugins/ai-search/api/fts5/reindex-all— reindex all selected collections6. Test Page Improvements
/admin/content/{id}/edit)7. Search Mode Integration
POST /api/searchnow acceptsmode: "fts5"alongside"ai"and"keyword"Technical Details
New Files:
services/fts5.service.ts— FTS5 search engine (531 lines): BM25 ranking, highlighting, auto-indexing, query sanitization, content syncmigrations/033_fts5_fulltext_search.sql— FTS5 virtual table and sync tracking tabletests/e2e/39-ai-search-fts5.spec.ts— 15 FTS5-specific E2E teststests/e2e/40-search-v3-comprehensive.spec.ts— 37 comprehensive E2E testsModified Files:
services/custom-rag.service.ts— AddedensureCollectionsIndexed(), score gap detection, stale data filtering, changed status filter frompublishedto non-deletedservices/ai-search.ts— Added FTS5 search mode routing, FTS5 fallback to keywordroutes/admin.ts— Added FTS5 status, index-collection, and reindex-all endpointsroutes/test-page.ts— Clickable result links, FTS5 mode toggle, string concatenation renderingcomponents/settings-page.ts— FTS5 status section with reindex buttonroutes/admin-content.ts— FTS5 sync hooks on content create/update/deleteroutes/api-content-crud.ts— FTS5 sync hooks on API content operationsdb/migrations-bundle.ts— Includes new FTS5 migrationtypes.ts— Addedfts5to SearchMode type, FTS5-specific result fieldsindex.ts— Route registration updatesTesting
Unit Tests (Vitest): 1237 passed, 328 skipped, 0 failed (42 test files)
E2E Tests (Playwright): 337 passed, 289 skipped, 2 failed (628 total, 26.9m)
20-content-api-collection-filter.spec.ts— pre-existing, unrelated to search40-search-v3-comprehensive.spec.ts:80— AI moderelevance_scoretest requires Vectorize; will pass in Cloudflare preview CISearch-specific E2E Tests: 81 across 4 files
39-ai-search-plugin.spec.ts39-ai-search-fts5.spec.ts39-ai-search-new-features.spec.ts40-search-v3-comprehensive.spec.tsNew E2E Coverage:
Performance Impact
Breaking Changes
None — fully backward compatible. Existing keyword and AI search continue working unchanged.
Migration Notes
033_fts5_fulltext_search.sqlcreates the FTS5 virtual table and sync tableKnown Issues
postscollection doesn't exist in the test environmentDemo / Screenshots
Related Issues
(Link any related GitHub issues here)
Checklist