Pinecone 索引入門

使用 Pinecone 構建 AI 應用

James Chapman

Curriculum Manager, DataCamp

Pinecone 標誌

 

你將學到…

  • 建立索引並匯入向量
  • 擷取與查詢向量
  • 建立常見 AI 應用

 

→ 建置並「擴充」GenAI 應用

 

 

語意搜尋

使用 Pinecone 構建 AI 應用

索引

 

  • 儲存向量
  • 服務查詢與其他向量操作
  • 索引為每個向量包含紀錄中繼資料
  • 可建立多個索引

一個有四層抽屜的檔案櫃,每層有多個資料夾。

使用 Pinecone 構建 AI 應用

以 Pod 為基礎

包含多個索引的 pod。

  • 選擇硬體來建立索引 → pods
  • Pod 類型決定儲存容量、查詢延遲、查詢輸送量

無伺服器(Serverless)

儲存在雲端的索引。

  • 無需資源管理
  • 索引會自動擴縮
  • 在雲端執行並儲存在 blob
  • 較易使用且常見成本更低

本課將使用此方式

1 https://docs.pinecone.io/guides/indexes/understanding-indexes
使用 Pinecone 構建 AI 應用

建立 Pinecone API key

 

  1. 建立 Pinecone Starter 帳號 → pinecone.io
  2. 前往「API Keys」
  3. 複製你的 API key

Pinecone 首頁

Pinecone 的 API keys 頁面

使用 Pinecone 構建 AI 應用

建立無伺服器索引

from pinecone import Pinecone, ServerlessSpec


pc = Pinecone(api_key="API_KEY")
pc.create_index(
name='datacamp-index',
dimension=1536,
spec=ServerlessSpec(
cloud='aws', region='us-east-1'
)
)
使用 Pinecone 構建 AI 應用

檢查索引

pc.list_indexes()
{'indexes': [{'dimension': 1536,
              'host': 'datacamp-index-1eef0f4.svc.aped-4627-b74a.pinecone.io',
              'metric': 'cosine',
              'name': 'datacamp-index',
              'spec': {'serverless': {'cloud': 'aws', 'region': 'us-east-1'}},
              'status': {'ready': True, 'state': 'Ready'}}]}
使用 Pinecone 構建 AI 應用

一起來練習吧!

使用 Pinecone 構建 AI 應用

Preparing Video For Download...