IndexTest.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. package io.milvus.v2.service.index;
  20. import io.milvus.v2.BaseTest;
  21. import io.milvus.v2.common.IndexParam;
  22. import io.milvus.v2.service.index.request.CreateIndexReq;
  23. import io.milvus.v2.service.index.request.DescribeIndexReq;
  24. import io.milvus.v2.service.index.request.DropIndexReq;
  25. import io.milvus.v2.service.index.request.ListIndexesReq;
  26. import io.milvus.v2.service.index.response.DescribeIndexResp;
  27. import org.junit.jupiter.api.Test;
  28. import org.slf4j.Logger;
  29. import org.slf4j.LoggerFactory;
  30. import java.util.ArrayList;
  31. import java.util.List;
  32. class IndexTest extends BaseTest {
  33. Logger logger = LoggerFactory.getLogger(IndexTest.class);
  34. @Test
  35. void testCreateIndex() {
  36. // vector index
  37. IndexParam indexParam = IndexParam.builder()
  38. .metricType(IndexParam.MetricType.COSINE)
  39. .indexType(IndexParam.IndexType.AUTOINDEX)
  40. .fieldName("vector")
  41. .build();
  42. // scalar index
  43. IndexParam scalarIndexParam = IndexParam.builder()
  44. .indexType(IndexParam.IndexType.AUTOINDEX)
  45. .fieldName("age")
  46. .build();
  47. List<IndexParam> indexParams = new ArrayList<>();
  48. indexParams.add(indexParam);
  49. indexParams.add(scalarIndexParam);
  50. CreateIndexReq createIndexReq = CreateIndexReq.builder()
  51. .collectionName("test")
  52. .indexParams(indexParams)
  53. .build();
  54. client_v2.createIndex(createIndexReq);
  55. }
  56. @Test
  57. void testDescribeIndex() {
  58. DescribeIndexReq describeIndexReq = DescribeIndexReq.builder()
  59. .collectionName("test")
  60. .fieldName("vector")
  61. .build();
  62. DescribeIndexResp responseR = client_v2.describeIndex(describeIndexReq);
  63. logger.info(responseR.toString());
  64. }
  65. @Test
  66. void testDropIndex() {
  67. DropIndexReq dropIndexReq = DropIndexReq.builder()
  68. .collectionName("test")
  69. .fieldName("vector")
  70. .build();
  71. client_v2.dropIndex(dropIndexReq);
  72. }
  73. @Test
  74. void testListIndexes() {
  75. ListIndexesReq listIndexesReq = ListIndexesReq.builder()
  76. .collectionName("test")
  77. .build();
  78. List<String> indexNames = client_v2.listIndexes(listIndexesReq);
  79. logger.info(indexNames.toString());
  80. }
  81. }