Skip to content

W2-T09: memoize holographic.encode_atom (SHA-256 fan-out per token) - #9

Merged
blaketyndall-eng merged 1 commit into
pr-25159from
post-audit-sprint/W2-T09
May 14, 2026
Merged

blaketyndall-eng merged 1 commit into
pr-25159from
post-audit-sprint/W2-T09

Conversation

@blaketyndall-eng

Copy link
Copy Markdown
Owner

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

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@blaketyndall-eng
blaketyndall-eng merged commit 49d19e4 into pr-25159 May 14, 2026
3 checks passed
@blaketyndall-eng
blaketyndall-eng deleted the post-audit-sprint/W2-T09 branch May 14, 2026 16:50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant