# Vector & AI

The Quickback Stack integrates with Cloudflare Workers AI to automatically generate vector embeddings for semantic search. Embeddings are generated asynchronously via Cloudflare Queues and stored in both D1 (as JSON) and optionally in a Vectorize index for fast similarity search.

## Two Levels of Configuration

| Level | API | Purpose |
|-------|-----|---------|
| Table-level | `embeddings` in `defineTable()` | Auto-embed on INSERT/UPDATE |
| Service-level | `defineEmbedding()` | Typed search functions with classification |

Use both together: table-level for auto-generation, service-level for search.

## How It Works

```
CRUD operation → Enqueue job → Queue consumer
                                    │
                                    ├─ Workers AI (generate embedding)
                                    ├─ D1 (store vector as JSON)
                                    └─ Vectorize (upsert for search)
```

1. A record is created or updated via the API
2. The compiler auto-enqueues an embedding job to `EMBEDDINGS_QUEUE`
3. The queue consumer generates the embedding using Workers AI
4. The vector is stored in D1 and optionally upserted to Vectorize

## Cloudflare Bindings

| Binding | Purpose |
|---------|---------|
| `AI` | Workers AI for embedding generation |
| `VECTORIZE` | Vectorize index for similarity search |
| `EMBEDDINGS_QUEUE` | Queue for async processing |

## Default Model

The default embedding model is `@cf/baai/bge-base-en-v1.5` (768 dimensions). You can configure a different model per table.

## Pages

- **[Automatic Embeddings](/stack/vector/embeddings)** — `defineTable()` embeddings config, queue consumer, Vectorize integration, and `defineEmbedding()` search service
- **[Using Embeddings](/stack/vector/using-embeddings)** — Embeddings API endpoints, semantic search, and practical usage
