Skip to content

AI Search

Temp edited this page Feb 11, 2026 · 2 revisions

AI Search

D1 Manager integrates with Cloudflare AI Search (formerly AutoRAG) to enable semantic search over your database schemas and data. Ask questions in natural language and get AI-generated SQL suggestions.

Overview

AI Search uses a D1β†’R2 connector pattern:

  1. Export - Your database schema and data are exported as markdown documents to R2
  2. Index - Cloudflare AI Search indexes these documents for semantic understanding
  3. Query - Ask questions in natural language or perform semantic searches

Features

Feature Description
Compatibility Analysis View table count, row count, and estimated export size
One-click Export Export database schema and data to R2 in markdown format
Semantic Search Find relevant tables, columns, and data based on meaning
AI-powered Search Get AI-generated answers and SQL suggestions
Instance Management List AI Search instances and trigger re-indexing

Prerequisites

  1. R2 Bucket - AI Search exports require the BACKUP_BUCKET binding in wrangler.toml
  2. AI Binding - Add the [ai] binding to wrangler.toml:
[ai]
binding = "AI"
  1. AI Search Instance - Create via Cloudflare Dashboard pointing to your backup bucket

Getting Started

Step 1: Export Database

  1. Open any database in D1 Manager
  2. Navigate to the AI Search tab
  3. Click Export to R2 to create searchable documents

The export creates:

  • schema.md - Full database schema with CREATE TABLE statements
  • tables/{name}.md - Per-table documentation
  • relationships.md - Foreign key relationships
  • data/{name}.md - Full table data in markdown format

Step 2: Create AI Search Instance

  1. Go to Cloudflare Dashboard > AI > AI Search
  2. Click Create AI Search
  3. Select your backup bucket as the data source
  4. Choose embedding and generation models (defaults recommended)
  5. Click Create

Wait for indexing to complete (shown on the instance overview page).

Step 3: Search

  1. Return to D1 Manager > AI Search tab
  2. Select your AI Search instance from the dropdown
  3. Choose search mode:
    • AI Search - Get AI-generated answers with SQL suggestions
    • Semantic Search - Find relevant documents based on meaning
  4. Enter your query and press Enter or click Search

Example Queries

Query Mode Result
"How do I find users by email?" AI SQL query suggestion with explanation
"tables with timestamps" Semantic List of tables containing created_at, updated_at columns
"foreign key relationships" Semantic Documents describing FK constraints
"What columns are in the orders table?" AI Column list with types and constraints

Export Format

Exports are stored in your BACKUP_BUCKET at ai-search/{databaseId}/:

ai-search/
└── {database-id}/
    β”œβ”€β”€ schema.md           # Full database schema
    β”œβ”€β”€ relationships.md    # FK relationships
    β”œβ”€β”€ tables/
    β”‚   β”œβ”€β”€ users.md        # Per-table documentation
    β”‚   └── orders.md
    └── data/
        β”œβ”€β”€ users.md        # Full data (markdown table)
        └── orders.md

API Reference

Endpoints

Method Endpoint Description
GET /api/ai-search/compatibility/:dbId Analyze database for indexability
POST /api/ai-search/export/:dbId Export database to R2
GET /api/ai-search/instances List AI Search instances
POST /api/ai-search/instances/:name/sync Trigger re-indexing
POST /api/ai-search/:name/search Semantic search
POST /api/ai-search/:name/ai-search AI-powered search

Export Request

curl -X POST https://your-d1-manager/api/ai-search/export/{databaseId} \
  -H "Content-Type: application/json" \
  -d '{"databaseName": "my-database"}'

Search Request

curl -X POST https://your-d1-manager/api/ai-search/{instanceName}/ai-search \
  -H "Content-Type: application/json" \
  -d '{"query": "How do I query users by email?", "max_num_results": 10}'

Troubleshooting

"No AI Search instances found"

  1. Export your database first using Export to R2
  2. Create an AI Search instance in the Cloudflare Dashboard
  3. Point the instance to your backup bucket (BACKUP_BUCKET)
  4. Wait for indexing to complete
  5. Return to D1 Manager and refresh

"R2 bucket not configured"

Add the BACKUP_BUCKET binding to your wrangler.toml:

[[r2_buckets]]
binding = "BACKUP_BUCKET"
bucket_name = "d1-manager-backups"

Search returns no results

  1. Verify the export completed successfully
  2. Check that the AI Search instance status is "active" (not "indexing")
  3. Try triggering a sync using the refresh button next to the instance selector
  4. Ensure your query relates to content in your database

Related Pages

Clone this wiki locally