W2-T09: memoize holographic.encode_atom (SHA-256 fan-out per token) - #9
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7f0565d8e1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| raise RuntimeError("numpy is required for holographic operations") | ||
|
|
||
|
|
||
| @functools.lru_cache(maxsize=4096) |
There was a problem hiding this comment.
Avoid sharing mutable cached atom vectors
Caching encode_atom now returns the exact same mutable np.ndarray to every caller for a given (word, dim). If any caller mutates the returned array in place (for example during experimentation, normalization, or test setup), all future encodings of that atom are silently corrupted and downstream HRR facts/searches use the modified vector. Either cache an immutable/read-only array or return a copy from the cached value so memoization cannot change the function's deterministic-value contract.
Useful? React with 👍 / 👎.
|



Audit W2-T09 (P2 #16).
@functools.lru_cache(maxsize=4096)onencode_atom(word: str, dim: int). Args hashable; no side effects; deterministic SHA-256 seeded fan-out makes this safe and effective.