| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean createIndex(String tableName, String fieldName, String indexType, String indexParam){ |
| | | public boolean createIndex(String tableName, String fieldName, String indexType, String indexParam |
| | | , com.walker.support.milvus.MetricType myMetricType){ |
| | | this.checkConnection(); |
| | | IndexType INDEX_TYPE = null; |
| | | if(indexType.equals("IVF_FLAT")){ |
| | |
| | | INDEX_TYPE = IndexType.IVF_PQ; |
| | | } else if(indexType.equals("HNSW")){ |
| | | INDEX_TYPE = IndexType.HNSW; |
| | | } else if(indexType.equals("ANNOY")){ |
| | | INDEX_TYPE = IndexType.ANNOY; |
| | | } else if(indexType.equals("FLAT")){ |
| | | } |
| | | else if(indexType.equals("ANNOY")){ |
| | | // INDEX_TYPE = IndexType.ANNOY; |
| | | throw new UnsupportedOperationException("新版本已不支持:ANNOY"); |
| | | } |
| | | else if(indexType.equals("FLAT")){ |
| | | INDEX_TYPE = IndexType.FLAT; |
| | | } else if(indexType.equals("GPU_IVF_FLAT")){ |
| | | INDEX_TYPE = IndexType.GPU_IVF_FLAT; |
| | | } else if(indexType.equals("GPU_IVF_PQ")){ |
| | | INDEX_TYPE = IndexType.GPU_IVF_PQ; |
| | | } else if(indexType.equals("SCANN")){ |
| | | INDEX_TYPE = IndexType.SCANN; |
| | | } else { |
| | | throw new IllegalArgumentException("暂不支持其他索引类型:" + indexType); |
| | | } |
| | | |
| | | /** |
| | | * **欧氏距离 (L2)**: 主要运用于计算机视觉领域。 |
| | | * **内积 (IP)**: 主要运用于自然语言处理(NLP)领域。 |
| | | * @date 2024-03-26 |
| | | */ |
| | | CreateIndexParam.Builder builder = CreateIndexParam.newBuilder(); |
| | | builder.withCollectionName(tableName) |
| | | .withFieldName(fieldName) |
| | | .withIndexName(fieldName + "_index") |
| | | .withIndexType(INDEX_TYPE) |
| | | .withMetricType(MetricType.L2) |
| | | // .withMetricType(MetricType.L2) |
| | | .withExtraParam(indexParam) |
| | | .withSyncMode(false); |
| | | if(myMetricType == com.walker.support.milvus.MetricType.NLP){ |
| | | builder.withMetricType(MetricType.IP); |
| | | } else if(myMetricType == com.walker.support.milvus.MetricType.IMAGE){ |
| | | builder.withMetricType(MetricType.L2); |
| | | } else { |
| | | throw new UnsupportedOperationException("暂时不支持距离类型:" + myMetricType); |
| | | } |
| | | |
| | | R<RpcStatus> statusR = this.client.createIndex(builder.build()); |
| | | return checkStatusR(statusR); |