RORK LABJP
PRICE — Rork Max spans $200 to $1,800 per month, with the upper tiers aimed at heavier builders and teamsFREE — The free tier lands at roughly five prompts per week, enough to try it but not to build on continuouslySHIP — App Store publishing is automated through builds, certificates, and submission, so you can ship an iOS app without a Mac or XcodeSIM — A browser-streamed simulator lets you watch your app run in a real Apple environment from your own browserNATIVE — It reaches HealthKit, ARKit and LiDAR, NFC, Dynamic Island, and Metal 3D — territory React Native cannot touchFUNDING — Rork raised a $15M seed led by Left Lane Capital, announced April 9, 2026, and acquired app builder PaperlinePRICE — Rork Max spans $200 to $1,800 per month, with the upper tiers aimed at heavier builders and teamsFREE — The free tier lands at roughly five prompts per week, enough to try it but not to build on continuouslySHIP — App Store publishing is automated through builds, certificates, and submission, so you can ship an iOS app without a Mac or XcodeSIM — A browser-streamed simulator lets you watch your app run in a real Apple environment from your own browserNATIVE — It reaches HealthKit, ARKit and LiDAR, NFC, Dynamic Island, and Metal 3D — territory React Native cannot touchFUNDING — Rork raised a $15M seed led by Left Lane Capital, announced April 9, 2026, and acquired app builder Paperline
Articles/AI Models
AI Models/2026-03-26Advanced

Taking Rork × Supabase pgvector Semantic Search to Production: Index Choice, Incremental Re-embedding, and Hybrid Retrieval

How to run semantic search in a Rork app for real. Measure HNSW against IVFFlat, cut embedding API calls with content hashing, and fuse vector search with full-text search using RRF.

rork58supabase3pgvector3semantic-searchvector-embeddingsAI29recommendationadvanced7

Premium Article

The day I shipped a search box in one of my calming-wallpaper apps, a log entry showed a user typing "something to look at when I can't sleep." The result count was zero. The database held hundreds of images tagged "stillness," "moonlight," and "restful sleep" — and not a single character matched.

Search had to reach for meaning, not letters. That was the moment I reached for pgvector.

This article builds semantic search and AI recommendations into a Rork mobile app with Supabase pgvector, at a scale an indie developer actually operates: low six figures of rows, a small Supabase instance, one person on call. If you need a refresher on Supabase auth and real-time features, see the Rork × Supabase Auth & Real-Time Implementation Guide.

Here is the architecture:

  1. The user enters a natural-language search query
  2. A Supabase Edge Function converts the query to a vector via the OpenAI Embeddings API
  3. pgvector runs a cosine similarity search against the database
  4. Results come back to the Rork app with relevance scores

Getting that far is the easy half. What bites you in production is the second half of this article: which index you choose, and when you decide to rebuild your embeddings.

Prerequisites and Setup

What You'll Need

  • A Rork Max account with an active project
  • A Supabase project (pgvector is available on the Free plan)
  • An OpenAI API key for the Embeddings API
  • Node.js 18+ for local Edge Function testing

What Are Vector Embeddings?

Vector embeddings transform data like text or images into high-dimensional numerical arrays. OpenAI's text-embedding-3-small model, for instance, converts any text into a 1536-dimensional array of floating-point numbers.

Texts with similar meanings end up close together in vector space. "Walking the dog" and "Taking my pet for a stroll" use different words but produce vectors that are nearly identical in direction. This is the foundation that makes semantic search possible.

Setting Up Supabase pgvector

Enabling the Extension

Run the following SQL in the Supabase Dashboard SQL Editor:

-- Enable the pgvector extension
create extension if not exists vector with schema extensions;
 
-- Products table (semantic search target)
create table products (
  id bigserial primary key,
  name text not null,
  description text not null,
  category text not null,
  price numeric(10,2) not null,
  image_url text,
  -- 1536-dimensional vector column (OpenAI text-embedding-3-small)
  embedding vector(1536),
  created_at timestamptz default now()
);
 
-- IVFFlat index for cosine similarity search
-- Suitable for medium-scale data (up to ~1M rows)
create index on products
  using ivfflat (embedding vector_cosine_ops)
  with (lists = 100);
 
-- Enable Row Level Security
alter table products enable row level security;
 
-- Authenticated users can view all products
create policy "Products are viewable by authenticated users"
  on products for select
  to authenticated
  using (true);

Creating the Search RPC Function

This PostgreSQL function is the core of our search pipeline. It accepts a query vector and returns products ranked by cosine similarity.

-- Semantic search function
-- query_embedding: the vectorized search query
-- match_threshold: similarity cutoff (0-1, higher = stricter)
-- match_count: maximum results to return
create or replace function match_products(
  query_embedding vector(1536),
  match_threshold float default 0.7,
  match_count int default 10
)
returns table (
  id bigint,
  name text,
  description text,
  category text,
  price numeric,
  image_url text,
  similarity float
)
language plpgsql
as $$
begin
  return query
  select
    products.id,
    products.name,
    products.description,
    products.category,
    products.price,
    products.image_url,
    -- Calculate cosine similarity (1 - cosine distance)
    1 - (products.embedding <=> query_embedding) as similarity
  from products
  where 1 - (products.embedding <=> query_embedding) > match_threshold
  order by products.embedding <=> query_embedding
  limit match_count;
end;
$$;

The <=> operator computes cosine distance in pgvector. By subtracting from 1, we get cosine similarity — a value closer to 1 means the items are more semantically related.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
A measured comparison of HNSW and IVFFlat on recall@10 and p95 latency, with selection criteria by data size
An incremental re-embedding design using content_hash that cuts Embeddings API calls by over 90%
A SQL implementation of hybrid search that fuses vector and full-text results with RRF
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Rork Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

AI Models2026-04-30
Building an AI-Powered Photo Organizer App with Rork — A Complete Implementation Guide Using Vision, CLIP, and pgvector
A complete implementation guide for building an AI-powered photo organizer app with Rork. Extract faces, objects, and text with the Vision framework, generate semantic embeddings with CLIP, and run similarity search at scale using Supabase pgvector — designed as a production pipeline from day one.
AI Models2026-04-12
Building an AI Photo Editor App with Rork — Complete Implementation Guide for Filters, Background Removal, and Style Transfer
A complete guide to building an AI-powered photo editor app with Rork. Implement image filters, background removal, AI style transfer, and export features to create a production-quality app ready for the App Store.
AI Models2026-08-07
Cutting MCP Tools Didn't Make Anything Lighter — 2,377 Bytes of Definitions vs 110,298 Bytes of Response
I wrote a minimal MCP server for a wallpaper catalog and measured the byte cost of tool definitions against the byte cost of responses. Here is which side actually matters, and the real reason to merge tools.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →