Search Proxy (Cloudflare Worker)
- Config:
components/search_proxy/wrangler.toml - Source:
components/search_proxy/src/
The main search API. Routes search queries to Marqo via service bindings, with authentication, caching, settings management, and metrics.
Worker Names
| Env | Worker Name | Domain |
|---|---|---|
| Staging | staging-ecom-api | staging-ecom.dev-marqo.org |
| Preprod | preprod-ecom-api | ecom.preprod-marqo.org |
| Prod | prod-ecom-api | ecom.marqo-ep.ai |
Bindings
| Binding | Type | Purpose |
|---|---|---|
KV | KV Namespace | Index settings (populated by Settings Exporter Lambda) |
KV_QCFG | KV Namespace | Query config overrides (populated by Admin Lambda) |
MARQO_WORKER | Service Binding | Marqo search backend (global-worker) |
PIXEL_WORKER | Service Binding | Analytics pixel tracking |
AGENTIC_SEARCH_WORKER | Service Binding | AI-powered conversational search |
Request Flow
- Extract API key from
X-API-Keyor Shopify proxy auth - Validate API key with control plane gateway
- Load index settings from KV
- Apply query overrides from KV_QCFG
- Check for redirects (parallel with search)
- Call Marqo via MARQO_WORKER service binding
- Transform and return results
- Enqueue metrics to SQS (async via
waitUntil)
Key Endpoints
| Path | Method | Purpose |
|---|---|---|
/search | POST | Main search |
/search/composite | POST | Multi-query search |
/recommendations/similar | POST | Similar product recs |
/recommendations/complementary | POST | Complementary recs |
/recommendations/for-you | POST | Personalized recs |
/search/suggestions | POST | Autocomplete |
/collections | POST | Collection-filtered search |
/agentic/search | POST | AI conversational search |
/agentic/chat | POST | Multi-turn AI chat |
External Dependencies
| Service | How | Credentials |
|---|---|---|
| Marqo | Service binding to global-worker | N/A (internal) |
| SQS (metrics) | AWS SDK via IAM user | AWS_ACCESS_KEY_ID/SECRET from Secrets Manager |
| DDB (redirects) | AWS SDK via IAM user | Same IAM user as SQS |
| KV (settings) | Cloudflare KV binding | N/A (built-in) |
| Control plane API | HTTP to API Gateway | IAM or API key |
Typical Investigation Paths
Search returning errors:
- Tail worker logs:
npx wrangler tail {env}-ecom-api - Check if settings exist in KV for the account
- Check Marqo worker health via service binding
Stale search results / settings not applying:
- Read KV key for the account:
npx wrangler kv key get --namespace-id {id} "{system_account_id}" - Compare with DDB source: query
EcomIndexSettingsTablefor the account pk - Check settings exporter Lambda logs (DDB stream consumer)
High latency:
- Check Marqo backend health
- Check CloudWatch dashboard for p99 latency widgets
- Look for slow queries in worker logs
Relevance trigger not appearing in responses:
relevanceScore is omitted silently from the response whenever any precondition fails. Walk this checklist in order:
- Client must pass
"relevanceScore": truein the request body. Without the flag, scoring is never invoked (zero overhead). - Index settings in KV must include
relevance_trigger_config.model_id. Read the KV record for the account and confirm the field is present:npx wrangler kv key get --namespace-id <id> "<system_account_id>-<index_name>" | jq .relevance_trigger_config - The model JSON must exist in KV under
relevance_model:<model_id>. Look forrelevance_model_not_foundwarnings in worker logs (npx wrangler tail {env}-ecom-api). - Query type — image queries, wildcard (
*), multi-term/weighted objects, and empty queries are skipped by design. - Hit count — fewer than 3 hits returned causes the scorer to skip (score-variance features need multiple data points).
- Errors — look for
relevance_score_call_failedwarnings (emitted by the search.ts call sites when the scorer throws). The scorer itself propagates errors to the call site, which is wrapped in try/catch and returns null on any exception. - Successful scoring logs
relevance_score_computedwithrelevance_score,relevance_scoring_ms, andmodel_idfields.
To enable the feature for a new index, follow the enable-relevance-trigger runbook.