Expand description
Memory embedding visualization (RFC-T1-B).
Projects high-dimensional memory embeddings into 2D coordinates for the web UI Memory Map. We use truncated PCA via pure-Rust power iteration (no external linear-algebra dependency) and cosine-similarity for neighbor detection.
§Why not UMAP / t-SNE?
The RFC recommends UMAP. We chose PCA for the MVP because:
- No external dep —
linfa/linfa-umapwould add ~5MB of compile time and a non-trivial pure-Rust surface area. PCA via power iteration fits in ~80 lines. - Deterministic — given the same input we always get the same output (UMAP/TSNE have stochastic init).
- Cheap-ish — O(nnz · iterations · k) for k components, where
nnzis the number of non-zero entries across the input. The TF-IDF vectors the kernel produces are sparse (most entries are zero), so the practical cost is much lower than the denseO(n · d)bound. We work directly on the sparse representation and never densify. - Caches well — pure function of embeddings, perfect for the 5-min epoch cache the RFC requires.
PCA captures global structure (the principal axes of variance), not local neighborhoods. That is sufficient for “is this cluster of Hot memories visually distinct from Cold?” — the use case for the MVP. UMAP can be added later behind the same interface.
Structs§
- Memory
MapEntry - One node on the memory map.
- Memory
Neighbor - Edge from one memory to a similar neighbor.
Functions§
- compute_
pca_ 2d - Project a set of embeddings into 2D coordinates via PCA.
- compute_
top_ neighbors - Top-k most similar neighbors per embedding, cosine-similarity only.