0Pricing
Supabase Backend as a Service · レッスン

pgvectorによる全文検索とベクトル埋め込み

Supabaseのpgvector拡張機能を使い、Postgresの全文検索と意味的類似度検索で強力な検索機能を実現します。

「pgvectorによる全文検索とベクトル埋め込み」はCoddyKit上の無料Supabase Backend as a Serviceレッスンです。 これはレッスン3/3です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはSupabase Backend as a Service学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Supabase Backend as a Serviceコースには全3レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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.

よくある質問

「pgvectorによる全文検索とベクトル埋め込み」レッスンは無料ですか?

はい。「pgvectorによる全文検索とベクトル埋め込み」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Supabase Backend as a Serviceコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Supabase Backend as a Serviceコースには全3レッスンが含まれています。

「pgvectorによる全文検索とベクトル埋め込み」で何を学びますか?

Supabaseのpgvector拡張機能を使い、Postgresの全文検索と意味的類似度検索で強力な検索機能を実現します。 ブラウザで直接実行するハンズオンコードでSupabase Backend as a Serviceを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Supabase Backend as a Serviceを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのSupabase Backend as a Serviceは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/3です。

「pgvectorによる全文検索とベクトル埋め込み」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このSupabase Backend as a Serviceレッスンでコードを書いて実行できますか?

はい。すべてのSupabase Backend as a Serviceレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. Postgres拡張機能の活用
  2. 高度な地理空間データ(PostGIS)
  3. pgvectorによる全文検索とベクトル埋め込み
← Supabase Backend as a Serviceに戻る