Cloudflare
Configure @vitehub/vector against Cloudflare Vectorize.
Use the Cloudflare provider when your app runs on Workers and you want ViteHub to read and write vectors through a Vectorize binding.
Before you start
Install @vitehub/vector and the Cloudflare SDK:
Terminal
pnpm add https://pkg.pr.new/vite-hub/vitehub/@vitehub/vector@main cloudflare
Deploy the app on Cloudflare Workers so the Vectorize binding exists at runtime.
Configure Cloudflare
nuxt.config.ts
export default defineNuxtConfig({
modules: ['@vitehub/vector/nuxt'],
vector: {
provider: 'cloudflare',
binding: 'VECTOR_INDEX',
defaultTopK: 8,
},
})
binding defaults to VECTOR_INDEX, so you only need to set it when your Worker uses a different binding name.
Define a vector
Keep the shared vector shape in the definition file. Put Cloudflare-only settings in top-level vector config or under providers.cloudflare.
server/vectors/docs.ts
export default defineVector({
dimensions: 1536,
metric: 'cosine',
filterable: ['tenantId', 'kind'],
providers: {
cloudflare: {
indexName: 'docs',
},
},
})
indexName is an optional prefix ViteHub adds before the discovered vector name when it builds the Vectorize namespace.
Query the vector
const docs = getVector('docs')
const matches = await docs.query({
vector: [0.1, 0.2, 0.3],
topK: 5,
filter: {
tenantId: 'acme',
},
})
Cloudflare-specific options
| Option | Use it for |
|---|---|
binding | Override the Cloudflare Vectorize binding name. |
defaultTopK | Set the default number of matches returned by query() when you do not pass topK. |
providers.cloudflare.indexName | Prefix the discovered vector name before ViteHub resolves the Vectorize namespace. |
What changes on Cloudflare
| Concern | Behavior |
|---|---|
| Binding resolution | ViteHub reads the Vectorize binding from vector.binding or falls back to VECTOR_INDEX. |
| Namespace naming | ViteHub uses the discovered vector name, plus indexName when you set one. |
| Native handle | getVector(name).native gives you the raw Cloudflare Vectorize binding. |
| Filtering | Portable equality and in filters are translated to the Vectorize query options ViteHub supports. |
Choose Cloudflare when the rest of the app already runs on Workers and you want Vectorize access through the same deployment.