常见索引对比
| 索引 | 特点 | 适用 |
|---|---|---|
| FLAT | 精确、无训练 | 小数据量与效果基线 |
| IVF_FLAT / IVF_SQ8 | 聚类加速、可量化压缩 | 百万级、内存可控 |
| HNSW | 图索引、低延迟高召回 | 在线问答主力场景 |
| DISKANN | 磁盘索引、内存占用低 | 亿级、内存受限 |
建 HNSW 索引并加载
建 HNSW 索引并加载
index_params = client.prepare_index_params()
index_params.add_index(field_name="vector", index_type="HNSW",
metric_type="COSINE",
params={"M": 16, "efConstruction": 200})
client.create_index("kb", index_params)
client.load_collection("kb") # 检索前需加载先用 FLAT 建立效果基线,再换近似索引对比召回与延迟;切换索引需重建。