Skip to content

Edge

turbomem supports opt-in edge deployment via Upstash Vector - a remote vector database over HTTP. PGlite and sqlite-vec remain the default local backends for Node/Bun; you only need this guide when deploying to stateless edge runtimes.

When to use edge vs local storage

RuntimeRecommended storage
Node, Bun, local-first apps"pglite" (default) or "sqlite-vec"
Cloudflare Workers, Vercel Edge, Deno Deploy"upstash-vector"

Edge runtimes are stateless, there is no writable filesystem, and memory in an isolate does not survive between requests. Local PGlite or sqlite-vec paths will not persist on edge. Use a remote vector store instead.

No migration required

Existing PGlite or sqlite-vec setups keep working unchanged. Edge storage is an additional opt-in path.

How edge deployment works

Edge runtime ──► TurboMemory ──► Embedding API (fetch)

                      └──► Upstash Vector (HTTP)
  1. Facts are extracted and embedded using fetch-based providers.
  2. Vectors and metadata are stored in your Upstash index over REST.
  3. Search queries embed the text, then query Upstash for similar vectors.

See Architecture for the full pipeline.

Prerequisites

Before writing code:

  • [ ] An Upstash account (free tier available)
  • [ ] A Vector index created in the console (see below)
  • [ ] An embedding provider API key - Google (gemini-embedding-001) or Voyage (voyage-4) recommended. See Providers for the full model list.
  • [ ] An extraction provider API key - Google (gemini-3.5-flash) recommended for edge. See Providers for the full model list.

Step 1: Create an Upstash Vector index

turbomem does not create the index for you. Set it up once in the Upstash Console:

  1. Go to console.upstash.comVectorCreate Index
  2. Choose a name (e.g. turbomem-prod)
  3. Set Dimensions to match your embedding model (see table below)
  4. Set Similarity function to Cosine (matches PGlite and sqlite-vec)
  5. Create the index
  6. Open the index → Connect tab → copy UPSTASH_VECTOR_REST_URL and UPSTASH_VECTOR_REST_TOKEN

Dimensions must match your embedding model

The index dimension count is fixed at creation time. If it does not match your embedding adapter, init() throws DimensionMismatchError. Create a new index when you change models.

Dimensions reference

Embeddings presetDefault dimensionsSet Upstash index to
"openai" (text-embedding-3-small)15361536
"openai" (text-embedding-3-large)30723072
"google" (gemini-embedding-001)3072768, 1536, or 3072 (match your google.dimensions config)
"voyage"10241024 (or match your voyage.dimensions)
"local"384Not recommended on edge

See Providers for the full embedding reference.

Step 2: Install

bash
npm install turbomem @upstash/vector

@upstash/vector is an optional peer dependency - only required when using storage: "upstash-vector".

Step 3: Environment variables

bash
# Upstash Vector (from console Connect tab)
export UPSTASH_VECTOR_REST_URL=https://...
export UPSTASH_VECTOR_REST_TOKEN=...

# Embedding + extraction (Google example)
export GEMINI_API_KEY=...
VariableRequiredUsed by
UPSTASH_VECTOR_REST_URLYes (unless set in config)Upstash storage
UPSTASH_VECTOR_REST_TOKENYes (unless set in config)Upstash storage
GEMINI_API_KEYYes (Google stack)Embeddings + extraction
VOYAGE_API_KEYYes (Voyage embeddings)Embeddings

Step 4: Configure turbomem

ts
import { TurboMemory } from "turbomem";

const memory = new TurboMemory({
  storage: "upstash-vector",
  upstashVector: {
    url: process.env.UPSTASH_VECTOR_REST_URL,
    token: process.env.UPSTASH_VECTOR_REST_TOKEN,
    // namespace: "my-app", // optional
  },
  embeddings: "google",
  google: {
    apiKey: process.env.GEMINI_API_KEY,
    dimensions: 768, // must match your Upstash index
  },
  extraction: {
    provider: "google",
    model: "gemini-3.5-flash",
    apiKey: process.env.GEMINI_API_KEY,
  },
});

await memory.init();

await memory.addFacts(["The user prefers edge deployments"], { userId: "user_123" });

const results = await memory.search("deployment preferences", { userId: "user_123" });

Or pass the adapter directly:

ts
import { TurboMemory, UpstashVectorStorageAdapter } from "turbomem";

const memory = new TurboMemory({
  storage: new UpstashVectorStorageAdapter({
    url: process.env.UPSTASH_VECTOR_REST_URL,
    token: process.env.UPSTASH_VECTOR_REST_TOKEN,
  }),
  // ...
});
ComponentRecommendedAvoid on edge
Storage"upstash-vector""pglite", "sqlite-vec"
Embeddings"google", "voyage""local" (heavy WASM cold start)
Extraction"google"-

Runtime notes

Cloudflare Workers

Set secrets with wrangler secret put UPSTASH_VECTOR_REST_URL (and token, API keys). No filesystem access, Upstash over HTTP is the right fit.

Vercel Edge Functions

Add environment variables in your project settings. If using Next.js App Router, mark the route as edge-compatible in your route config.

Node / serverless (not edge)

PGlite is usually simpler for Node deployments with disk access. Upstash is optional here too, useful when you want shared remote storage across serverless instances.

Limitations

  • getAll() - paginates the full index and filters client-side. Can be slow on large indexes.
  • deleteAll() - Upstash metadata filter deletes perform a full index scan (O(n)).
  • Eventual consistency - newly upserted vectors may take a moment before appearing in search results.
  • Cost - Upstash charges per request; PGlite uses free local disk.
  • CLI - the turbomem CLI targets local PGlite. Edge users integrate via the SDK.

Troubleshooting

ErrorCauseFix
DimensionMismatchErrorIndex dimensions ≠ embedding modelCreate a new index with correct dimensions, or adjust google.dimensions
ConfigError (missing @upstash/vector)Peer not installednpm install @upstash/vector
Upsert/query fails (401)Wrong URL or tokenRe-copy credentials from Upstash Connect tab
Empty search results right after insertEventual consistencyRetry after a brief delay

Next steps