CSR Spreading Activation: The Mathematics of Cognitive Association

When you think of the word "ocean," your brain might instantly recall "water," "blue," "fish," or "vacation." This occurs because the activation of one node in your neural network spreads along synaptic connections to excite neighboring concepts. This is known as Spreading Activation.

Spector implements associative thinking by applying spreading activation algorithms to its Hebbian co-activation graph.


The CSR Matrix Representation

Representing a dense graph of millions of memory nodes is computationally expensive. Spector uses an off-heap Compressed Sparse Row (CSR) structure to store the Hebbian association graph, optimizing layout for CPU cache alignment.

The graph consists of three flat arrays:

  1. rowOffsets: Indices mapping nodes to the start of their adjacency lists.
  2. columnIndices: Target node IDs for each edge.
  3. weights: Co-activation strengths \(W_{ij}\) for each link.

Spreading Activation Math

Given a seed set of active memories represented as an activation vector \(a^{(0)}\), the spreading activation at step \(k\) is computed recursively:

\[a^{(k)} = d \cdot W_{CSR} \cdot a^{(k-1)} + (1 - d) \cdot a^{(0)}\]

Where:

  • \(W_{CSR}\) is the normalized CSR weights matrix.
  • \(d\) is a decay factor (typically \(0.85\)) preventing runaway feedback loops.
  • \(a^{(0)}\) is the initial activation vector, acting as a "source of gravity" to keep the activation close to the query context.

In practice, Spector limits this search to 2-3 hops using SIMD matrix-vector multiplications, allowing the engine to surface associated context nodes in microseconds.


Real-world Example: Associative Recall in Action

If an agent is debugging a deployment script:

  1. The search query retrieves the vector for the deployment file.
  2. Spreading activation hops to related nodes: the build system configuration, the server credentials, and the user's past environment variables.
  3. The agent receives a complete picture of the environment, not just the code file.