Crate micro_hnsw_wasm

Crate micro_hnsw_wasm 

Source
Expand description

Micro HNSW v2.3 - Neuromorphic HNSW with Novel Discoveries Target: <12KB WASM with multi-core support

Features:

  • Multiple distance metrics (L2, Cosine, Dot)
  • Multi-core sharding (256 cores × 32 vectors = 8K total)
  • Batch operations with 4-vector batching
  • Beam search for better recall
  • Result merging across cores
  • Node types for Cypher-style typed graphs (16 types)
  • Edge weights for GNN message passing
  • Vector updates for online learning/GNN propagation
  • Spiking Neural Network integration with LIF neurons
  • STDP (Spike-Timing Dependent Plasticity) learning

§Novel Neuromorphic Discoveries (v2.3)

  • Spike-Timing Vector Encoding: Convert vectors to temporal spike patterns
  • Homeostatic Plasticity: Self-stabilizing network activity
  • Oscillatory Resonance: Frequency-tuned search amplification
  • Temporal Pattern Recognition: Spike-based similarity matching
  • Winner-Take-All Circuits: Competitive neural selection
  • Dendritic Computation: Non-linear local processing

Structs§

MicroHnsw
Node
SearchResult
Vector

Enums§

Metric

Functions§

aggregate_neighbors
Aggregate neighbors into DELTA buffer (GNN message passing)
clear_global
Clear global results
compute_resonance
Compute resonance boost for a neuron based on phase alignment Neurons in sync with gamma get amplified
count
dendrite_inject
Inject input to specific dendritic compartment
dendrite_integrate
Dendritic integration with nonlinearity Multiple coincident inputs on same branch get amplified
dendrite_propagate
Propagate spikes through dendritic tree (not just soma)
dendrite_reset
Reset dendritic compartments
encode_vector_to_spikes
Encode vector to temporal spike pattern (rate-to-time conversion) Higher values → earlier spikes (first-spike coding) Returns encoded pattern as 32-bit bitmask
get_capacity
get_core_id
get_delta_ptr
Get delta buffer pointer for reading aggregated values
get_dims
get_edge_weight
Get node edge weight
get_global_ptr
get_insert_ptr
get_metric
get_network_activity
Get total network activity (sum of spike rates)
get_node_type
Get node type (0-15)
get_pattern
Get temporal spike pattern for a neuron
get_query_ptr
get_result_ptr
get_spike_rate
Get current spike rate estimate
hnsw_to_snn
Combined HNSW-SNN cycle: search → convert to currents → inject Useful for linking vector similarity to neural activation
homeostatic_update
Apply homeostatic plasticity: adjust thresholds to maintain target rate
init
Initialize: init(dims, metric, core_id) metric: 0=L2, 1=Cosine, 2=Dot
insert
Insert vector from INSERT buffer, returns index or 255 if full
merge
Merge results from another core into global buffer
neuromorphic_search
Advanced neuromorphic search with all novel features Combines: HNSW graph, spike timing, oscillation, WTA
oscillator_get_phase
Get current oscillator phase (0 to 2π)
oscillator_step
Update oscillator phase
pattern_correlate
Temporal correlation: find neurons with similar spike history
pattern_match
Match pattern against stored patterns (Hamming similarity) Returns best matching neuron index
pattern_record
Record current spike state into pattern buffer (shift register)
resonance_search
Apply resonance-modulated search boost Query matches are enhanced when neuron is in favorable phase
search
Search for k nearest neighbors using beam search
set_delta_ptr
Get mutable delta buffer pointer
set_edge_weight
Set node edge weight (uniform for all edges from this node, 0-255)
set_node_type
Set node type (0-15) for Cypher-style typed queries Types packed 2 per byte (4 bits each)
snn_get_membrane
Get membrane potential
snn_get_spikes
Get spike bitset (32 neurons packed into u32)
snn_get_time
Get current simulation time
snn_inject
Inject current into a neuron (adds to membrane potential)
snn_propagate
Propagate spikes to neighbors (injects current based on edge weights) Call after snn_step to propagate activity
snn_reset
Reset SNN state for all neurons
snn_set_membrane
Set membrane potential for a neuron
snn_set_threshold
Set firing threshold for a neuron
snn_spiked
Get spike status (1 if spiked last step, 0 otherwise)
snn_stdp
STDP learning: adjust edge weights based on spike timing Call after snn_step to apply plasticity
snn_step
LIF neuron step: simulate one timestep (dt in ms) Returns number of neurons that spiked
snn_tick
Combined: step + propagate + optionally STDP Returns spike count
spike_search
Search using spike-timing representation Novel: temporal code matching instead of distance
spike_timing_similarity
Compute spike-timing similarity between two spike patterns Uses Victor-Purpura-inspired metric: count matching spike times
type_matches
Check if node type matches mask (for filtering in JS/host)
update_vector
Update vector: v = v + alpha * delta (in-place)
wta_compete
Run WTA competition: only highest membrane potential survives Returns winner index (or 255 if no winner)
wta_reset
Reset WTA state
wta_soft
Soft WTA: proportional inhibition based on rank