refactor(semantic-search): introduce backend contract#67
Conversation
Greptile SummaryThis PR introduces
Confidence Score: 5/5Safe to merge — all changed paths are covered by typecheck and unit tests, and the no-backend fallback is safe and typed throughout. The refactoring is a clean extraction with no logic changes: every operation that previously returned a typed error when unconfigured continues to do so through the shared sentinels, the Cloudflare host guard is unchanged, and the new backend-storage wiring test validates the full factory lifecycle. No regressions introduced. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
Host["apps/host-cloudflare\nplugins.ts"] -->|"ToolSearchBackend.vector(\n store, geminiApiKey, namespace\n)"| Factory["ToolSearchBackendFactory\n(makeVectorToolSearchBackend)"]
Factory -->|"pluginStorage"| Plugin["semanticSearchPlugin\nplugin.ts"]
Factory -->|"storage(deps) → TStorage"| Plugin
Factory -->|"build({ storage }) → ToolSearchBackend"| Plugin
Plugin -->|"makeSemanticSearchExtension(\n backend\n)"| Ext["SemanticSearchExtension\n(index / reindex / sweep / search / status / provider)"]
Ext -->|"backend present"| Backend["ToolSearchBackend\n(vector impl)"]
Ext -->|"backend absent"| NC["notConfigured()\nor unconfiguredIndex"]
Backend -->|"index"| TSI["ToolSearchIndex.Service\n(makeToolSearchIndex)"]
Backend -->|"reindex"| RTI["runToolSearchIndex"]
Backend -->|"sweep"| SW["sweepRemoved"]
Backend -->|"search"| Prov["ToolDiscoveryProvider\n(vector or hybrid)"]
Backend -->|"status"| Stat["fingerprints.count\n+ lexicalStore.count"]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
Host["apps/host-cloudflare\nplugins.ts"] -->|"ToolSearchBackend.vector(\n store, geminiApiKey, namespace\n)"| Factory["ToolSearchBackendFactory\n(makeVectorToolSearchBackend)"]
Factory -->|"pluginStorage"| Plugin["semanticSearchPlugin\nplugin.ts"]
Factory -->|"storage(deps) → TStorage"| Plugin
Factory -->|"build({ storage }) → ToolSearchBackend"| Plugin
Plugin -->|"makeSemanticSearchExtension(\n backend\n)"| Ext["SemanticSearchExtension\n(index / reindex / sweep / search / status / provider)"]
Ext -->|"backend present"| Backend["ToolSearchBackend\n(vector impl)"]
Ext -->|"backend absent"| NC["notConfigured()\nor unconfiguredIndex"]
Backend -->|"index"| TSI["ToolSearchIndex.Service\n(makeToolSearchIndex)"]
Backend -->|"reindex"| RTI["runToolSearchIndex"]
Backend -->|"sweep"| SW["sweepRemoved"]
Backend -->|"search"| Prov["ToolDiscoveryProvider\n(vector or hybrid)"]
Backend -->|"status"| Stat["fingerprints.count\n+ lexicalStore.count"]
Reviews (3): Last reviewed commit: "refactor(semantic-search): let backends ..." | Re-trigger Greptile |
6063ba3 to
02ad2ce
Compare
## Summary Add the Cloudflare AI Search backend for the semantic search backend contract. ## Changes - Add the AI Search backend and plugin-storage tracking for uploaded items. - Use AI Search as the Cloudflare host semantic backend when the binding is present. - Truncate uploaded documents by bytes before sending them to AI Search. ## Tests - `bun run --cwd packages/plugins/semantic-search typecheck` - `bun run --cwd packages/plugins/semantic-search test src/sdk/plugin.test.ts src/sdk/ai-search.test.ts` - `bun run --cwd apps/host-cloudflare typecheck` - `oxfmt --check apps/host-cloudflare/src/app.ts apps/host-cloudflare/src/config.ts apps/host-cloudflare/src/execution.ts apps/host-cloudflare/src/plugins.ts apps/host-cloudflare/wrangler.jsonc packages/plugins/semantic-search/src/api/group.ts packages/plugins/semantic-search/src/sdk/ai-search.ts packages/plugins/semantic-search/src/sdk/ai-search.test.ts packages/plugins/semantic-search/src/sdk/collections.ts packages/plugins/semantic-search/src/sdk/documents.ts packages/plugins/semantic-search/src/sdk/index.ts packages/plugins/semantic-search/src/sdk/plugin.ts packages/plugins/semantic-search/src/sdk/tool-search-backend.ts` - `oxlint -c .oxlintrc.jsonc apps/host-cloudflare/src/app.ts apps/host-cloudflare/src/config.ts apps/host-cloudflare/src/execution.ts apps/host-cloudflare/src/plugins.ts packages/plugins/semantic-search/src/api/group.ts packages/plugins/semantic-search/src/sdk/ai-search.ts packages/plugins/semantic-search/src/sdk/ai-search.test.ts packages/plugins/semantic-search/src/sdk/collections.ts packages/plugins/semantic-search/src/sdk/documents.ts packages/plugins/semantic-search/src/sdk/index.ts packages/plugins/semantic-search/src/sdk/plugin.ts packages/plugins/semantic-search/src/sdk/tool-search-backend.ts --deny-warnings` <!-- stack:links:start --> ### [Stack](https://github.com/aryasaatvik/stack) 1. #67 2. **#68** 👈 current <!-- stack:links:end -->
Summary
Introduce the semantic search backend contract and move the current vector implementation behind it.
Changes
ToolSearchBackendas the plugin-level backend boundary.ToolSearchBackend.vector.Tests
bun run --cwd packages/plugins/semantic-search typecheckbun run --cwd packages/plugins/semantic-search test src/sdk/plugin.test.tsbun run --cwd apps/host-cloudflare typecheckoxfmt --check apps/host-cloudflare/src/plugins.ts packages/plugins/semantic-search/src/sdk/index.ts packages/plugins/semantic-search/src/sdk/plugin.ts packages/plugins/semantic-search/src/sdk/plugin.test.ts packages/plugins/semantic-search/src/sdk/tool-search-backend.tsoxlint -c .oxlintrc.jsonc apps/host-cloudflare/src/plugins.ts packages/plugins/semantic-search/src/sdk/index.ts packages/plugins/semantic-search/src/sdk/plugin.ts packages/plugins/semantic-search/src/sdk/plugin.test.ts packages/plugins/semantic-search/src/sdk/tool-search-backend.ts --deny-warningsStack