java 操作 milvus 2.1.4

1. 确认 docker 运行的 milvus容器镜像版本情况:

2. pom 依赖:

        <dependency>
            <groupId>io.milvus</groupId>
            <artifactId>milvus-sdk-java</artifactId>
            <version>2.1.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

3. MilvusTest1.java:



import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.protobuf.ByteString;
import io.milvus.client.MilvusServiceClient;
import io.milvus.grpc.*;
import io.milvus.param.ConnectParam;
import io.milvus.param.MetricType;
import io.milvus.param.R;
import io.milvus.param.RpcStatus;
import io.milvus.param.collection.*;
import io.milvus.param.dml.DeleteParam;
import io.milvus.param.dml.InsertParam;
import io.milvus.param.dml.QueryParam;
import io.milvus.param.dml.SearchParam;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;

public class MilvusTest1 {


    private static final String MILVUS_IP = "127.0.0.1";
    private static final int MILVUS_PORT = 19530;

     /*
    使用 docker-compose 方式启动的 milvus 容器默认未开启登录校验,即不填写用户名和密码即可连接成功,开启登录校验,需要修改 milvus 容器内部的一个配置文件,可使用如下方式修改:
        1.  docker  cp xxxxxxxxxx:/milvus/configs/milvus.yaml ./  ( 其中 xxxxxxxxxx 是milvus容器的id )
        2. 打开 milvus.yaml,将内容中的 common.security.authorizationEnabled的值改为 true( 默认是 false )
        3. docker  cp ./milvus.yaml xxxxxxxxxx:/milvus/configs
     */
    private static final String USERNAME = "root";
    private static final String PASSWORD = "Milvus";

    private static final int VECTOR_DIMENSION = 256;

    /**
     * 创建  MilvusServiceClient
     * @return
     */
    private static MilvusServiceClient getMilvusServiceClient(){
        ConnectParam connectParam = ConnectParam.newBuilder()
                                                .withHost( MILVUS_IP )
                                                .withPort( MILVUS_PORT )
                                                .withAuthorization( USERNAME,PASSWORD )
                                                .build();
        connectParam.toString();
        MilvusServiceClient milvusServiceClient = new MilvusServiceClient(connectParam);
        return milvusServiceClient;
    }

    private static boolean existCollection(String collectionName){
        MilvusServiceClient milvusClient = getMilvusServiceClient();
        HasCollectionParam hasCollectionParam = HasCollectionParam.newBuilder()
                                                                    .withCollectionName(collectionName)
                                                                    .build();
        R<Boolean> response = milvusClient.hasCollection( hasCollectionParam );
        Integer status = response.getStatus();
        Boolean data = response.getData();
        System.out.println( collectionName + ":status = " + status + ",data = " + data );
        return false;
    }

    //创建集合
    private static void creatCollection(String collectionName){
        MilvusServiceClient milvusClient = getMilvusServiceClient();
        FieldType featureId = FieldType.newBuilder()
                .withName("id")
                .withDescription("主键id")
                .withDataType(DataType.Int64)
                .withPrimaryKey(true)
                .withAutoID(false)
                .build();
        FieldType materielId = FieldType.newBuilder()
                .withName("materiel_id")
                .withDescription("物料id")
                .withDataType(DataType.Int64)
                .build();
        FieldType colorPosition = FieldType.newBuilder()
                .withName(PushMaterielsConfig.Field.COLOR_POSITION)
                .withDescription("特征值")
                .withDataType(DataType.FloatVector)
                .withDimension(PushMaterielsConfig.FEATURE_DIM)
                .build();
        FieldType materielTypeId = FieldType.newBuilder()
                .withName( "materiel_type_id" )
                .withDescription("物料类型id")
                .withDataType(DataType.Int64)
                .build();

        CreateCollectionParam createCollectionReq = CreateCollectionParam.newBuilder()
                .withCollectionName(collectionName)
                .withDescription("特征集合")
                //.withShardsNum(PushMaterielsConfig.SHARDS_NUM)
                .addFieldType(featureId)
                .addFieldType(materielId)
                .addFieldType(colorPosition)
                .addFieldType(materielTypeId)
                .build();

        R<RpcStatus> response = milvusClient.createCollection(createCollectionReq);
        System.out.println(PushMaterielsConfig.COLLECTION_NAME+"是否成功创建集合——>>"+response.getStatus());
    }


    //数据插入
    public static void insertDataTo(String collectionName,int insertCount,List<String> imgNameList,List<String> matNameList ) {
        List<List<Float>> imageVectors = new ArrayList<>();

        for (int i = 0; i < insertCount; i++) {
            List<Float> floatList = buildRandomFloatArrayList(VECTOR_DIMENSION);
            imageVectors.add( floatList );
        }
        List<InsertParam.Field> fields = new ArrayList<>();
        // fields.add(new InsertParam.Field( "title_vector", DataType.FloatVector, titleVectors ) );
        // fields.add(new InsertParam.Field( "title", DataType.String, titles ) );
        fields.add(new InsertParam.Field( "image_vector", imageVectors ) );
        fields.add(new InsertParam.Field( "img_name", imgNameList ) );
        fields.add(new InsertParam.Field( "mat_name", matNameList ) );

        insert(collectionName,fields);
    }

    private static String buildRandomTitle() {
        String title = UUID.randomUUID().toString().replaceAll("-", "");
        System.out.println( title );
        return title;
    }

    private static List<Float> buildRandomFloatArrayList(int size) {
        if( size <= 0 ){
            return null;
        }
        Random random = new Random();
        List<Float> floatList = new ArrayList<>();
        BigDecimal one_thousand = BigDecimal.valueOf(1000d);
        for (int i = 0; i < size; i++) {
            float v = one_thousand.multiply(BigDecimal.valueOf(random.nextDouble())).setScale(3, RoundingMode.HALF_UP).floatValue();
            floatList.add( v );
        }
        System.out.println( floatList );
        return floatList;
    }

    /**
     * 插入数据
     * @param collectionName
     * @param fields
     * @return
     */
    public static void insert(String collectionName, List<InsertParam.Field> fields ){
        MilvusServiceClient milvusClient = getMilvusServiceClient();
        //插入
        InsertParam insertParam = InsertParam.newBuilder()
                                                .withCollectionName(collectionName)
                                                //.withPartitionName(partitionName)
                                                .withFields(fields)
                                                .build();
        R<MutationResult> insert = milvusClient.insert(insertParam);
        Integer status = insert.getStatus();
        Exception exception = insert.getException();
        MutationResult data = insert.getData();
        if( data == null ){
            System.out.println( exception.getMessage() );
            return;
        }
        List<Long> ids = data.getIDs().getIntId().getDataList();
        System.out.println();
        System.out.println();
        System.out.println();
        for( Long id:ids ){
            System.out.println( id );
        }
        System.out.println();
        System.out.println();
        System.out.println();


        System.out.println("插入 " + data.getInsertCnt() + " 行");
        System.out.println( "status = " + status );
        if( exception != null ){
            System.out.println( "exception = " + exception.getMessage() );
            System.out.println( "message = " + insert.getMessage() );
        }
    }

    /**
     * 加载集合到内存( 必须首先加载集合到内存,否则查询报错 "collection:tb_article or partition:[] not loaded into memory when search" )
     * @param collectionName
     */
    private static void loadCollectionByName( String collectionName ){
        if( collectionName == null ){
            return;
        }
        MilvusServiceClient milvusServiceClient = getMilvusServiceClient();
        LoadCollectionParam loadCollectionParam = LoadCollectionParam.newBuilder()
                                                                        .withCollectionName(collectionName)
                                                                        .build();
        R<RpcStatus> response = milvusServiceClient.loadCollection(loadCollectionParam);
        handleRpcStatus( response );
    }

    private static void  handleRpcStatus( R<RpcStatus> response ){
        if( response == null ){
            return;
        }
        int status = response.getStatus();
        if( status == 0 ){
            System.out.println( "操作成功" );
            return;
        }
        Exception exception = response.getException();
        System.err.println( "操作失败( status = " + status + " )");
        if( exception == null ){
            return;
        }
        System.err.println( response.getMessage() );
        exception.printStackTrace();
    }

    /**
     * 从内存中释放集合
     * */
    public static void releaseCollection(String collectionName) {
        MilvusServiceClient milvusServiceClient = getMilvusServiceClient();

        ReleaseCollectionParam releaseCollectionParam = ReleaseCollectionParam.newBuilder()
                                                                                .withCollectionName(collectionName)
                                                                                .build();

        R<RpcStatus> response = milvusServiceClient.releaseCollection( releaseCollectionParam );
        handleRpcStatus( response );
    }

    public static List<MaterialMilvusImageVO> search( String collectionName,List<Float> floatList ,int topK){
        if( collectionName == null || floatList == null || floatList.size() != VECTOR_DIMENSION ){
            return null;
        }
        MilvusServiceClient milvusServiceClient = getMilvusServiceClient();

        List<String> outFields = new ArrayList<>();
        outFields.add( "id" );
        outFields.add( "img_name" );
        outFields.add( "mat_name" );

        List<List<Float>> vectors = new ArrayList<>();
        vectors.add( floatList );
        SearchParam searchParam = SearchParam.newBuilder()
                                            .withCollectionName(collectionName)
                                            .withTopK( topK )
                                            .withMetricType( MetricType.L2 )
                                            .withVectorFieldName("image_vector")
                                            .withVectors( vectors )
                                            .withOutFields( outFields )
                                            .withExpr( "" )
                                            // .withParams( "xxxx" )
                                            .withParams( "{\n" +
                                                            "\"params\": \"{\\\"nprobe\\\":1,\\\"round_decimal\\\":-1}\",\n" +
                                                            "\"anns_field\": \"image_vector\",\n" +
                                                            "\"topk\": "+ topK +",\n" +
                                                            "\"metric_type\": \"L2\",\n" +
                                                            "\"round_decimal\": -1\n" +
                                                        "}" )
                                            .build();
        R<SearchResults> response = milvusServiceClient.search(searchParam);
        int status = response.getStatus();
        if( status != 0 ){
            System.err.println( "search 失败( status = " + status + " )" );
            Exception exception = response.getException();
            if( exception != null ){
                String message = response.getMessage();
                System.out.println( "message = " + message );
                exception.printStackTrace();
            }
            return null;
        }
        System.out.println( "search 成功" );
        SearchResults data = response.getData();
        if( data == null ){
            return null;
        }
        SearchResultData results = data.getResults();
        int scoresCount = results.getScoresCount();

        List<MaterialMilvusImageVO> imageVOs = new ArrayList<>();

        FieldData fieldsData_id = results.getFieldsData(0);
        FieldData fieldsData_imgName = results.getFieldsData(1);
        FieldData fieldsData_matName = results.getFieldsData(2);

        LongArray ids = fieldsData_id.getScalars().getLongData();
        StringArray imgNames = fieldsData_imgName.getScalars().getStringData();
        StringArray matNames = fieldsData_matName.getScalars().getStringData();

        for (int i = 0; i < scoresCount; i++) {
            float scores = results.getScores(i);
            long id = ids.getData(i);
            String imgName = imgNames.getData(i);
            String matName = matNames.getData(i);

            MaterialMilvusImageVO imageVO = new MaterialMilvusImageVO();
            imageVO.setScores( scores );
            imageVO.setId( id );
            imageVO.setImgName( imgName );
            imageVO.setMatName( matName );
            imageVOs.add( imageVO );
        }
        return imageVOs;
    }

    private static List<Float> jsonArray2FloatList(JSONArray jsonArray) {
        if( jsonArray == null || jsonArray.size() == 0 ){
            return null;
        }
        int size = jsonArray.size();
        List<Float> floatList = new ArrayList<Float>();
        for (int i = 0; i < size; i++) {
            Float value = jsonArray.getFloat(i);
            floatList.add( value );
        }
        return floatList;
    }

    public static void searchTest( String collectionName ){
        // JSONArray array = JSONArray.parseArray("[720.665, 758.783, 831.477, 854.1, 597.977, 913.809, 659.829, 18.985, 852.756, 111.971, 596.902, 563.502, 234.051, 567.567, 140.383, 924.133, 829.13, 988.017, 691.144, 262.374, 970.751, 118.709, 774.637, 143.978, 613.916, 501.722, 200.533, 691.481, 991.008, 82.699, 591.095, 360.414, 417.625, 465.253, 537.802, 45.303, 966.211, 808.509, 756.147, 308.451, 350.507, 590.982, 0.121, 142.657, 771.119, 722.743, 170.707, 828.464, 660.933, 777.875, 6.887, 127.168, 238.876, 440.523, 982.933, 262.739, 531.455, 610.351, 552.415, 888.992, 53.779, 997.045, 677.183, 512.721, 655.2, 448.508, 658.687, 649.202, 129.465, 703.703, 649.351, 323.384, 65.253, 738.626, 863.322, 398.229, 70.156, 382.692, 428.757, 611.107, 939.694, 422.846, 27.923, 129.785, 562.639, 984.002, 956.735, 901.485, 354.926, 576.952, 1.945, 61.654, 796.625, 838.696, 582.076, 193.462, 209.974, 655.13, 927.256, 284.777, 261.139, 52.392, 683.495, 816.206, 794.394, 970.637, 218.536, 532.017, 514.615, 792.845, 79.253, 95.126, 722.457, 291.282, 504.682, 8.026, 776.332, 475.541, 634.123, 893.436, 206.254, 678.608, 66.354, 471.613, 436.861, 101.206, 723.824, 345.681]");
        // JSONArray array = JSONArray.parseArray("[887.7130126953125,582.594970703125,362.6090087890625,322.5509948730469,400.1929931640625,934.3790283203125,55.89699935913086,595.0859985351562,763.9600219726562,70.4489974975586,388.57501220703125,72.06099700927734,654.4879760742188,914.051025390625,36.4739990234375,700.8900146484375,344.0140075683594,320.7019958496094,840.7139892578125,84.53900146484375,163.5030059814453,918.593017578125,696.1790161132812,951.6420288085938,562.447021484375,152.7689971923828,458.2380065917969,264.114990234375,80.23600006103516,680.0590209960938,631.1799926757812,578.4970092773438,512.5880126953125,583.0670166015625,837.1630249023438,489.1789855957031,307.4800109863281,224.04800415039062,581.0999755859375,724.8469848632812,757.2730102539062,943.2869873046875,624.72802734375,743.85302734375,867.1829833984375,221.64999389648438,362.2430114746094,479.9320068359375,874.9860229492188,373.239990234375,950.2050170898438,226.57200622558594,272.8059997558594,311.6669921875,586.031982421875,516.4990234375,839.0880126953125,442.1809997558594,252.25799560546875,252.18800354003906,627.3159790039062,272.0159912109375,447.82000732421875,273.9389953613281,77.75399780273438,902.5150146484375,912.9970092773438,13.991000175476074,419.49700927734375,169.21800231933594,121.22899627685547,878.3060302734375,312.3059997558594,829.801025390625,358.8900146484375,522.0679931640625,241.21099853515625,864.8870239257812,543.1820068359375,240.61099243164062,521.572021484375,652.947021484375,538.7000122070312,284.39300537109375,898.2739868164062,508.11700439453125,624.77099609375,24.81100082397461,629.948974609375,828.5139770507812,938.5770263671875,547.0609741210938,637.6119995117188,892.6719970703125,173.12100219726562,426.8949890136719,766.8049926757812,163.02699279785156,544.4879760742188,160.07699584960938,463.3340148925781,807.89697265625,59.422000885009766,956.4660034179688,194.8990020751953,37.20600128173828,412.1260070800781,385.0920104980469,764.4030151367188,762.2429809570312,418.2550048828125,662.2429809570312,255.45399475097656,36.01499938964844,754.4569702148438,211.50799560546875,726.5339965820312,708.322021484375,913.39697265625,492.8659973144531,927.5560302734375,738.4450073242188,707.06298828125,997.344970703125,250.9969940185547,648.3900146484375,355.2460021972656,734.427978515625]");
        JSONArray array = JSONArray.parseArray("[448.4100036621094,979.3410034179688,66.54499816894531,993.3980102539062,38.8380012512207,599.7849731445312,960.1179809570312,301.9750061035156,50.95899963378906,581.3389892578125,130.75,238.89500427246094,122.23899841308594,750.6589965820312,149.5780029296875,357.802001953125,730.9910278320312,952.2589721679688,203.71099853515625,33.452999114990234,494.2099914550781,470.4779968261719,818.3170166015625,515.3560180664062,286.39599609375,376.0419921875,636.7769775390625,713.02001953125,130.31900024414062,100.96600341796875,729.8670043945312,868.6270141601562,46.03300094604492,757.4639892578125,655.9400024414062,625.4429931640625,561.06298828125,459.656005859375,26.284000396728516,384.10101318359375,382.50799560546875,181.34500122070312,643.302001953125,253.8990020751953,810.947021484375,488.72601318359375,373.9169921875,352.5870056152344,836.343017578125,823.864990234375,796.5440063476562,685.5980224609375,497.7799987792969,882.9019775390625,317.23199462890625,344.52801513671875,11.690999984741211,32.39500045776367,889.030029296875,304.6679992675781,377.3489990234375,637.8259887695312,688.3690185546875,672.6900024414062,653.7520141601562,640.2630004882812,103.22699737548828,838.1380004882812,868.6160278320312,710.3040161132812,170.0749969482422,616.1519775390625,568.051025390625,832.8369750976562,160.06900024414062,133.9010009765625,344.6090087890625,231.84300231933594,359.6809997558594,909.4829711914062,291.7200012207031,131.3560028076172,216.95399475097656,299.5899963378906,224.1490020751953,966.8699951171875,931.7670288085938,251.0330047607422,676.9630126953125,310.89801025390625,256.99798583984375,81.25199890136719,149.5780029296875,957.0490112304688,747.1790161132812,834.2260131835938,796.8380126953125,318.8999938964844,942.2269897460938,610.7440185546875,785.6409912109375,543.1079711914062,6.054999828338623,155.77699279785156,833.5260009765625,510.6300048828125,153.3489990234375,900.7420043945312,24.680999755859375,205.56100463867188,792.510009765625,604.7249755859375,859.239990234375,768.0289916992188,688.7659912109375,716.280029296875,633.2969970703125,915.7589721679688,608.6400146484375,586.2000122070312,669.927978515625,318.3080139160156,845.4879760742188,701.7139892578125,625.6320190429688,938.6530151367188,745.5040283203125,183.82000732421875,81.92500305175781,318.7340087890625,854.593994140625,892.0390014648438,898.4349975585938,278.6889953613281,588.7340087890625,614.6380004882812,351.7170104980469,523.9829711914062,393.9070129394531,987.4310302734375,913.0609741210938,210.2310028076172,206.43800354003906,980.5269775390625,628.9710083007812,602.4910278320312,650.531982421875,19.959999084472656,459.56201171875,583.9320068359375,817.0360107421875,69.92400360107422,602.9769897460938,918.1920166015625,655.9199829101562,291.3420104980469,788.0349731445312,850.4459838867188,984.7119750976562,213.83700561523438,752.676025390625,844.0549926757812,866.0999755859375,710.6680297851562,642.3569946289062,992.8939819335938,640.1060180664062,450.0119934082031,860.4130249023438,923.8280029296875,209.76400756835938,910.9949951171875,981.5,809.4849853515625,273.9289855957031,499.177001953125,699.5859985351562,448.39599609375,76.81999969482422,773.718017578125,423.5539855957031,237.71099853515625,901.1439819335938,307.2650146484375,56.3380012512207,263.1549987792969,970.1110229492188,239.61599731445312,697.6199951171875,661.5020141601562,643.375,157.5189971923828,495.44500732421875,872.8079833984375,792.927978515625,535.4979858398438,638.7429809570312,392.7669982910156,27.187000274658203,606.3930053710938,530.572021484375,159.99600219726562,994.9829711914062,195.33200073242188,511.02099609375,768.7119750976562,345.9179992675781,747.1480102539062,109.03600311279297,284.1619873046875,49.49800109863281,504.7860107421875,694.0650024414062,556.3579711914062,682.6950073242188,555.052001953125,571.2420043945312,577.06201171875,984.0700073242188,248.06399536132812,17.948999404907227,605.6409912109375,442.302001953125,318.0899963378906,494.9429931640625,501.32000732421875,937.9580078125,885.9660034179688,281.8219909667969,942.5269775390625,489.5570068359375,407.093994140625,84.48899841308594,988.4450073242188,968.4609985351562,544.06201171875,741.3280029296875,743.530029296875,241.8509979248047,889.1909790039062,15.206999778747559,722.7039794921875,579.0289916992188,439.8940124511719,599.989013671875,883.0449829101562,313.5,738.4819946289062,893.0850219726562,187.26699829101562,691.7789916992188,628.1099853515625,789.7230224609375,994.9010009765625,559.5830078125,647.8560180664062]");

        List<Float> floatList = jsonArray2FloatList( array );
        List<MaterialMilvusImageVO> imageVOS = search(collectionName, floatList, 10);
        if( imageVOS == null ){
            return;
        }
        for ( MaterialMilvusImageVO imageVO:imageVOS ){
            Long id = imageVO.getId();
            Float scores = imageVO.getScores();
            String imgName = imageVO.getImgName();
            String matName = imageVO.getMatName();
            System.out.println( id + " \t "+ scores +" \t "+ imgName +" \t " + matName );
        }
    }

    public static void insertTest( String collectionName ){
        int insertCount = 3;

        List<String> imgNameList = new ArrayList<>();
        imgNameList.add( "西瓜01" );
        imgNameList.add( "西瓜02" );
        imgNameList.add( "西瓜03" );

        List<String> matNameList = new ArrayList<>();
        matNameList.add( "西瓜" );
        matNameList.add( "西瓜" );
        matNameList.add( "西瓜" );

        insertDataTo( collectionName,insertCount,imgNameList,matNameList );
    }

    private static void deleteTest( String collectionName,List<Long> ids ){
        if( ids == null || ids.size() == 0 ){
            return;
        }
        /*String expr = "{" +
                "\"expr\": \"id in " + JSONObject.toJSONString( ids ) + "\"" +
                "}";*/
        String expr = "id in " + JSONObject.toJSONString( ids );
        System.out.println();
        System.out.println( expr );
        System.out.println();
        DeleteParam deleteParam = DeleteParam.newBuilder()
                                    .withCollectionName(collectionName)
                                    .withExpr( expr )
                                    .build();
        R<MutationResult> response = getMilvusServiceClient().delete(deleteParam);
        if( response == null ){
            System.err.println( "从 milvus 中删除记录失败( ids = " + JSONObject.toJSONString( ids ) + " ) cause response is empty" );
            return;
        }
        Integer status = response.getStatus();
        if( status == 0 ){
            System.out.println( "删除成功" );
            return;
        }
        Exception e = response.getException();
        if( e != null ){
            System.err.println( "从 milbus 中删除记录失败( ids = " + JSONObject.toJSONString( ids ) + " ) cause " + e.getMessage() );
        }
    }

    public static void main(String[] args) throws InterruptedException {

        // existCollection( "tb_article" );
        // existCollection( "tb_material_image" );
        // existCollection( "tb_material_image" );
        // existCollection( "xxx" );

        // creatCollection();
        // existCollection( "tb_article" );

        // creatCollection( "tb_materiel_xxx2" );

        // loadCollectionByName( collectionName );
        // releaseCollection( collectionName );
        // searchTest( "tb_material_image" );

        // id = 450704941225082936
        //      450704941225082937
        //      450704941225082938
        // insertTest( "tb_material_image" );

        queryTest( "tb_material_image" );
    }

    private static void queryTest(String collectionName) {
        QueryParam queryParam = QueryParam.newBuilder().withCollectionName(collectionName)
                                                        .addOutField("id")
                                                        .addOutField("image_vector")
                                                        .addOutField("mat_name")
                                                        .addOutField("img_name")
                                                        .withExpr("id >= 111")
                                                        .build();
        R<QueryResults> response = getMilvusServiceClient().query(queryParam);
        Integer status = response.getStatus();
        if( status != 0 ){
            System.err.println( "查询失败,cause " + response.getException().getMessage() );
            return;
        }
        System.out.println( "查询成功!" );

        QueryResults queryResults = response.getData();
        List<Long> ids = queryResults.getFieldsData(0).getScalars().getLongData().getDataList();
        List<Float> imageVectors = queryResults.getFieldsData(1).getVectors().getFloatVector().getDataList();
        List<String> matNames = queryResults.getFieldsData(2).getScalars().getStringData().getDataList();
        List<String> imgNames = queryResults.getFieldsData(3).getScalars().getStringData().getDataList();
        int size = ids.size();
        int dimension = 256;
        int index_start = 0;
        for (int i = 0; i < size; i++) {
            Long id = ids.get(i);
            int index_end = index_start + dimension;
            List<Float> imageVector = imageVectors.subList(index_start, index_end);
            String matName = matNames.get(i);
            String imgName = imgNames.get(i);
            System.out.println( i + ":" +id + " \t "+ matName +" \t " + imgName + " \t " + imageVector.size() + ":" + imageVector );
            index_start += dimension;
        }
    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/754725.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【秋招突围】2024届秋招笔试-科大笔试题-01-三语言题解(Java/Cpp/Python)

&#x1f36d; 大家好这里是清隆学长 &#xff0c;一枚热爱算法的程序员 ✨ 本系计划跟新各公司春秋招的笔试题 &#x1f4bb; ACM银牌&#x1f948;| 多次AK大厂笔试 &#xff5c; 编程一对一辅导 &#x1f44f; 感谢大家的订阅➕ 和 喜欢&#x1f497; 文章目录 &#x1f4d6…

在Tomcat中部署war包

1、准备war包 确保已经有一个有效的war包&#xff0c;该war包包含了web应用程序的所有内容&#xff1b; 2、停止tomcat服务器 在部署之前&#xff0c;确保tomcat服务器已经停止&#xff0c;进入tomcat的配置目录执行命令&#xff1a;[路径]/tomcat/conf&#xff1b; 在Linux…

前端vite+vue3——利用环境变量和路由区分h5、pc模块打包(从0到1)

⭐前言 大家好&#xff0c;我是yma16&#xff0c;本文分享 前端vitevue3——利用环境变量和路由对前端区分h5和pc模块打包&#xff08;从0到1&#xff09;。 背景&#xff1a; 前端本地开发pc和h5的项目&#xff0c;发布时需要区分开h5和pc的页面 vite Vite 通过在一开始将应…

论文阅读--《FourierGNN:从纯图的角度重新思考多元时间序列预测》

Yi K, Zhang Q, Fan W, et al. FourierGNN: Rethinking multivariate time series forecasting from a pure graph perspective[J]. Advances in Neural Information Processing Systems, 2024, 36. 本次介绍的文章来自NeurIPS 2023&#xff0c;关于多变量时间序列的预测 摘要…

CocosCreator构建IOS的wwise教程

CocosCreator构建IOS教程 添加wwise教程: 1.添加include 2.添加SoundEngine 3.添加Profile-iphoneos下面lib下面的.a 4.导入js调用C++的文件 5.导入这些文件 6.初始化ios绝对路径和TTS语音合成对象 6.获得根目录绝对路径,加载pck需要找到绝对路径。怎么找绝对路径? #impor…

现如今软考通过率真的很低吗?

刚开始机考&#xff0c;10个人中有3个人表示想要尝试考试&#xff0c;这样通过率能高吗&#xff1f;就拿PMP证书来说吧&#xff0c;一下子就得花费三千多块&#xff0c;有几个人会轻易去尝试呢&#xff1f; 说到底&#xff0c;考试的难度是一个方面&#xff0c;考试的成本低是…

vue3日历选择器

倒叙日历&#xff1a; <template><div class"date-picker"><div class"column" wheel"onYearScroll"><div v-for"(year, index) in displayedYears" :key"index" :class"{current: year current…

深度解析RocketMq源码-消费者索引ConsumeQueue

1.绪论 rocketmq的broker中关于消息持久化的组件主要包含三个&#xff0c;分别是&#xff1a;持久化消息到文件中的组件commitLog&#xff1b;根据消息key索引commitLog日志的indexFile&#xff1b;消费者根据topic和queueId查询commitLog日志的consumeQueue。前面已经介绍com…

Profibus协议转profinet协议网关模块连接电机保护器与PLC通讯

一、背景 工业通讯中常见的协议有&#xff1a;Modbus协议&#xff0c;ModbusTCP协议&#xff0c;Profinet协议&#xff0c;Profibus协议&#xff0c;Profibus DP协议&#xff0c;EtherCAT协议&#xff0c;EtherNET协议等在现代工业控制系统中具有重要的角色。而Profibus协议转…

智慧数据中心可视化:高效管理与直观监控的未来

随着数据中心的规模和复杂性不断增加&#xff0c;传统管理方式难以满足需求。智慧数据中心通过图扑可视化实现实时数据监控和智能分析&#xff0c;将复杂的基础设施直观呈现&#xff0c;极大提升了运维效率、故障排查速度和资源优化能力&#xff0c;为企业提供现代化、智能化的…

mac app应用程序如何自定义图标, 更换.app为自己喜欢的图标或者图片 详细图文讲解

在mac系统中&#xff0c;我们可以对任何的app应用程序更换或者自定义图标&#xff0c; 这个图标可以是拥有的app的图标&#xff0c;或者是你自己制作的 x.icns 图标 或者是 任意的图片&#xff0c; 建议大小512x512 。 自定义图标方法如下&#xff1a; 1. 更换为已有app的图标…

词向量模型

文章目录 RNN词向量模型模型整体框架训练数据构建CBOW与Skip-gram模型负采样 RNN 卷积神经网络&#xff08;CNN&#xff09;主要应用计算机视觉&#xff0c;而递归神经网络&#xff08;RNN&#xff09;主要应用于自然语言处理。 递归神经网络会涉及处理之前所有的数据&#x…

Paragon NTFS与Tuxera NTFS有何区别 Mac NTFS 磁盘读写工具选哪个好

macOS系统虽然以稳定、安全系数高等优点著称&#xff0c;但因其封闭性&#xff0c;不能对NTFS格式磁盘写入数据常被人们诟病。优质的解决方案是使用磁盘管理软件Paragon NTFS for Mac&#xff08;点击获取激活码&#xff09;和Tuxera NTFS&#xff08;点击获取激活码&#xff0…

51单片机STC89C52RC——11.1 蜂鸣器播放音乐

目录 目的/效果 一&#xff0c;STC单片机模块 二&#xff0c;蜂鸣器 2.1 介绍 2.2 板子位置电路图 2.3 发声原理 2.4 音符和频率 三&#xff0c;创建Keil项目 四&#xff0c;代码 4.1 乐谱代码 4.1.1 《义勇军进行曲》 4.1.2 《天空之城》 4.1.3 《小美满》 4.1.…

2024年湖南建筑安全员考试题库,精准题库。

31.安全考核的对象应包括施工企业各管理层的&#xff08;&#xff09;、相关职能部门及岗位和工程项目参建人员。 A.技术负责人 B.安全负责人 C.主要负责人 D.第一负责人 答案&#xff1a;C 32.安全防护设施应标准化、定型化、&#xff08;&#xff09;。 A.规范化 B.工…

TFMath Caculator:一个简单的Java AWT计算器

目录 背景&#xff1a; 代码展示: 代码解析: 输出结果: 总结: 背景&#xff1a; 使用Java AWT(Abstract Window Toolkit)库创建的简单计算器应用-TFMath Calculator。这个计算器允许用户输入两个数字&#xff0c;点击号按钮后&#xff0c;计算器会计算这两个数字的和&…

【Redis四】主从复制、哨兵以及Cluster集群

目录 一.主从复制、哨兵、集群的区别 二.Redis主从复制 1.作用 2.原理 3.流程 三.搭建Redis 主从复制 1.源码编译安装以及配置文件修改 1.1.修改 Redis 配置文件&#xff08;Slave节点操作&#xff09; 2.验证主从复制 2.1.在Master节点上看日志 2.2.在Master节点上…

混凝土搅拌站中的智能化系统应用

随着科技的飞速发展&#xff0c;混凝土搅拌站已经进入了现代化、智能化的新时代。现代自动化、智能化技术的应用&#xff0c;使得混凝土搅拌站更加高效、准确、可靠&#xff0c;同时也提高了生产效率和质量。本文将带你深入探索混凝土搅拌站中运用到现代自动化、智能化的方方面…

k8s架构设计思想

1.谷歌borg云计算管理平台 一类&#xff1a;infrastucture platform software 另一类&#xff1a;borg为主的非虚拟化技术&#xff0c;调度进程 核心是轻量级作业调度&#xff0c;不是做虚拟化/云平台的 borg本身用了一些容器技术 生产业务product workload要求高可用&#xf…

第三节:如何理解Spring的两个特性IOC和AOP(自学Spring boot 3.x第一天)

大家好&#xff0c;我是网创有方&#xff0c;接下来教大家如何理解Spring的两个特性IOC和AOP。本节有点难&#xff0c;大家多理解。 IOC&#xff08;控制反转&#xff09; 定义与核心思想&#xff1a; IOC&#xff0c;全称Inversion of Control&#xff0c;即控制反转。 其核…