Context: This guide assumes you have a running Payload CMS 3.0 project.
Imagine if your CMS didn't just store content, but actually understood it. By integrating a Vector Store (Upstash) with Payload, you unlock Chatbots, RAG (Retrieval Augmented Generation), and Semantic Search.
But there is a trap: AI operations are slow. Generating embeddings and syncing to Upstash can take 2-3 seconds—too long for a user to wait when saving a post.
This guide shows you how to implement a Background Job pipeline to sync your content asynchronously using Payload's native Jobs queue.
0. Prerequisites
Before writing code, we need to set up our environment.
Install Dependencies
bash
npm install @upstash/vector openai
Environment Variables
Add these to your .env file:
bash
# Get keys from https://console.upstash.com/vector
UPSTASH_VECTOR_REST_URL="https://your-index-url.upstash.io"
UPSTASH_VECTOR_REST_TOKEN="your-token"# Get key from https://platform.openai.com/
OPENAI_API_KEY="sk-..."
Create the Upstash Index
CRITICAL: When creating your index in the Upstash Console, you MUST set the dimensions to 1024 to match OpenAI's text-embedding-3-small model config we will use.
Defining the job isn't enough; something needs to run it.
Local Development
In a separate terminal window, run:
bash
npx payload jobs:run
This starts a long-running process that polls the payload-jobs collection.
Production (Vercel/Serverless)
Since you don't have a long-running server, usage Vercel Cron or an external cron service to poke Payload's job endpoint.
Enable Vercel Cron.
Payload automatically configured the endpoint at /api/payload-jobs/run.
Ensure your vercel.json calls this endpoint periodically.
Summary
Dependencies: Installed @upstash/vector & openai.
Config: Created Index (1024 dims) & .env.
Code: Added client, embedding, operations, and upsert job handler.
Registration: Registered Job in payload.config.ts.
Trigger: Added hook to Posts collection.
Runner: Started npx payload jobs:run.
Now, when you publish a post, Payload queues the task, your worker picks it up, and your Vector Store stays perfect in sync—users never wait.
If you're deploying this job to Vercel specifically, running Payload CMS jobs on Vercel covers the cron-endpoint setup serverless requires instead of a long-running worker.