Skip to content

[Feat] Memory embeddings auto-wire to Cloudflare Workers AI - #3616

Closed
pridemusvaire wants to merge 4 commits into
RooCodeInc:developfrom
pridemusvaire:feat/memory-cloudflare-embeddings
Closed

pridemusvaire wants to merge 4 commits into
RooCodeInc:developfrom
pridemusvaire:feat/memory-cloudflare-embeddings

Conversation

@pridemusvaire

Copy link
Copy Markdown
Contributor

Why this PR exists

  • I am a maintainer / this is internal Roomote work

Memory Settings currently warns "Memory has no embeddings provider, so it can only match keywords" on Cloudflare-only deployments. Those deployments already have a Workers AI token that speaks OpenAI-compatible embeddings, but Memory only treated an explicit embeddings upstream URL or an OpenAI/OpenRouter key as an embeddings provider.

What changed

Memory embeddings auto-wire to Cloudflare Workers AI when CLOUDFLARE_WORKERS_AI_API_TOKEN and a 32-hex CLOUDFLARE_WORKERS_AI_ACCOUNT_ID are set. Semantic recall no longer needs a separate OpenAI or OpenRouter key.

  • Explicit R_BRAIN_EMBEDDINGS_UPSTREAM_URL still wins.
  • The gateway base is https://api.cloudflare.com/client/v4/accounts/{account}/ai; Roomote appends /v1/embeddings.
  • Chat synthesis stays on OpenAI, OpenRouter, or the helper model. Cloudflare is embeddings-only.
  • Set R_BRAIN_EMBEDDING_MODEL=@cf/baai/bge-m3 and R_BRAIN_EMBEDDING_DIMENSIONS=1024 before Memory's first boot.

How it was tested

  • SDK (19): isBrainEmbeddingAvailable and resolveBrainEmbeddingsUpstream (URL wins, CF /ai base, invalid account including 32-char non-hex, token/account missing, 30s cache on hits and misses)
  • API gateway (32): embeddings route to Workers AI without an OpenAI key; chat stays on the provider when CF embeddings are wired
  • Web (3): Settings status is incomplete without embeddings and connected when embeddings are available
  • Pre-push gates: oxlint, turbo lint, check-types:fast (27/27), knip, gitleaks: pass

Checklist

  • The PR title follows the repo convention: [Fix], [Feat], [Improve], [Refactor], [Docs], or [Chore] followed by a user-facing description
  • This PR is small and scoped to one change
  • pnpm lint and pnpm check-types pass locally
  • I added tests or included a clear manual validation note above
  • I removed secrets, tokens, private keys, and customer data from code, logs, and screenshots
  • If this change should appear in the changelog, I ran pnpm changeset

Cloudflare-only deployments already had a Workers AI token that speaks
OpenAI-compatible embeddings, but Memory still required an OpenAI or
OpenRouter key for semantic recall.
@mintlify

mintlify Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 7fc18b1.

Approve preview

@roomote-community

roomote-community Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

No new code issues found. Both earlier routing findings are addressed: Cloudflare-model requests stay on Workers AI when a provider key is added, while OpenAI-model requests retain the provider path. An isolated resolver probe passed for both OpenAI and OpenRouter coexistence, cache isolation, and explicit-upstream precedence. CI tests and the app Docker build are still running. See session

Reviewed 7fc18b1

…are also set.

Workers AI embeddings auto-wire only when no OpenAI or OpenRouter Memory key is configured, so an existing corpus pinned to text-embedding-3-small is not forwarded to Cloudflare.
A corpus pinned to @cf/baai/bge-m3 must stay on Cloudflare even after an OpenAI or OpenRouter chat/task key is configured, instead of forwarding that model id to the provider.
Knip failed on CloudflareWorkersAiEmbeddings because it is only used inside the credential reader.
@pridemusvaire

Copy link
Copy Markdown
Contributor Author

Closing this. Memory embeddings should be wired with the documented R_BRAIN_EMBEDDINGS_UPSTREAM_URL (any OpenAI-compatible embeddings server, plus R_BRAIN_INFERENCE_UPSTREAM_API_KEY when that server needs a bearer key). Auto-detecting Cloudflare Workers AI credentials is the wrong product: operators without Cloudflare never needed it, and operators with Cloudflare can point the documented upstream URL at Workers AI themselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant