A small Vectorize example you can adapt quickly
This example keeps Vectorize honest: one index binding, one upsert, and one query against the same worker path.
That is enough to show the binding shape without requiring a whole retrieval stack in the very first example.
- Config focus
- Explicit index naming
- Runtime shape
- Upsert one vector and query it back
- Best use
- Search prototypes and embedding-backed retrieval endpoints
Start by wiring the binding clearly in config
Minimal Vectorize config
import { defineConfig } from 'devflare/config'
export default defineConfig({
name: 'vectorize-example',
files: {
fetch: 'src/fetch.ts'
},
bindings: {
vectorize: {
DOCUMENT_INDEX: {
indexName: 'document-index'
}
}
}
})
Then use it in one honest runtime path
- Keep the embedding dimension explicit and consistent with the actual index you created.
- If you later split write and read into separate routes, this same example still teaches the core binding path.
A tiny write-and-query route
import { env } from 'devflare'
export async function fetch(): Promise<Response> {
const vector = Array(32).fill(0.5)
await env.DOCUMENT_INDEX.upsert?.([
{ id: 'doc-1', values: vector, metadata: { title: 'Demo doc' } }
])
const result = await env.DOCUMENT_INDEX.query?.(vector, {
topK: 1,
returnMetadata: true
})
return Response.json({ result })
}
Keep the first version boring on purpose
The remote index still has to exist
This example is small on purpose, but it is not fictional. The named index has to exist and match the vector shape you send.
Previous
Testing Vectorize
The right Vectorize tests are targeted remote checks: a small insert or query, a clear skip condition, and a real index behind the binding.
Next
Hyperdrive
Hyperdrive is modeled in Devflare config and compile flows like other name-based resources, but its tested local ergonomics are thinner than D1 or KV.