更新与删除向量

使用 Pinecone 构建 AI 应用

James Chapman

Curriculum Manager, DataCamp

保持数据新鲜...

  • 保持数据始终_最新_
  • 优化查询性能
  • 维护数据完整性

数据从采集到使用、验证、更新或删除的生命周期。

使用 Pinecone 构建 AI 应用

更新向量值

index.fetch(ids=['1'])
{'namespace': '',
 'usage': {'read_units': 1},
 'vectors': {'1': {'id': '1',
                   'metadata': {"genre": "action", "year": 2023},
                   'values': [-0.0131468913, ...]}
            }
}
使用 Pinecone 构建 AI 应用

更新向量值

index.update(

id="1",
values=[0.370695321, ...]
)
  • 确保:列表长度 = 索引维度
1 https://docs.pinecone.io/docs/update-data
使用 Pinecone 构建 AI 应用

更新向量值

index.fetch(ids=['1'])
{'namespace': '',
 'usage': {'read_units': 1},
 'vectors': {'1': {'id': '1',
                   'metadata': {"genre": "action", "year": 2023},
                   'values': [0.370695321, ...]}
            }
}
使用 Pinecone 构建 AI 应用

更新向量元数据

index.update(
    id="1",
    set_metadata={"genre": "comedy", "rating": 5}
)
1 https://docs.pinecone.io/docs/update-data
使用 Pinecone 构建 AI 应用

更新向量元数据

index.fetch(ids=['1'])
{'namespace': '',
 'usage': {'read_units': 1},
 'vectors': {'1': {'id': '1',
                   'metadata': {"genre": "comedy", "year": 2023, "rating": 5},
                   'values': [0.370695321, ...]}
            }
}
使用 Pinecone 构建 AI 应用

同时更新向量值与元数据

index.update(
    id="1",
    values=[-0.31956, ...],
    set_metadata={"genre": "thriller", "ratings": 4}
)
1 https://docs.pinecone.io/docs/update-data
使用 Pinecone 构建 AI 应用

删除向量

index.delete(
    ids=["1", "2"]
)
1 https://docs.pinecone.io/docs/delete-data
使用 Pinecone 构建 AI 应用

按元数据删除向量

index.delete(
    filter={
        "genre": {"$eq": "action"},
    }
)
使用 Pinecone 构建 AI 应用

在命名空间内删除向量

index.delete(delete_all=True, namespace='namespace1')
  • 注意:同时会删除该命名空间!
1 https://docs.pinecone.io/docs/delete-data
使用 Pinecone 构建 AI 应用

Passons à la pratique !

使用 Pinecone 构建 AI 应用

Preparing Video For Download...