Skip to content
Dashboard

Amazon OpenSearch Serverless is now available in the Vercel Marketplace

Link to headingBuilt for agentic infrastructure

lib/opensearch.ts
import { createOpenSearch } from '@vercel/aws';
const os = createOpenSearch();

An OpenSearch client authenticated through Vercel OIDC, with no static AWS keys.

app/api/ask/route.ts
import { opensearch } from "@/lib/opensearch";
import { embed, generateText } from "ai";
export async function POST(req: Request) {
const { question } = await req.json();
// Turn the question into a vector
const { embedding } = await embed({
model: "openai/text-embedding-3-small",
value: question,
});
// Retrieve the 5 most semantically similar docs
const { body } = await opensearch.search({
index: "docs",
body: {
size: 5,
query: { knn: { embedding: { vector: embedding, k: 5 } } },
},
});
const context = body.hits.hits
.map((h: any) => h._source.content)
.join("\n\n");
// Answer grounded in the retrieved context
const { text } = await generateText({
model: "anthropic/claude-sonnet-4-5",
prompt: `Answer using only this context:\n\n${context}\n\nQuestion: ${question}`,
});
return Response.json({ answer: text });
}

A RAG route that embeds the question, retrieves the top-5 nearest documents from OpenSearch, and answers grounded in them.

Link to headingGet started

Ready to deploy?