Skip to content
🚚 Self-hosting
Deployment

Deploying Embedbase

For any help or assistance with deployment, book a demo (opens in a new tab) and we will help you deploy your own instance.

Using Postgres

⚠️ Postgres support is currently in alpha and is very likely only working in local development.

Run Postgres in Docker:

docker run --name postgres -e POSTGRES_DB=embedbase -e POSTGRES_PASSWORD=localdb -p 5432:5432 -p 8080:8080 -d ankane/pgvector

Basic entrypoint that uses Postgres & OpenAI (get your key (opens in a new tab)):

# main.py
import os
from embedbase import get_app
from embedbase.settings import Settings
from embedbase.database.postgres_db import Postgres
from embedbase.embedding.openai import OpenAI
 
settings = Settings(vector_database="postgres")
app = get_app(settings).use(Postgres()).use(OpenAI("<your key>")).run()

Run:

uvicorn main:app

Using Supabase

Basic entrypoint that uses Supabase & OpenAI (get your key (opens in a new tab)):

# main.py
import os
from embedbase import get_app
from embedbase.settings import Settings
from embedbase.database.supabase_db import Supabase
from embedbase.embedding.openai import OpenAI
 
settings = Settings(vector_database="supabase")
app = get_app(settings).use(Supabase("<your url>", "<your key>")).use(OpenAI("<your key>")).run()

There are multiple ways to use Supabase, either running it locally (opens in a new tab) or using their hosted instance.

First, create a supabase project on https://supabase.com (opens in a new tab).

Then you can setup Supabase database either using Supabase UI or via Supabase CLI (opens in a new tab)

Using CLI

git clone https://github.com/different-ai/embedbase
supabase init

Use the reset command here to reset the database to the current migrations (opens in a new tab).

supabase db reset

Now you can Setup your configuration file

Using Supabase UI

  1. Go to SQL Editor
  1. Enable pgvector extension by running the following query
create extension vector
with
  schema extensions;
  1. Run the following query to create the table
create table documents (
    id text primary key,
    data text,
    embedding vector (1536),
    hash text,
    dataset_id text,
    user_id text,
    metadata json
);
  1. Enable row-level security (prevent client from read & write access to the db)
alter table documents
  enable row level security;
  1. Create the search database function
create or replace function match_documents (
  query_embedding vector(1536),
  similarity_threshold float,
  match_count int,
  query_dataset_id text,
  query_user_id text default null
)
returns table (
  id text,
  data text,
  score float,
  hash text,
  embedding vector(1536),
  metadata json
)
language plpgsql
as $$
begin
  return query
  select
    documents.id,
    documents.data,
    (1 - (documents.embedding <=> query_embedding)) as similarity,
    documents.hash,
    documents.embedding,
    documents.metadata
  from documents
  where 1 - (documents.embedding <=> query_embedding) > similarity_threshold
    and query_dataset_id = documents.dataset_id
    and (query_user_id is null or query_user_id = documents.user_id)
  order by documents.embedding <=> query_embedding
  limit match_count;
end;
$$;
  1. Create the index
create index on documents
using ivfflat (embedding vector_cosine_ops)
with (lists = 100);
  1. Create a view for the /datasets endpoint
CREATE OR REPLACE VIEW distinct_datasets AS
SELECT dataset_id, user_id, COUNT(*) AS documents_count
FROM documents
GROUP BY dataset_id, user_id;

🎉 Now you should be able to run Embedbase with Supabase

uvicorn main:app

Cloud Run deployment

Embedbase makes it easy for you to deploy your own instance. This assures you're in control of your data end to end.

Setup

# login to gcloud
gcloud auth login
 
PROJECT_ID=$(gcloud config get-value project)
 
# Enable container registry
gcloud services enable containerregistry.googleapis.com
 
# Enable Cloud Run
gcloud services enable run.googleapis.com
 
# Enable Secret Manager
gcloud services enable secretmanager.googleapis.com
 
# create a secret for the config
gcloud secrets create EMBEDBASE --replication-policy=automatic
 
# add a secret version based on your yaml config
gcloud secrets versions add EMBEDBASE --data-file=config.yaml
 
IMAGE_URL="gcr.io/${PROJECT_ID}/embedbase:0.0.1"
 
docker buildx build . --platform linux/amd64 -t ${IMAGE_URL} -f ./docker/Dockerfile
 
docker push ${IMAGE_URL}
 
gcloud run deploy embedbase \
  --image ${IMAGE_URL} \
  --region us-central1 \
  --allow-unauthenticated \
  --set-secrets /secrets/config.yaml=EMBEDBASE:1
 
# getting cloud run url
gcloud run services list --platform managed --region us-central1 --format="value(status.url)" --filter="metadata.name=embedbase"

If you don't want to use Google Cloud Run, consider: