From 65c1714039bfe31b748e10ca5fb7c0b78a4829e5 Mon Sep 17 00:00:00 2001 From: shikeying <pxzsky@163.com> Date: 星期二, 26 三月 2024 18:06:36 +0800 Subject: [PATCH] 更新milvus库,添加测试方法 --- walker-support-milvus/src/main/java/com/walker/support/milvus/engine/DefaultOperateService.java | 32 +++++++++++++++++++++++++++----- 1 files changed, 27 insertions(+), 5 deletions(-) diff --git a/walker-support-milvus/src/main/java/com/walker/support/milvus/engine/DefaultOperateService.java b/walker-support-milvus/src/main/java/com/walker/support/milvus/engine/DefaultOperateService.java index d32c455..0247b14 100644 --- a/walker-support-milvus/src/main/java/com/walker/support/milvus/engine/DefaultOperateService.java +++ b/walker-support-milvus/src/main/java/com/walker/support/milvus/engine/DefaultOperateService.java @@ -154,7 +154,8 @@ } @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")){ @@ -165,22 +166,43 @@ 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)**鈥�: 涓昏杩愮敤浜庤嚜鐒惰瑷�澶勭悊锛圢LP锛夐鍩熴�� + * @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); -- Gitblit v1.9.1