中繼資料過濾

使用 Pinecone 構建 AI 應用

James Chapman

Curriculum Manager, DataCamp

中繼資料過濾

{
    "genre": "action",
    "year": 2020,
    "color": "blue",
    "fit": "straight",
    "price": 29.99,
    "is_jeans": true,
    "areas": ["London", "Kent", "Bath"]
}
  • 中繼資料可為 _字串_、_數字_、布林值,以及字串的 _清單_
  • 中繼資料過濾:可縮小搜尋空間並降低 查詢延遲
1 https://docs.pinecone.io/docs/metadata-filtering
使用 Pinecone 構建 AI 應用

中繼資料過濾

index.query(
    vector=[-0.250919762305275, ...],

filter={
"genre": {"$eq": "documentary"}, "year": 2019
},
top_k=1 )
1 https://docs.pinecone.io/docs/metadata-filtering
使用 Pinecone 構建 AI 應用

中繼資料過濾器

 

  • $eq - 等於(number、string、boolean)
  • $ne - 不等於(number、string、boolean)
  • $gt - 大於(number)
  • $gte - 大於等於(number)
  • $lt - 小於(number)
  • $lte - 小於等於(number)
  • $in - 在陣列中(string 或 number)
  • $nin - 不在陣列中(string 或 number)
1 https://docs.pinecone.io/docs/metadata-filtering
使用 Pinecone 構建 AI 應用

中繼資料過濾:大於

index.query(
    vector=[-0.250919762305275, ...],

filter={
"year": {"$gt": 2019},
},
top_k=1,
include_metadatas=True
)
{'matches': [{'id': '1', 'score': 0.0478537641,
              'values': [],
              'metadata': {'genre': 'action', 'year': 2020}}],
 'namespace': '',
 'usage': {'read_units': 5}}
使用 Pinecone 構建 AI 應用

一起來練習吧!

使用 Pinecone 構建 AI 應用

Preparing Video For Download...