0Pricing
Supabase Backend as a Service · Lesson

Full-Text Search and Vector Embeddings with pgvector

Power search features using Postgres full-text search and semantic similarity search with the pgvector extension in Supabase.

Full-Text Search and Vector Embeddings with pgvector is a free Supabase Backend as a Service lesson on CoddyKit — lesson 3 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Supabase Backend as a Service learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Two Kinds of Search

Postgres supports full-text search for keyword matching and, via the pgvector extension, semantic search over AI embeddings, both inside Supabase.

Full-Text Search Basics

Postgres turns text into a searchable tsvector and queries it with a tsquery, handling stemming and ranking.

A Full-Text Query

Match documents whose body contains the search terms.

select id, title
from articles
where to_tsvector('english', body)
      @@ plainto_tsquery('english', 'database scaling');

Indexing for Speed

A GIN index on the tsvector makes full-text search fast at scale.

create index articles_fts
on articles
using gin (to_tsvector('english', body));

What Are Embeddings?

An embedding is a list of numbers (a vector) that captures meaning. Similar texts have vectors that are close together, enabling search by concept, not just keywords.

Enabling pgvector

Turn on the extension, then add a vector column sized to your model's dimensions.

create extension if not exists vector;
alter table docs add column embedding vector(1536);

Storing an Embedding

Generate the vector with an embedding model, then insert it alongside the text.

const { error } = await supabase
  .from('docs')
  .insert({ content: text, embedding: vectorArray });

Similarity Search

Find the nearest vectors using a distance operator. <=> is cosine distance.

select content
from docs
order by embedding <=> query_embedding
limit 5;

Indexing Vectors

An HNSW or IVFFlat index speeds up nearest-neighbor search on large vector tables.

create index on docs
using hnsw (embedding vector_cosine_ops);

Choosing the Right Approach

Use full-text search for exact keyword needs, and vector search for meaning-based retrieval like Q&A or recommendations. Many apps combine both (hybrid search).

function pickSearch(needsMeaning) {
  return needsMeaning ? 'vector' : 'full-text';
}
console.log(pickSearch(true));

Putting It Together

Postgres gives you both keyword and semantic search natively. With GIN indexes for text and HNSW indexes for vectors, search stays fast as data grows.

Quick Check

Test your understanding of search extensions.

Recap

You learned full-text search with tsvector and GIN indexes, plus semantic search with pgvector, vector columns, distance operators, and HNSW indexes, and when to use each or combine them.

Frequently asked questions

Is the “Full-Text Search and Vector Embeddings with pgvector” lesson free?

Yes — the full text of “Full-Text Search and Vector Embeddings with pgvector” is free to read here on the web, and the Supabase Backend as a Service course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Supabase Backend as a Service course, upgrade to CoddyKit PRO.

What will I learn in “Full-Text Search and Vector Embeddings with pgvector”?

Power search features using Postgres full-text search and semantic similarity search with the pgvector extension in Supabase. You practise Supabase Backend as a Service with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Supabase Backend as a Service?

No prior experience is required. Supabase Backend as a Service on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 3, so you can start here or from the beginning and move at your own pace.

How long does the “Full-Text Search and Vector Embeddings with pgvector” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Supabase Backend as a Service lesson?

Yes. Every Supabase Backend as a Service lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Utilizing Postgres Extensions
  2. Advanced Geospatial Data (PostGIS)
  3. Full-Text Search and Vector Embeddings with pgvector
← Back to Supabase Backend as a Service