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

พื้นฐานตัวชี้วัดระยะห่างและการสร้างดัชนี

เรียนรู้ตัวชี้วัดระยะห่างที่กำหนดความคล้ายคลึงของเวกเตอร์ และดัชนีเพื่อนบ้านใกล้เคียงโดยประมาณที่ทำให้การค้นหาเวกเตอร์รวดเร็วในระดับใหญ่

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

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

Measuring Closeness

A vector DB finds vectors close to your query, but 'close' is defined by a distance metric — and the metric you pick shapes what counts as similar.

Euclidean Distance

Euclidean (L2) distance is the straight-line distance between two points: smaller means closer. Run the example to see it.

import math

def l2(a, b):
    return math.sqrt(sum((x-y)**2 for x, y in zip(a, b)))

print(round(l2([0,0],[3,4]), 1))

Cosine Similarity

Cosine similarity measures the angle between vectors, ignoring magnitude. It's the go-to for text embeddings, since direction carries the meaning.

import math

def cosine(a, b):
    dot = sum(x*y for x, y in zip(a, b))
    na = math.sqrt(sum(x*x for x in a))
    nb = math.sqrt(sum(y*y for y in b))
    return dot / (na*nb)

print(round(cosine([1,0],[1,1]), 3))

Dot Product

The dot product blends angle and magnitude. With normalized vectors it equals cosine similarity — which is why many systems normalize, then use dot product for speed.

Choosing a Metric

Match the metric to what your model was trained for: text usually cosine, normalized vectors dot product, some image or geo data Euclidean. A mismatch silently hurts results.

The Brute-Force Problem

Brute force — comparing the query to every stored vector — is exact but slow: millions of vectors mean millions of comparisons per query. It doesn't scale.

Approximate Nearest Neighbor

ANN indexes trade a sliver of accuracy for massive speed by cleverly skipping most candidates. Recall stays high while latency drops by orders of magnitude.

HNSW Indexes

HNSW builds a layered graph you navigate coarse to fine for excellent recall and speed — the default in many vector DBs, tunable via ef and M.

IVF Indexes

IVF clusters vectors into buckets and only searches the ones nearest your query. Fewer probes mean faster search, at a small accuracy cost.

The Recall-Speed Trade-off

Every ANN index exposes knobs that trade recall for speed. Searching more candidates raises both recall and latency. Tune to your accuracy target, then push speed.

Putting It Together

Putting it together: pick the right distance metric for your embeddings, then use an ANN index (HNSW or IVF) to query fast at scale, tuning the recall-speed knobs.

Quick Check

Test your understanding of metrics and indexes.

Recap

Recap: the core distance metrics (Euclidean, cosine, dot product) — text usually cosine — plus ANN indexes like HNSW and IVF that trade a little recall for big speed.

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

บทเรียน “พื้นฐานตัวชี้วัดระยะห่างและการสร้างดัชนี” ฟรีหรือไม่

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

คุณจะเรียนรู้อะไรในบทเรียน “พื้นฐานตัวชี้วัดระยะห่างและการสร้างดัชนี”

เรียนรู้ตัวชี้วัดระยะห่างที่กำหนดความคล้ายคลึงของเวกเตอร์ และดัชนีเพื่อนบ้านใกล้เคียงโดยประมาณที่ทำให้การค้นหาเวกเตอร์รวดเร็วในระดับใหญ่ คุณปฏิบัติ 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