MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / random_layer

Method random_layer

nodedb-vector/src/codec_index/graph.rs:107–111  ·  view source on GitHub ↗

Assign a random layer per the HNSW exponential distribution. Capped at `MAX_LAYER_CAP` to prevent pathological draws from inflating `max_layer`.

(&mut self)

Source from the content-addressed store, hash-verified

105 /// Capped at `MAX_LAYER_CAP` to prevent pathological draws from inflating
106 /// `max_layer`.
107 pub fn random_layer(&mut self) -> usize {
108 let r = self.rng.next_f64().max(f64::MIN_POSITIVE);
109 let layer = (-r.ln() * self.level_mult as f64).floor() as usize;
110 layer.min(MAX_LAYER_CAP)
111 }
112
113 /// Return a reference to the quantized payload at `idx`, if present and
114 /// not deleted.

Callers 1

insertMethod · 0.45

Calls 1

next_f64Method · 0.45

Tested by

no test coverage detected