用於嵌入式系統的向量資料庫

Introduction to Embeddings with the OpenAI API

Emmanuel Pire

Senior Software Engineer, DataCamp

現行做法的限制

  • 將所有嵌入載入記憶體(1536 個浮點數約 13kB/embedding
  • 每個新查詢都重新計算嵌入
  • 對每個嵌入計算餘弦距離並排序很慢,且線性擴展

一張圖示,顯示在沒有儲存方案下,每次查詢都要對文件與查詢做嵌入。

Introduction to Embeddings with the OpenAI API

向量資料庫

  • 已嵌入的文件會從向量資料庫中_儲存_與_查詢_

一張圖示,顯示使用向量資料庫儲存文件嵌入,並依嵌入後的查詢回傳結果給使用者。

Introduction to Embeddings with the OpenAI API

 

NoSQL 資料庫
  • 結構更彈性,可更快查詢

NoSQL 資料庫綱要範例,包括 key:value、文件型與圖形資料庫。

 

SQL/關聯式資料庫
  • 以資料表、列與欄的結構化資料

SQL(關聯式)資料庫中的資料表、欄與列。

Introduction to Embeddings with the OpenAI API

需要儲存的元件

 

  • 嵌入向量
  • 原始文字
  • 中繼資料
    • ID 與參照
    • 有助於篩選結果的額外資料

 

小撇步:不要把原始文字放在中繼資料裡!

向量資料庫圖示。

Introduction to Embeddings with the OpenAI API

向量資料庫全覽

多個熱門向量資料庫方案,依是否開源與是否為專用向量資料庫分類。

1 Image Credit: Yingjun Wu
Introduction to Embeddings with the OpenAI API

如何選擇合適方案?

 

  • 資料庫管理
    • 託管服務 → 成本較高但可減輕工作量
    • 自行管理 → 較便宜但需時間與專業
  • 開源或商用?
    • 開源 → 彈性高、成本效益佳
    • 商用 → 更佳支援、進階功能與法規遵循

 

  • 資料模型:你的資料型態是否適合特定資料庫?
  • 特定功能:你的情境是否仰賴特定功能,例如多模態儲存?

Chroma 標誌。

Introduction to Embeddings with the OpenAI API

一起來練習吧!

Introduction to Embeddings with the OpenAI API

Preparing Video For Download...