Package io.github.jbellis.jvector.graph
Class ConcurrentNeighborSet
java.lang.Object
io.github.jbellis.jvector.graph.ConcurrentNeighborSet
A concurrent set of neighbors that encapsulates diversity/pruning mechanics.
-
Constructor Summary
ConstructorsConstructorDescriptionConcurrentNeighborSet(int nodeId, int maxConnections, NodeSimilarity similarity) ConcurrentNeighborSet(int nodeId, int maxConnections, NodeSimilarity similarity, float alpha) -
Method Summary
Modifier and TypeMethodDescriptionintvoidbacklink(IntFunction<ConcurrentNeighborSet> neighborhoodOf, float overflow) For every neighbor X that this node Y connects to, add a reciprocal link from X to Y.copy()voidEnforce maxConnections as a hard cap, since we allow it to be exceeded temporarily during construction for efficiency.floatvoidinsert(int neighborId, float score, float overflow) Insert a new neighbor, maintaining our size cap by removing the least diverse neighbor if necessary.voidinsertDiverse(NodeArray natural, NodeArray concurrent) For each candidate (going from best to worst), select it only if it is closer to target than it is to any of the already-selected candidates.iterator()booleanremoveDeletedNeighbors(Bits deletedNodes) intsize()
-
Constructor Details
-
ConcurrentNeighborSet
-
ConcurrentNeighborSet
public ConcurrentNeighborSet(int nodeId, int maxConnections, NodeSimilarity similarity, float alpha)
-
-
Method Details
-
getShortEdges
public float getShortEdges() -
iterator
-
backlink
For every neighbor X that this node Y connects to, add a reciprocal link from X to Y. If overflow is > 1.0, allow the number of neighbors to exceed maxConnections temporarily. -
enforceDegree
public void enforceDegree()Enforce maxConnections as a hard cap, since we allow it to be exceeded temporarily during construction for efficiency. This method is threadsafe, but if you call it concurrently with other inserts, the limit may end up being exceeded again. -
removeDeletedNeighbors
- Returns:
- true if we had deleted neighbors
-
size
public int size() -
arrayLength
public int arrayLength() -
insertDiverse
For each candidate (going from best to worst), select it only if it is closer to target than it is to any of the already-selected candidates. This is maintained whether those other neighbors were selected by this method, or were added as a "backlink" to a node inserted concurrently that chose this one as a neighbor. -
insert
public void insert(int neighborId, float score, float overflow) Insert a new neighbor, maintaining our size cap by removing the least diverse neighbor if necessary. "Overflow" is the factor by which to allow going over the size cap temporarily. -
copy
-