fromAnnotation static method
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(
argument: hnsw.dimensions,
condition: hnsw.dimensions > 0,
name: "dimensions",
message: "must be 1 or greater",
);
final neighborsPerNode = hnsw.neighborsPerNode;
if (neighborsPerNode != null) {
_checkArgument(
argument: neighborsPerNode,
condition: neighborsPerNode > 0,
name: "neighborsPerNode",
message: "must be 1 or greater",
);
}
final indexingSearchCount = hnsw.indexingSearchCount;
if (indexingSearchCount != null) {
_checkArgument(
argument: indexingSearchCount,
condition: indexingSearchCount > 0,
name: "indexingSearchCount",
message: "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(
argument: reparationBacklinkProbability,
condition:
reparationBacklinkProbability >= 0.0 &&
reparationBacklinkProbability <= 1.0,
name: "reparationBacklinkProbability",
message: "must be between 0.0 or 1.0",
);
}
final vectorCacheHintSizeKB = hnsw.vectorCacheHintSizeKB;
if (vectorCacheHintSizeKB != null) {
_checkArgument(
argument: vectorCacheHintSizeKB,
condition: vectorCacheHintSizeKB > 0,
name: "vectorCacheHintSizeKB",
message: "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,
);
}