fromAnnotation static method

ModelHnswParams fromAnnotation(
  1. HnswIndex hnsw
)

Create with values from an HnswIndex annotation.

Implementation

static ModelHnswParams fromAnnotation(HnswIndex hnsw) {
  // Reject illegal configuration values during a generator run already,
  // otherwise would error at runtime (which might not be easily attributable,
  // see model.dart).
  // See allowed ranges in objectbox-c/src/model.cpp
  checkArgument(hnsw.dimensions, hnsw.dimensions > 0, "dimensions",
      "must be 1 or greater");
  final neighborsPerNode = hnsw.neighborsPerNode;
  if (neighborsPerNode != null) {
    checkArgument(neighborsPerNode, neighborsPerNode > 0, "neighborsPerNode",
        "must be 1 or greater");
  }
  final indexingSearchCount = hnsw.indexingSearchCount;
  if (indexingSearchCount != null) {
    checkArgument(indexingSearchCount, indexingSearchCount > 0,
        "indexingSearchCount", "must be 1 or greater");
  }
  final reparationBacklinkProbability = hnsw.reparationBacklinkProbability;
  if (reparationBacklinkProbability != null) {
    // The C API allows values bigger than 1.0, but internally everything
    // above 0.999 is just mapped to "always": so restrict to max 1.0.
    checkArgument(
        reparationBacklinkProbability,
        reparationBacklinkProbability >= 0.0 &&
            reparationBacklinkProbability <= 1.0,
        "reparationBacklinkProbability",
        "must be between 0.0 or 1.0");
  }
  final vectorCacheHintSizeKB = hnsw.vectorCacheHintSizeKB;
  if (vectorCacheHintSizeKB != null) {
    checkArgument(vectorCacheHintSizeKB, vectorCacheHintSizeKB > 0,
        "vectorCacheHintSizeKB", "must be 1 or greater");
  }
  return ModelHnswParams(
      dimensions: hnsw.dimensions,
      neighborsPerNode: neighborsPerNode,
      indexingSearchCount: indexingSearchCount,
      flags: hnsw.flags?.toFlags(),
      distanceType: hnsw.distanceType?.toConstant(),
      reparationBacklinkProbability: reparationBacklinkProbability,
      vectorCacheHintSizeKB: vectorCacheHintSizeKB);
}