# AI and vectors on SupaHost

> Build semantic search, recommendations and RAG on SupaHost with pgvector in each project's Postgres, embeddings generated in Edge Functions, and RLS on every query.

Source: https://supahost.app/docs/ai/overview · Updated 2026-11-11

Every SupaHost project's database can store and search vectors with the `pgvector` extension. That's enough to build semantic search, "more like this" recommendations, deduplication and retrieval-augmented generation (RAG) without a separate vector database: embeddings sit in the same tables as the rows they describe, Row Level Security decides who can search what, and backups cover them like any other data.

## The pieces

| Piece | What it does | Where it runs on SupaHost |
|---|---|---|
| Embedding model | Turns text (or images) into a list of numbers that captures meaning | An external embeddings API, called from an Edge Function |
| `vector` column | Stores the embedding next to your row | Your project's Postgres database |
| Distance operators | Find the rows whose embeddings are closest to a query | Postgres, via a database function you call with `rpc()` |
| Vector index | Keeps similarity search fast as the table grows | Postgres (HNSW or IVFFlat) |
| Chat model | Writes an answer from the rows you retrieved | An external model API, called from an Edge Function |

A typical flow for a recipe app:

1. A user saves a recipe. A trigger or your app asks an Edge Function to embed the text, and the function stores the vector in `recipes.embedding`.
2. Someone searches "something warm with leftover rice". An Edge Function embeds the query.
3. A database function compares that vector with stored ones and returns the closest recipes the user is allowed to see.
4. Optionally, a chat model summarises the matches into an answer.

## What you need

- **pgvector**: enable it with `create extension if not exists vector with schema extensions;`. It ships with the Supabase Postgres image. See [Vector columns with pgvector](/docs/ai/pgvector).
- **An embeddings provider** and its API key. Store the key as a function secret in Dashboard → your project → **Functions** tab → **Secrets**, never in browser code. See [Generating embeddings](/docs/ai/embeddings).
- **Edge Functions** to call the provider. Each run gets 150 MB of memory and must start responding within 150 seconds, which is plenty for embedding calls and for streaming a chat answer. See [Edge Function limits](/docs/functions/limits).

SupaHost doesn't host embedding or chat models itself. Don't rely on a built-in model session inside Edge Functions; call your provider's HTTP API instead.

## Guides in this section

- [Vector columns with pgvector](/docs/ai/pgvector): column types, distance operators, inserting and reading vectors.
- [Generating embeddings](/docs/ai/embeddings): an Edge Function that embeds rows, automatic embedding on insert, and backfills.
- [Semantic search](/docs/ai/semantic-search): a match function with RLS, called from supabase-js.
- [Hybrid search](/docs/ai/hybrid-search): combine keyword and vector results with reciprocal rank fusion.
- [Vector indexes (HNSW and IVFFlat)](/docs/ai/vector-indexes): when to add one and how to tune it.
- [Retrieval-augmented generation (RAG)](/docs/ai/rag): chunking documents and answering questions from them.

## Sizing on SupaHost

Vectors are just data, so they count toward your plan's shared database size, and searching them uses the instance's CPU and RAM, which all projects share.

Some rough numbers for planning:

| Embedding size | Bytes per vector (`vector`) | 100,000 rows | 1,000,000 rows |
|---|---|---|---|
| 384 dimensions | about 1.5 KB | about 150 MB | about 1.5 GB |
| 1536 dimensions | about 6 KB | about 600 MB | about 6 GB |

An HNSW index roughly doubles that again, and it's fastest when it fits in memory. Builder instances have 4 GB of RAM, Pro 8 GB and Business 16 GB, shared by Postgres and every other service on the instance. If memory is tight, store vectors as `halfvec` (half the size) or choose a model with fewer dimensions. See [Vector indexes](/docs/ai/vector-indexes) and [Plans and limits](/docs/platform/plans).

Because SupaHost charges per instance rather than per request, running searches or Edge Functions doesn't add per-call fees. Your embedding and chat provider bills you separately.

## Things that work differently

- **Direct Postgres clients** (such as Python libraries that connect to Postgres instead of using the Data API) need a direct connection, which is only available on Business and Enterprise through the SSH tunnel. On other plans, use supabase-js or another Data API client and database functions. See [Connecting to your database](/docs/database/connecting).
- **No connection pooler**: the Data API runs at most five queries at once per project, so keep vector searches fast with an index and a sensible `limit`. See [Connections and timeouts](/docs/database/connections-and-timeouts).

## Let an agent build it

If you use an AI coding tool, connect it to the [SupaHost MCP server](/docs/ai-tools/mcp). It can enable `vector`, create tables and match functions with `apply_migration`, and deploy the embedding Edge Function with `deploy_edge_function`.

## Related

- [Example: calling an AI model](/docs/functions/openai)
- [Full-text search](/docs/database/full-text-search)
- [Faster vector search with an HNSW index](/kb/hnsw-index-speed)
