Supabase Backend as a Service · Lezione

Ricerca full-text e vector embedding con pgvector

Potenzia le funzionalità di ricerca usando la ricerca full-text di Postgres e la ricerca per similarità semantica con l’estensione pgvector in Supabase.

Lezione 3 di 313 passaggi

Ricerca full-text e vector embedding con pgvector è una lezione Supabase Backend as a Service gratuita su CoddyKit. Questa è la lezione 3 di 3. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Supabase Backend as a Service, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Supabase Backend as a Service include 3 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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.

Gratis per iniziare

Impara Supabase Backend as a Service con un tutor IA — gratis

Scrivi ed esegui vero codice nel tuo browser, ricevi aiuto istantaneo da un tutor IA disponibile 24/7, e riprendi da dove hai lasciato sul web o nell'app.

Corsi
11
Lezioni
40

Domande Frequenti

La lezione «Ricerca full-text e vector embedding con pgvector» è gratuita?

Sì — il testo completo di «Ricerca full-text e vector embedding con pgvector» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Supabase Backend as a Service, passa a CoddyKit PRO. Il corso Supabase Backend as a Service include 3 lezioni in totale.

Cosa imparerò in «Ricerca full-text e vector embedding con pgvector»?

Potenzia le funzionalità di ricerca usando la ricerca full-text di Postgres e la ricerca per similarità semantica con l’estensione pgvector in Supabase. Eserciti Supabase Backend as a Service con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Supabase Backend as a Service?

Non è richiesta alcuna esperienza precedente. Supabase Backend as a Service su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 3 di 3.

Quanto tempo richiede la lezione «Ricerca full-text e vector embedding con pgvector»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Supabase Backend as a Service?

Sì. Ogni lezione Supabase Backend as a Service include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Utilizzo delle estensioni di Postgres
  2. Dati geospaziali avanzati (PostGIS)
  3. Ricerca full-text e vector embedding con pgvector
← Torna a Supabase Backend as a Service