> ## Documentation Index
> Fetch the complete documentation index at: https://docs.portkey.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Supabase

> Generate embeddings with Portkey and store them in Supabase pgvector

Supabase provides Postgres with pgvector for AI applications. With Portkey, generate embeddings using 1600+ models and store them in Supabase for efficient retrieval.

## Prerequisites

* Supabase project API key
* [Portkey API key](https://app.portkey.ai/api-keys)

## Setup

### 1. Install Dependencies

```sh theme={"system"}
pip install portkey-ai supabase
```

### 2. Prepare Database

**1. Create Supabase Project**

Go to [Supabase](https://supabase.com/dashboard/sign-in) and create a new project.

**2. Enable pgvector**

In **Database → Extensions**, enable `pgvector`. Or run:

```sql theme={"system"}
create extension vector;
```

**3. Create Documents Table**

Create a table for documents and embeddings. OpenAI's `text-embedding-ada-002` outputs 1536 dimensions:

```sql theme={"system"}
create table documents (
  id bigserial primary key,
  content text,
  embedding vector(1536)
);
```

### 3. Configure Clients

```python theme={"system"}
from portkey_ai import Portkey
from supabase import create_client, Client

# Supabase
supabase: Client = create_client(
    "YOUR_SUPABASE_PROJECT_URL",
    "YOUR_SUPABASE_API_KEY"
)

# Portkey
client = Portkey(
    api_key="YOUR_PORTKEY_API_KEY",
    provider="@openai-prod"
)
```

## Generate & Store Embeddings

```python theme={"system"}
# Generate embedding
response = client.embeddings.create(
    model="text-embedding-ada-002",
    input="The food was delicious and the waiter..."
)

embedding = response.data[0].embedding

# Store in Supabase
result = supabase.table('documents').insert({
    "content": "The food was delicious and the waiter...",
    "embedding": embedding
}).execute()
```

## Switch Providers

Change the provider to use different embedding models:

```python theme={"system"}
# Cohere embeddings (1024 dimensions)
client = Portkey(
    api_key="YOUR_PORTKEY_API_KEY",
    provider="@cohere-prod"
)

response = client.embeddings.create(
    model="embed-english-v3.0",
    input_type="search_query",
    input="The food was delicious and the waiter..."
)
```

> [!NOTE]
>
> Cohere's `embed-english-v3.0` outputs 1024 dimensions. Create a separate table with `vector(1024)` for Cohere embeddings.

## Next Steps

> [card] [Model Catalog](https://docs.portkey.ai/docs/product/model-catalog.md)
>
> Set up embedding providers

> [card] [Supported Providers](https://docs.portkey.ai/docs/integrations/llms.md)
>
> See all 1600+ supported models

***

> [card] [Portkey is now PRISMA AIRS AI Gateway. See it in action.](https://www.paloaltonetworks.in/ai-security/ai-gateway?utm_source=portkey\&utm_medium=referral\&utm_campaign=prisma_airs\&utm_content=docs_nav#contact)
>
> Contact Us


## Related topics

- [Build an article suggestion app with Supabase pgvector, and Portkey](https://docs.portkey.ai/docs/guides/use-cases/build-an-article-suggestion-app-with-supabase-pgvector-and-portkey.md)
- [November](https://docs.portkey.ai/docs/changelog/2024/nov.md)
- [Overview](https://docs.portkey.ai/docs/integrations/libraries.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.