docs: EMGRAM integration research for issue #699#772
Conversation
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
|
Warning Review limit reached
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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.
| 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()) | ||
| } |
There was a problem hiding this comment.
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.
| 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()) | |
| } |
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
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.