|
| 1 | +/* |
| 2 | + * Copyright 2024 ObjectBox Ltd. All rights reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +// automatically generated by the FlatBuffers compiler, do not modify |
| 18 | + |
| 19 | +package io.objectbox.model; |
| 20 | + |
| 21 | +import io.objectbox.flatbuffers.BaseVector; |
| 22 | +import io.objectbox.flatbuffers.BooleanVector; |
| 23 | +import io.objectbox.flatbuffers.ByteVector; |
| 24 | +import io.objectbox.flatbuffers.Constants; |
| 25 | +import io.objectbox.flatbuffers.DoubleVector; |
| 26 | +import io.objectbox.flatbuffers.FlatBufferBuilder; |
| 27 | +import io.objectbox.flatbuffers.FloatVector; |
| 28 | +import io.objectbox.flatbuffers.IntVector; |
| 29 | +import io.objectbox.flatbuffers.LongVector; |
| 30 | +import io.objectbox.flatbuffers.ShortVector; |
| 31 | +import io.objectbox.flatbuffers.StringVector; |
| 32 | +import io.objectbox.flatbuffers.Struct; |
| 33 | +import io.objectbox.flatbuffers.Table; |
| 34 | +import io.objectbox.flatbuffers.UnionVector; |
| 35 | +import java.nio.ByteBuffer; |
| 36 | +import java.nio.ByteOrder; |
| 37 | + |
| 38 | +/** |
| 39 | + * Parameters to configure HNSW-based approximate nearest neighbor (ANN) search. |
| 40 | + * Some of the parameters can influence index construction and searching. |
| 41 | + * Changing these values causes re-indexing, which can take a while due to the complex nature of HNSW. |
| 42 | + */ |
| 43 | +@SuppressWarnings("unused") |
| 44 | +public final class HnswParams extends Table { |
| 45 | + public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_26(); } |
| 46 | + public static HnswParams getRootAsHnswParams(ByteBuffer _bb) { return getRootAsHnswParams(_bb, new HnswParams()); } |
| 47 | + public static HnswParams getRootAsHnswParams(ByteBuffer _bb, HnswParams obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); } |
| 48 | + public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); } |
| 49 | + public HnswParams __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; } |
| 50 | + |
| 51 | + /** |
| 52 | + * Dimensions of vectors; vector data with less dimensions are ignored. |
| 53 | + * Vectors with more dimensions than specified here are only evaluated up to the given dimension value. |
| 54 | + * Changing this value causes re-indexing. |
| 55 | + */ |
| 56 | + public long dimensions() { int o = __offset(4); return o != 0 ? (long)bb.getInt(o + bb_pos) & 0xFFFFFFFFL : 0L; } |
| 57 | + /** |
| 58 | + * Aka "M": the max number of connections per node (default: 30). |
| 59 | + * Higher numbers increase the graph connectivity, which can lead to more accurate search results. |
| 60 | + * However, higher numbers also increase the indexing time and resource usage. |
| 61 | + * Try e.g. 16 for faster but less accurate results, or 64 for more accurate results. |
| 62 | + * Changing this value causes re-indexing. |
| 63 | + */ |
| 64 | + public long neighborsPerNode() { int o = __offset(6); return o != 0 ? (long)bb.getInt(o + bb_pos) & 0xFFFFFFFFL : 0L; } |
| 65 | + /** |
| 66 | + * Aka "efConstruction": the number of neighbor searched for while indexing (default: 100). |
| 67 | + * The higher the value, the more accurate the search, but the longer the indexing. |
| 68 | + * If indexing time is not a major concern, a value of at least 200 is recommended to improve search quality. |
| 69 | + * Changing this value causes re-indexing. |
| 70 | + */ |
| 71 | + public long indexingSearchCount() { int o = __offset(8); return o != 0 ? (long)bb.getInt(o + bb_pos) & 0xFFFFFFFFL : 0L; } |
| 72 | + public long flags() { int o = __offset(10); return o != 0 ? (long)bb.getInt(o + bb_pos) & 0xFFFFFFFFL : 0L; } |
| 73 | + /** |
| 74 | + * The distance type used for the HNSW index; for now only "Euclidean" is supported. |
| 75 | + * Changing this value causes re-indexing. |
| 76 | + */ |
| 77 | + public int distanceType() { int o = __offset(12); return o != 0 ? bb.getShort(o + bb_pos) & 0xFFFF : 0; } |
| 78 | + /** |
| 79 | + * When repairing the graph after a node was removed, this gives the probability of adding backlinks to the |
| 80 | + * repaired neighbors. |
| 81 | + * The default is 1.0 (aka "always") as this should be worth a bit of extra costs as it improves the graph's |
| 82 | + * quality. |
| 83 | + */ |
| 84 | + public float reparationBacklinkProbability() { int o = __offset(14); return o != 0 ? bb.getFloat(o + bb_pos) : 0.0f; } |
| 85 | + /** |
| 86 | + * A non-binding hint at the maximum size of the vector cache in KB (default: 2097152 or 2 GB/GiB). |
| 87 | + * The actual size max cache size may be altered according to device and/or runtime settings. |
| 88 | + * The vector cache is used to store vectors in memory to speed up search and indexing. |
| 89 | + * Note 1: cache chunks are allocated only on demand, when they are actually used. |
| 90 | + * Thus, smaller datasets will use less memory. |
| 91 | + * Note 2: the cache is for one specific HNSW index; e.g. each index has its own cache. |
| 92 | + * Note 3: the memory consumption can temporarily exceed the cache size, |
| 93 | + * e.g. for large changes, it can double due to multi-version transactions. |
| 94 | + */ |
| 95 | + public long vectorCacheHintSizeKb() { int o = __offset(16); return o != 0 ? bb.getLong(o + bb_pos) : 0L; } |
| 96 | + |
| 97 | + public static int createHnswParams(FlatBufferBuilder builder, |
| 98 | + long dimensions, |
| 99 | + long neighborsPerNode, |
| 100 | + long indexingSearchCount, |
| 101 | + long flags, |
| 102 | + int distanceType, |
| 103 | + float reparationBacklinkProbability, |
| 104 | + long vectorCacheHintSizeKb) { |
| 105 | + builder.startTable(7); |
| 106 | + HnswParams.addVectorCacheHintSizeKb(builder, vectorCacheHintSizeKb); |
| 107 | + HnswParams.addReparationBacklinkProbability(builder, reparationBacklinkProbability); |
| 108 | + HnswParams.addFlags(builder, flags); |
| 109 | + HnswParams.addIndexingSearchCount(builder, indexingSearchCount); |
| 110 | + HnswParams.addNeighborsPerNode(builder, neighborsPerNode); |
| 111 | + HnswParams.addDimensions(builder, dimensions); |
| 112 | + HnswParams.addDistanceType(builder, distanceType); |
| 113 | + return HnswParams.endHnswParams(builder); |
| 114 | + } |
| 115 | + |
| 116 | + public static void startHnswParams(FlatBufferBuilder builder) { builder.startTable(7); } |
| 117 | + public static void addDimensions(FlatBufferBuilder builder, long dimensions) { builder.addInt(0, (int) dimensions, (int) 0L); } |
| 118 | + public static void addNeighborsPerNode(FlatBufferBuilder builder, long neighborsPerNode) { builder.addInt(1, (int) neighborsPerNode, (int) 0L); } |
| 119 | + public static void addIndexingSearchCount(FlatBufferBuilder builder, long indexingSearchCount) { builder.addInt(2, (int) indexingSearchCount, (int) 0L); } |
| 120 | + public static void addFlags(FlatBufferBuilder builder, long flags) { builder.addInt(3, (int) flags, (int) 0L); } |
| 121 | + public static void addDistanceType(FlatBufferBuilder builder, int distanceType) { builder.addShort(4, (short) distanceType, (short) 0); } |
| 122 | + public static void addReparationBacklinkProbability(FlatBufferBuilder builder, float reparationBacklinkProbability) { builder.addFloat(5, reparationBacklinkProbability, 0.0f); } |
| 123 | + public static void addVectorCacheHintSizeKb(FlatBufferBuilder builder, long vectorCacheHintSizeKb) { builder.addLong(6, vectorCacheHintSizeKb, 0L); } |
| 124 | + public static int endHnswParams(FlatBufferBuilder builder) { |
| 125 | + int o = builder.endTable(); |
| 126 | + return o; |
| 127 | + } |
| 128 | + |
| 129 | + public static final class Vector extends BaseVector { |
| 130 | + public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; } |
| 131 | + |
| 132 | + public HnswParams get(int j) { return get(new HnswParams(), j); } |
| 133 | + public HnswParams get(HnswParams obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); } |
| 134 | + } |
| 135 | +} |
| 136 | + |
0 commit comments