RORK LABJP
TOOLING — Rork's developer repos keep moving: rork-xcode was updated on July 16, rork-device on July 15, and rork-plist on July 13OPUS46 — Claude Opus 4.6 is live in Rork, and Rork Max is built to assemble apps on top of Claude CodeSIM — A cloud iOS simulator runs in the browser, with one click to install on a device and two clicks to publish to the App StoreMAX — Rork Max emits pure Swift rather than React Native, reaching iPhone, iPad, Apple Watch, Apple TV, Vision Pro, and even iMessageNATIVE — That opens up HealthKit, ARKit and LiDAR, NFC, Dynamic Island, Live Activities, 3D through Metal, and on-device inference with Core MLSEED — Rork raised a $15M seed led by Left Lane Capital, with Peak XV and a16z Speedrun joining the roundTOOLING — Rork's developer repos keep moving: rork-xcode was updated on July 16, rork-device on July 15, and rork-plist on July 13OPUS46 — Claude Opus 4.6 is live in Rork, and Rork Max is built to assemble apps on top of Claude CodeSIM — A cloud iOS simulator runs in the browser, with one click to install on a device and two clicks to publish to the App StoreMAX — Rork Max emits pure Swift rather than React Native, reaching iPhone, iPad, Apple Watch, Apple TV, Vision Pro, and even iMessageNATIVE — That opens up HealthKit, ARKit and LiDAR, NFC, Dynamic Island, Live Activities, 3D through Metal, and on-device inference with Core MLSEED — Rork raised a $15M seed led by Left Lane Capital, with Peak XV and a16z Speedrun joining the round
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-embeddingsAI30recommendationadvanced6

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-07-05
When Your Finance App's AI Keeps Dumping Everything Into 'Other' — Field Notes on Catching Silent Classification Drift
An AI expense classifier in a Rork finance app can be accurate at launch and quietly decay over months until the monthly advice goes wrong. Here is how I instrumented confidence and category distribution to get ahead of the drift, with working code.
📚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 →