Index.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.client;
  20. import javax.annotation.Nonnull;
  21. /** Represents an index containing <code>indexType</code> and <code>nList</code> */
  22. public class Index {
  23. private final String collectionName;
  24. private final IndexType indexType;
  25. private final String paramsInJson;
  26. private Index(@Nonnull Builder builder) {
  27. this.collectionName = builder.collectionName;
  28. this.indexType = builder.indexType;
  29. this.paramsInJson = builder.paramsInJson;
  30. }
  31. public String getCollectionName() {
  32. return collectionName;
  33. }
  34. public IndexType getIndexType() {
  35. return indexType;
  36. }
  37. public String getParamsInJson() {
  38. return paramsInJson;
  39. }
  40. @Override
  41. public String toString() {
  42. return "Index {"
  43. + "collectionName="
  44. + collectionName
  45. + ", indexType="
  46. + indexType
  47. + ", params="
  48. + paramsInJson
  49. + '}';
  50. }
  51. /** Builder for <code>Index</code> */
  52. public static class Builder {
  53. // Required parameters
  54. private final String collectionName;
  55. private final IndexType indexType;
  56. // Optional parameters - initialized to default values
  57. private String paramsInJson;
  58. /**
  59. * @param collectionName collection to create index on
  60. * @param indexType a <code>IndexType</code> object
  61. */
  62. public Builder(@Nonnull String collectionName, @Nonnull IndexType indexType) {
  63. this.collectionName = collectionName;
  64. this.indexType = indexType;
  65. }
  66. /**
  67. * Optional. Default to empty <code>String</code>. Index parameters are different for different
  68. * index types. Refer to <a
  69. * href="https://milvus.io/docs/v0.8.0/guides/milvus_operation.md">https://milvus.io/docs/v0.8.0/guides/milvus_operation.md</a>
  70. * for more information.
  71. *
  72. * <pre>
  73. * FLAT/IVFLAT/SQ8: {"nlist": 16384}
  74. * nlist range:[1, 999999]
  75. *
  76. * IVFPQ: {"nlist": 16384, "m": 12}
  77. * nlist range:[1, 999999]
  78. * m is decided by dim and have a couple of results.
  79. *
  80. * NSG: {"search_length": 45, "out_degree": 50, "candidate_pool_size": 300, "knng": 100}
  81. * search_length range:[10, 300]
  82. * out_degree range:[5, 300]
  83. * candidate_pool_size range:[50, 1000]
  84. * knng range:[5, 300]
  85. *
  86. * HNSW: {"M": 16, "efConstruction": 500}
  87. * M range:[5, 48]
  88. * efConstruction range:[100, 500]
  89. *
  90. * ANNOY: {"n_trees": 4}
  91. * n_trees range: [1, 16384)
  92. * </pre>
  93. *
  94. * @param paramsInJson extra parameters in JSON format
  95. * @return <code>Builder</code>
  96. */
  97. public Builder withParamsInJson(@Nonnull String paramsInJson) {
  98. this.paramsInJson = paramsInJson;
  99. return this;
  100. }
  101. public Index build() {
  102. return new Index(this);
  103. }
  104. }
  105. }