0Pricing
Supabase Backend as a Service · บทเรียน

การค้นหาข้อความเต็มและเวกเตอร์ฝังตัวด้วย pgvector

เพิ่มประสิทธิภาพฟีเจอร์การค้นหาด้วยการค้นหาข้อความเต็มของ Postgres และการค้นหาความคล้ายคลึงเชิงความหมายด้วยส่วนขยาย pgvector ใน Supabase

การค้นหาข้อความเต็มและเวกเตอร์ฝังตัวด้วย pgvector เป็นบทเรียน Supabase Backend as a Service ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 3 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน 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” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Supabase Backend as a Service ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Supabase Backend as a Service มีบทเรียนทั้งหมด 3 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การค้นหาข้อความเต็มและเวกเตอร์ฝังตัวด้วย pgvector”

เพิ่มประสิทธิภาพฟีเจอร์การค้นหาด้วยการค้นหาข้อความเต็มของ Postgres และการค้นหาความคล้ายคลึงเชิงความหมายด้วยส่วนขยาย pgvector ใน Supabase คุณปฏิบัติ Supabase Backend as a Service ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Supabase Backend as a Service หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Supabase Backend as a Service บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 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