SmallWorldParameters Class
Definition
Namespace: HNSW.Net
public class SmallWorldParameters
The single configuration object passed to a SmallWorld<TItem, TDistance>. Most defaults are sensible; the properties below control graph degree, build quality, query-time recall, and optional ACORN-γ filtering.
Remarks
Pick M first, build once with the defaults, then tune EfSearch at query time — it is the cheapest dial and gives a direct recall/latency curve without rebuilding. Construction knobs (M, LevelLambda, ConstructionPruning, the heuristic and ACORN settings) take effect at build time and require a rebuild to change. See Parameters.
Properties
| Name | Description |
|---|---|
M |
Graph degree. Higher = better recall and faster search, more memory. |
LevelLambda |
Controls the level distribution. Keep in sync with M. |
ConstructionPruning |
Candidates considered when inserting an item (efConstruction). |
NeighbourHeuristic |
Strategy for picking neighbours during insertion. |
ExpandBestSelection |
Expands the candidate pool before pruning (heuristic only). |
KeepPrunedConnections |
Keeps pruned candidates as second-best edges (heuristic only). |
EnableDistanceCacheForConstruction |
Caches distance computations during build. |
InitialDistanceCacheSize |
Initial size of the distance cache. |
InitialItemsSize |
Pre-allocates the items list. |
EfSearch |
Candidates kept during the query-time graph walk. |
OptimizeForFiltering |
Enables the ACORN-γ construction strategy. |
Gamma |
ACORN neighbour expansion factor (γ). |
Mb |
ACORN layer-0 compression parameter. |
M
public int M { get; set; }
Graph degree. Default 10. Higher values mean better recall and faster search, at the cost of memory and build time. Typical range 8–64; 16 is a reasonable default for float[] embeddings of dimension 100–1000.
LevelLambda
public double LevelLambda { get; set; }
Controls the level distribution. Default 1 / Math.Log(M). Keep in sync with M — set both together.
ConstructionPruning
public int ConstructionPruning { get; set; }
Number of candidates considered when inserting an item (efConstruction). Default 200. Larger values produce a higher-quality graph at the cost of build time, and do not affect query time.
NeighbourHeuristic
public NeighbourSelectionHeuristic NeighbourHeuristic { get; set; }
Strategy for picking neighbours during insertion. Default SelectSimple. SelectHeuristic keeps more diverse neighbours — useful for clustered data.
ExpandBestSelection
public bool ExpandBestSelection { get; set; }
Default false. Only meaningful with SelectHeuristic. Expands the candidate pool before pruning.
KeepPrunedConnections
public bool KeepPrunedConnections { get; set; }
Default false. Only meaningful with SelectHeuristic. Keeps pruned candidates as second-best edges.
EnableDistanceCacheForConstruction
public bool EnableDistanceCacheForConstruction { get; set; }
Default true. Caches distance computations during build. Disable only if distances are nearly free (for example a precomputed table lookup).
InitialDistanceCacheSize
public int InitialDistanceCacheSize { get; set; }
Initial size of the distance cache. Default 1_048_576. Reset to 0 on DeserializeGraph.
InitialItemsSize
public int InitialItemsSize { get; set; }
Pre-allocates the items list. Default 1024. Set to your expected dataset size to avoid resizing. Affects allocation strategy only — it does not pre-reserve graph nodes.
EfSearch
public int EfSearch { get; set; }
Number of candidates kept during the query-time graph walk. Default 50. Higher values mean better recall at the cost of latency. This is the runtime dial — change it between queries without rebuilding the graph.
OptimizeForFiltering
public bool OptimizeForFiltering { get; set; }
Default false. Enables the ACORN-γ construction strategy for filtered nearest-neighbor search. Must be set before calling AddItems. See Filtering.
Gamma
public int Gamma { get; set; }
ACORN neighbour expansion factor (γ). Default 1. Higher values build a denser graph that survives more selective filters at the cost of memory and build time; 3–5 is a reasonable starting range.
Mb
public int Mb { get; set; }
ACORN compression parameter for layer 0. Default 10. Higher values make layer 0 less dense and recover memory at the cost of recall under filters.
Applies to
HNSW.Net — see Parameters and the guides.