Supabase
Open-source Firebase alternative with vector database capabilities for AI applications
Alternative To
- • Firebase
- • MongoDB Atlas
- • AWS Amplify
- • Pinecone
Difficulty Level
Requires some technical experience. Moderate setup complexity.
Overview
Supabase is an open-source Firebase alternative built on top of PostgreSQL that includes integrated vector database capabilities. It provides a complete backend solution with authentication, storage, and database services, with special features for AI applications. Supabase Vector, powered by the pgvector extension, allows you to store, index, and query vector embeddings directly in your PostgreSQL database, making it ideal for building AI applications with similarity search and retrieval augmented generation (RAG).
System Requirements
- CPU: 2+ cores (4+ recommended for production)
- RAM: 4GB+ (8GB+ recommended for production)
- GPU: Not required
- Storage: 10GB+ (SSD recommended)
- Operating System: Linux, macOS, Windows, or Docker-compatible platforms
Installation Guide
Prerequisites
- Basic knowledge of command line interfaces
- Git installed on your system
- Docker and Docker Compose (recommended for easy setup)
- Node.js and npm for local development
- Postgres knowledge helpful but not required
Option 1: Local Development with Supabase CLI (Recommended)
Install the Supabase CLI:
# macOS and Linux brew install supabase/tap/supabase # Windows scoop bucket add supabase https://github.com/supabase/scoop-bucket.git scoop install supabaseInitialize a new Supabase project:
supabase initStart the local Supabase development environment:
supabase startAccess the local dashboard:
Open your browser and navigate to
http://localhost:54323
Option 2: Docker Installation
Clone the Supabase Docker repository:
git clone https://github.com/supabase/supabase-docker.gitNavigate to the project directory:
cd supabase-dockerStart the Docker containers:
docker compose up -dAccess the Supabase Dashboard:
Open your browser and navigate to
http://localhost:8000
Option 3: Cloud Hosting
For those who prefer not to self-host, Supabase offers a cloud-hosted solution with a generous free tier:
- Sign up at Supabase Cloud
- Create a new project
- Follow the setup instructions provided
Note: For detailed installation instructions specific to your operating system and environment, please refer to the official documentation on the project’s GitHub repository.
Practical Exercise: Building a Vector Search System with Supabase
Let’s create a simple document retrieval system using Supabase Vector and OpenAI embeddings.
Step 1: Set Up pgvector in Supabase
First, enable the pgvector extension in your Supabase project:
-- Enable the pgvector extension
CREATE EXTENSION IF NOT EXISTS vector;
-- Create a table for documents with vector embeddings
CREATE TABLE documents (
id SERIAL PRIMARY KEY,
content TEXT NOT NULL,
metadata JSONB,
embedding VECTOR(1536) -- For OpenAI embeddings
);
-- Create a function to search for similar documents
CREATE FUNCTION match_documents (
query_embedding VECTOR(1536),
match_count INT DEFAULT 5
) RETURNS TABLE (
id BIGINT,
content TEXT,
metadata JSONB,
similarity FLOAT
) LANGUAGE plpgsql AS $$
BEGIN
RETURN QUERY
SELECT
id,
content,
metadata,
1 - (documents.embedding <=> query_embedding) AS similarity
FROM documents
ORDER BY documents.embedding <=> query_embedding
LIMIT match_count;
END;
$$;
Step 2: Add Sample Documents with Embeddings
Create a simple script to add documents with their vector embeddings:
// Save as add-documents.js
import { createClient } from "@supabase/supabase-js";
import { Configuration, OpenAIApi } from "openai";
const supabaseUrl = "YOUR_SUPABASE_URL";
const supabaseKey = "YOUR_SUPABASE_SERVICE_KEY";
const openaiApiKey = "YOUR_OPENAI_API_KEY";
const supabase = createClient(supabaseUrl, supabaseKey);
const configuration = new Configuration({ apiKey: openaiApiKey });
const openai = new OpenAIApi(configuration);
const documents = [
"Artificial intelligence is transforming industries worldwide",
"Vector databases store and query high-dimensional vectors efficiently",
"Retrieval augmented generation improves the accuracy of large language models",
"Supabase combines PostgreSQL with modern development tools",
"Embedding models convert text into numerical vector representations",
];
async function getEmbedding(text) {
const response = await openai.createEmbedding({
model: "text-embedding-ada-002",
input: text,
});
return response.data.data[0].embedding;
}
async function addDocuments() {
for (const doc of documents) {
const embedding = await getEmbedding(doc);
await supabase.from("documents").insert({
content: doc,
metadata: { source: "example" },
embedding: embedding,
});
console.log(`Added document: ${doc.substring(0, 30)}...`);
}
}
addDocuments();
Step 3: Creating a Simple Search Function
Build a function to search for similar documents:
// Save as search-documents.js
import { createClient } from "@supabase/supabase-js";
import { Configuration, OpenAIApi } from "openai";
const supabaseUrl = "YOUR_SUPABASE_URL";
const supabaseKey = "YOUR_SUPABASE_KEY";
const openaiApiKey = "YOUR_OPENAI_API_KEY";
const supabase = createClient(supabaseUrl, supabaseKey);
const configuration = new Configuration({ apiKey: openaiApiKey });
const openai = new OpenAIApi(configuration);
async function searchDocuments(query, matchCount = 3) {
// Generate embedding for the query text
const embeddingResponse = await openai.createEmbedding({
model: "text-embedding-ada-002",
input: query,
});
const queryEmbedding = embeddingResponse.data.data[0].embedding;
// Search for similar documents using the match_documents function
const { data: documents, error } = await supabase.rpc("match_documents", {
query_embedding: queryEmbedding,
match_count: matchCount,
});
if (error) {
console.error("Error searching documents:", error);
return [];
}
return documents;
}
// Example usage
async function runExample() {
const query = "How can AI help businesses?";
console.log(`Searching for: "${query}"`);
const results = await searchDocuments(query);
console.log("\nResults:");
results.forEach((doc, i) => {
console.log(
`${i + 1}. ${doc.content} (Similarity: ${doc.similarity.toFixed(4)})`,
);
});
}
runExample();
Step 4: Extending the System
Once you have the basic system working, you can extend it with more advanced features:
- Add metadata filtering to your search queries
- Implement hybrid search combining keyword and vector similarity
- Create a simple web interface for your search system
- Integrate with a large language model for RAG (Retrieval Augmented Generation)
- Add real-time syncing of documents using Supabase’s real-time capabilities
Resources
Official Documentation
Supabase provides comprehensive documentation covering all aspects of the platform.
Vector Database Features
- Store and query vector embeddings in the same database as your application data
- Support for multiple vector similarity metrics (cosine, Euclidean, dot product)
- Efficient indexing via pgvector with HNSW and IVF indexing methods
- Hybrid search combining metadata filtering with vector similarity
- Open-source stack with no vendor lock-in
Community Support
Join the active Supabase community to get help, share experiences, and contribute.
GitHub Repository Discord Community Twitter/X @supabase
Tutorials and Guides
Learn more about using Supabase for AI applications through these resources:
Vector Search with Next.js and OpenAI AI & Vector Guides Supabase Blog AI Articles
Suggested Projects
You might also be interested in these similar projects:
Qdrant is a high-performance vector similarity search engine and vector database written in Rust, designed for production-ready AI applications
Chroma is the AI-native open-source embedding database for storing and searching vector embeddings