Skip to content

docs: EMGRAM integration research for issue #699#772

Open
iberi22 wants to merge 1 commit into
mainfrom
feature/issue-699-emgram-research
Open

docs: EMGRAM integration research for issue #699#772
iberi22 wants to merge 1 commit into
mainfrom
feature/issue-699-emgram-research

Conversation

@iberi22

@iberi22 iberi22 commented Jun 4, 2026

Copy link
Copy Markdown
Owner

EMGRAM (DeepSeek) Integration Research

Closes #699

Summary

This PR adds a comprehensive research document analyzing DeepSeek's Engram (EMGRAM) conditional memory architecture and its integration potential with Synapse Protocol.

What's Included

  • Executive summary of Engram's 5 key innovations
  • DeepSeek benchmark results comparison table
  • Full audit of Synapse's existing EngramPort + EngramSledAdapter
  • 10+ integration points mapped across the codebase
  • Proposed trait extensions (hash lookup, gating, prefetch)
  • Multi-tier adapter architecture (HashIndex + Sled)
  • 3-phase implementation plan with per-file blueprint
  • Risk assessment and next steps

Key Finding

Synapse already has an EngramPort trait and Sled adapter — but the current implementation is a basic KV store. The research proposes evolving it toward a true DeepSeek-style conditional memory module with O(1) hash lookups, context-aware gating, and multi-head hashing.

Resolves #699 — Research EMGRAM (DeepSeek) and integration options

- Comprehensive analysis of DeepSeek's Engram conditional memory architecture
- Current Synapse Engram implementation audit (EngramPort + EngramSledAdapter)
- Identification of 10+ integration points across the codebase
- Proposed EngramPort trait extensions with O(1) hash lookup, gating, prefetch
- Multi-tier adapter architecture (DRAM HashIndex + Sled persistence)
- 3-phase implementation plan with file-level blueprint
- Risk assessment and next steps
@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@iberi22, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 56 minutes and 8 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fa8ee44d-a04d-43a5-b9d8-358ce65d2a3a

📥 Commits

Reviewing files that changed from the base of the PR and between c801b64 and d7ae16d.

📒 Files selected for processing (1)
  • docs/research/EMGRAM_INTEGRATION.md
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/issue-699-emgram-research

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a research document outlining the integration roadmap for the EMGRAM (Engram) conditional memory architecture into the Synapse Protocol. The review feedback identifies a mathematical issue in the conceptual compute_gate function where mismatched embedding dimensions would cause silent truncation during the dot product calculation while using full lengths for normalization, and provides a code suggestion to assert equal lengths.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +237 to +251
fn compute_gate(
context_embedding: &[f32],
memory_embedding: &[f32],
temperature: f32,
) -> f32 {
let dot: f32 = context_embedding.iter()
.zip(memory_embedding)
.map(|(a, b)| a * b)
.sum();
let norm_a = context_embedding.iter().map(|x| x * x).sum::<f32>().sqrt();
let norm_b = memory_embedding.iter().map(|x| x * x).sum::<f32>().sqrt();
let cosine = dot / (norm_a * norm_b + 1e-10);
// Sigmoid: maps [-1, 1] → [0.12, 0.88] roughly; temperature sharpens
1.0 / (1.0 + (-cosine * temperature).exp())
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

In compute_gate, if context_embedding and memory_embedding have mismatched dimensions, zip will silently truncate to the shorter length. However, norm_a and norm_b are computed over the entire length of each slice. This will result in a mathematically incorrect cosine similarity calculation.

To prevent this silent failure, add an assertion to ensure that both embedding slices have the same length.

Suggested change
fn compute_gate(
context_embedding: &[f32],
memory_embedding: &[f32],
temperature: f32,
) -> f32 {
let dot: f32 = context_embedding.iter()
.zip(memory_embedding)
.map(|(a, b)| a * b)
.sum();
let norm_a = context_embedding.iter().map(|x| x * x).sum::<f32>().sqrt();
let norm_b = memory_embedding.iter().map(|x| x * x).sum::<f32>().sqrt();
let cosine = dot / (norm_a * norm_b + 1e-10);
// Sigmoid: maps [-1, 1] → [0.12, 0.88] roughly; temperature sharpens
1.0 / (1.0 + (-cosine * temperature).exp())
}
fn compute_gate(
context_embedding: &[f32],
memory_embedding: &[f32],
temperature: f32,
) -> f32 {
assert_eq!(
context_embedding.len(),
memory_embedding.len(),
"Embedding dimensions must match"
);
let dot: f32 = context_embedding.iter()
.zip(memory_embedding)
.map(|(a, b)| a * b)
.sum();
let norm_a = context_embedding.iter().map(|x| x * x).sum::<f32>().sqrt();
let norm_b = memory_embedding.iter().map(|x| x * x).sum::<f32>().sqrt();
let cosine = dot / (norm_a * norm_b + 1e-10);
// Sigmoid: maps [-1, 1] → [0.12, 0.88] roughly; temperature sharpens
1.0 / (1.0 + (-cosine * temperature).exp())
}

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.

Research EMGRAM (DeepSeek) and integration options

1 participant