Vector Databases: Pinecone, Weaviate & pgvector · บทเรียน

การค้นหาแบบผสมด้วยเวกเตอร์เบาบางและหนาแน่น

เรียนรู้ว่า Pinecone ผสานเวกเตอร์ความหมายแบบหนาแน่นกับเวกเตอร์คำสำคัญแบบเบาบางอย่างไร เพื่อสร้างการค้นหาแบบผสมที่ครอบคลุมทั้งความหมายและคำที่ตรงกัน

บทเรียน 4 จาก 413 ขั้นตอน

การค้นหาแบบผสมด้วยเวกเตอร์เบาบางและหนาแน่น เป็นบทเรียน Vector Databases: Pinecone, Weaviate & pgvector ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Vector Databases: Pinecone, Weaviate & pgvector และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Vector Databases: Pinecone, Weaviate & pgvector มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

The Limits of Dense-Only Search

Dense vectors capture meaning but can miss exact terms like product codes, names, or rare keywords. A user searching 'error E4012' may get semantically related but wrong results.

Hybrid search fixes this by adding keyword matching.

Dense vs Sparse Vectors

Two vector kinds:

  • Dense — a few hundred floats encoding semantic meaning
  • Sparse — mostly zeros, with weights only for present terms (like keyword scores)

Sparse vectors behave like classic keyword search.

What Sparse Vectors Look Like

A sparse vector is stored as indices and values for the non-zero terms.

sparse = {'indices': [10, 42, 77], 'values': [0.8, 0.5, 0.3]}
print('non-zero terms:', len(sparse['indices']))

Why Hybrid Wins

Hybrid search combines the strengths:

  • Dense handles synonyms and intent
  • Sparse guarantees exact-term matches
  • Together they boost recall and precision

Pinecone Hybrid Indexes

To use hybrid search in Pinecone, create a dotproduct index and upsert each record with both a dense values array and a sparse_values field. Queries supply both representations of the query.

Upserting a Hybrid Record

A record carries dense and sparse parts together.

record = {
  'id': 'doc1',
  'values': [0.1, 0.2, 0.3],
  'sparse_values': {'indices': [5, 9], 'values': [0.7, 0.4]},
  'metadata': {'title': 'Setup guide'}
}
print(record['id'], 'has', len(record['values']), 'dense dims')

The Alpha Weighting

Hybrid queries use an alpha parameter to weight dense vs sparse. alpha=1 is pure dense, alpha=0 is pure sparse. Tune it for your data.

def weight(dense_vec, sparse_vals, alpha):
    d = [v*alpha for v in dense_vec]
    s = [v*(1-alpha) for v in sparse_vals]
    return d, s

print(weight([1.0], [1.0], 0.7))

Generating Sparse Vectors

Sparse vectors come from keyword models like BM25 or learned sparse encoders (e.g. SPLADE). They map terms to weighted indices that Pinecone can match against stored records.

Tuning Alpha

The right alpha depends on your queries:

  • Keyword-heavy domains (codes, IDs) -> lower alpha
  • Natural-language questions -> higher alpha

Test on real queries and measure both recall and precision.

When to Use Hybrid

Reach for hybrid when exact terms matter: legal, medical, technical docs, or catalogs with SKUs. For purely conversational content, dense alone may be enough and simpler.

Bringing It Together

Hybrid search in Pinecone = a dotproduct index, records with dense and sparse values, queries supplying both, and a tuned alpha. It captures meaning and exact terms in one ranked result set.

Quick Check

Test your understanding of hybrid search.

Recap

You learned that hybrid search combines dense semantic vectors with sparse keyword vectors so Pinecone captures both meaning and exact terms. Use a dotproduct index, upsert both representations, and tune the alpha weighting to your query mix.

เริ่มต้นได้ฟรี

เรียนรู้ Vector Databases: Pinecone, Weaviate & pgvector ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
12
บทเรียน
48

คำถามที่พบบ่อย

บทเรียน “การค้นหาแบบผสมด้วยเวกเตอร์เบาบางและหนาแน่น” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การค้นหาแบบผสมด้วยเวกเตอร์เบาบางและหนาแน่น” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Vector Databases: Pinecone, Weaviate & pgvector ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Vector Databases: Pinecone, Weaviate & pgvector มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การค้นหาแบบผสมด้วยเวกเตอร์เบาบางและหนาแน่น”

เรียนรู้ว่า Pinecone ผสานเวกเตอร์ความหมายแบบหนาแน่นกับเวกเตอร์คำสำคัญแบบเบาบางอย่างไร เพื่อสร้างการค้นหาแบบผสมที่ครอบคลุมทั้งความหมายและคำที่ตรงกัน คุณปฏิบัติ Vector Databases: Pinecone, Weaviate & pgvector ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Vector Databases: Pinecone, Weaviate & pgvector หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Vector Databases: Pinecone, Weaviate & pgvector บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “การค้นหาแบบผสมด้วยเวกเตอร์เบาบางและหนาแน่น” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Vector Databases: Pinecone, Weaviate & pgvector นี้ได้ไหม

ได้ บทเรียน Vector Databases: Pinecone, Weaviate & pgvector ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การกรองด้วยเมทาดาทา
  2. การจัดการเนมสเปซ
  3. การอัปเดตและการลบแบบเรียลไทม์
  4. การค้นหาแบบผสมด้วยเวกเตอร์เบาบางและหนาแน่น
← กลับไปที่ Vector Databases: Pinecone, Weaviate & pgvector