เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การเปลี่ยน distance metric

โดยค่าเริ่มต้น Pinecone จะใช้ cosine similarity เป็น distance metric ในการคำนวณคะแนนความคล้ายคลึงระหว่างเวกเตอร์ ซึ่งใช้ในการค้นหาเวกเตอร์ที่ใกล้เคียงที่สุดเมื่อทำการ query นอกจากนี้ Pinecone ยังรองรับ distance metric อื่น ๆ ด้วย เช่น Euclidean distance และ dot product

การกำหนด distance metric จะทำตอนสร้าง index และไม่สามารถเปลี่ยนแปลงได้ในภายหลัง ในแบบฝึกหัดนี้ จะได้ฝึกสร้าง index ที่ใช้ dot product เป็น distance metric

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Vector Databases สำหรับ Embeddings ด้วย Pinecone

ดูคอร์ส

คำแนะนำการฝึกหัด

  • เริ่มต้นการเชื่อมต่อ Pinecone ด้วย API key ของคุณ
  • สร้าง index ใหม่ชื่อ "dotproduct-index" โดยใช้ dot product เป็น distance metric
  • แสดงรายการ index เพื่อยืนยันว่าสร้างสำเร็จและใช้ metric ที่ถูกต้อง

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Initialize the Pinecone client with your API key
pc = Pinecone(api_key="____")

# Create an index that uses the dot product distance metric
pc.create_index(
    name="____",
    dimension=1536,
    ____,
    spec=ServerlessSpec(
        cloud='aws',
        region='us-east-1'
    )
)

# Print a list of your indexes
print(____)
แก้ไขและรันโค้ด