Skip to content
/ vectr Public

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

License

vercel/vectr

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
sequenceDiagram
    participant User
    participant App as Next.js App
    participant Workflow as Vercel Workflow
    participant Blob as Vercel Blob
    participant AI as Grok Vision AI
    participant Search as Upstash Search

    User->>App: Upload Image (FormData)
    App->>Workflow: POST /api/upload

    Note over Workflow: Start Workflow

    Workflow->>Blob: Upload to Storage (Step 1)
    Note over Blob: Max 3 retries<br/>Rate limit handling
    Blob-->>Workflow: Blob URL + Metadata

    Workflow->>AI: Generate Description (Step 2)
    Note over AI: Max 5 retries<br/>Rate limit handling
    AI-->>Workflow: Image Description

    Workflow->>Search: Index with Metadata (Step 3)
    Note over Search: Max 5 retries<br/>Stores description + blob metadata
    Search-->>Workflow: Success

    Workflow-->>App: 200 OK

    User->>App: Search Images
    App->>Search: Semantic Query
    Search-->>App: Results with Metadata
    App-->>User: Display Results
Loading

πŸ—οΈ 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:

Deploy with Vercel

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 Gateway Key (only needed locally)
AI_GATEWAY_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

Variable Description Required
UPSTASH_SEARCH_URL Upstash Vector Search endpoint Yes
UPSTASH_SEARCH_TOKEN Upstash authentication token Yes
BLOB_READ_WRITE_TOKEN Vercel Blob Storage token Yes
XAI_API_KEY xAI API key for Grok Vision Yes

πŸ“Š 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

About

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

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks