Skip to content
Back to Templates

Vectr: Natural Language Image Search

A free, open-source template for building natural language image search on the AI Cloud.

Vectr OG Image

Vectr

Vectr is an AI-powered image search application template that automatically generates descriptions for uploaded images and indexes them for semantic search.

✨ Features

  • πŸ“€ Drag-and-drop image uploads with Vercel Blob Storage
  • πŸ€– AI-powered image descriptions using Grok 2 Vision
  • πŸ” Semantic search with Upstash Vector Search (stores metadata too!)
  • πŸ”„ Resilient processing with Vercel Workflow automatic retries
  • 🎨 Beautiful UI built with shadcn/ui and Tailwind CSS
  • πŸ’° Incredibly cheap - No database needed!

πŸš€ How It Works

When you upload an image, Vectr automatically:

  1. πŸ’Ύ Stores the image in Vercel Blob Storage
  2. 🧠 Generates a detailed description using Grok 2 Vision AI
  3. πŸ”Ž Indexes the description AND metadata in Upstash for semantic search

πŸ—οΈ Architecture

Workflow Steps

Each step in the image processing workflow is isolated and runs on a separate serverless function with automatic retries:

Step 1: Upload Image (upload-image.ts)

  • πŸ’Ύ Uploads to Vercel Blob Storage
  • ⏱️ Handles rate limiting with 1-minute retry delays
  • πŸ”„ Maximum 3 retry attempts
  • ❌ Fatal error on quota exceeded or invalid files

Step 2: Generate Description (generate-description.ts)

  • πŸ€– Uses Grok 2 Vision AI to analyze the image
  • ⏱️ Handles rate limiting with 5-minute retry delays
  • πŸ”„ Maximum 5 retry attempts
  • ❌ Fatal error on invalid/unsupported images

Step 3: Index Image (index-image.ts)

  • πŸ”Ž Indexes description AND blob metadata in Upstash
  • πŸ’Ύ Stores all image data (url, size, contentType, etc.) as metadata
  • ⏱️ Handles rate limiting with 1-minute retry delays
  • πŸ”„ Maximum 5 retry attempts
  • ❌ Fatal error on invalid data

Error Handling

Vectr uses sophisticated error handling to ensure reliable processing:

  • πŸ”„ RetryableError: Temporary failures (rate limits, network issues, timeouts)
  • ❌ FatalError: Permanent failures (invalid data, constraint violations)
  • πŸ“Š Context-aware retries: Each step tracks attempt count and timestamps
  • 🎯 Smart HTTP responses: 400 for fatal errors, 500 for retryable errors

πŸ› οΈ Tech Stack

  • ⚑ Framework: Next.js 15 with App Router and React 19
  • πŸ”„ Workflow: Vercel Workflow (alpha)
  • πŸ€– AI: Grok 2 Vision via Vercel AI SDK
  • πŸ” Search & Storage: Upstash Vector Search (stores metadata too!)
  • πŸ’Ύ Blob Storage: Vercel Blob Storage
  • 🎨 UI: shadcn/ui + Tailwind CSS 4
  • πŸ”’ Type Safety: TypeScript + Zod

πŸš€ Deploy to Vercel

The easiest way to deploy Vectr is using the Vercel Marketplace:

During deployment, you'll be prompted to set up:

  1. πŸ” Upstash Vector Search - Semantic search + metadata storage
  2. πŸ’Ύ Vercel Blob Storage - Image storage

Both services have generous free tiers and will be automatically configured. No database needed!

πŸ’» Local Development

Prerequisites

  • 🟒 Node.js 18+
  • πŸ“¦ pnpm (recommended)

Setup

  1. Clone the repository:
git clone https://github.com/your-username/vectr.git
cd vectr
  1. Install dependencies:
pnpm install
  1. Set up environment variables:

Create a .env.local file with:

# Upstash Search
UPSTASH_SEARCH_URL="https://..."
UPSTASH_SEARCH_TOKEN="..."
# Vercel Blob
BLOB_READ_WRITE_TOKEN="..."
# AI Provider (Grok via Vercel AI SDK)
XAI_API_KEY="..."
  1. Run the development server:
pnpm dev

Open http://localhost:3000 to see your app.

πŸ“œ Scripts

  • πŸš€ pnpm dev - Start development server with Turbopack
  • πŸ—οΈ pnpm build - Build for production
  • βœ… pnpm check - Run linting checks
  • ✨ pnpm format - Format code with Biome

πŸ“ Project Structure

vectr/
β”œβ”€β”€ app/
β”‚ β”œβ”€β”€ actions/
β”‚ β”‚ └── search.ts # Server action for search
β”‚ β”œβ”€β”€ api/
β”‚ β”‚ └── upload/
β”‚ β”‚ β”œβ”€β”€ route.ts # Workflow route handler
β”‚ β”‚ β”œβ”€β”€ upload-image.ts # Step 1: Upload to Blob
β”‚ β”‚ β”œβ”€β”€ generate-description.ts # Step 2: AI description
β”‚ β”‚ └── index-image.ts # Step 3: Index with metadata
β”‚ β”œβ”€β”€ layout.tsx
β”‚ └── page.tsx
β”œβ”€β”€ components/
β”‚ β”œβ”€β”€ header.tsx
β”‚ β”œβ”€β”€ results.tsx
β”‚ β”œβ”€β”€ upload-button.tsx
β”‚ └── uploaded-images-provider.tsx
β”œβ”€β”€ lib/
β”‚ └── utils.ts
└── package.json

πŸ” Environment Variables

VariableDescriptionRequired
UPSTASH_SEARCH_URLUpstash Vector Search endpointYes
UPSTASH_SEARCH_TOKENUpstash authentication tokenYes
BLOB_READ_WRITE_TOKENVercel Blob Storage tokenYes
XAI_API_KEYxAI API key for Grok VisionYes

πŸ“Š Observability

Vectr includes comprehensive logging for monitoring and debugging:

  • πŸ”„ [WORKFLOW] - Workflow-level events and timing
  • πŸ”§ [stepId] - Step-level events with unique identifiers
  • 🌐 [API] - HTTP request/response logging

All logs include timestamps, attempt counts, and duration metrics.

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. Our Contributing Guide has more information on how to get started.

πŸ“„ License

MIT

GitHub Repovercel/vectr
Use Cases