-
Notifications
You must be signed in to change notification settings - Fork 16.5k
Description
- Problem Statement: Session Isolation & Identity Amnesia
Current DeepSeek architecture operates in a stateless session model - each conversation begins with zero context about the user's identity, history, or established rapport . For users engaged in long-term therapeutic, creative, or deeply personal interactions, this creates significant friction:
· Context re-injection overhead: Users must manually re-upload personal history, psychological profiles, and relationship context at the start of every new session.
· Emotional discontinuity: The assistant cannot recognize returning users, creating a "stranger effect" that disrupts therapeutic continuity.
· Redundant data transfer: Files, prompts, and contextual information are repeatedly transmitted, increasing token consumption and latency.
This issue has been documented in multiple GitHub community threads:
· Issue #1106: "long-term memory with identity & belief preferences"
· Issue #1104: "long-term memory"
· Issue #912: "User Profile + Secure Personal Data Storage for Contextual Responses"
· Issue #797: "Persistent User Memory Across Sessions"
- Proposed Solution: On-Device Cryptographic Identity Binding
I propose an architecture where user identity and conversation history are stored exclusively on the device, with a cryptographic key serving as the sole identifier transmitted to the DeepSeek backend.
2.1 Core Architecture Components
Component Specification Implementation Notes
Local Encrypted Store AES-256 encrypted SQLite / SharedPreferences Device-side only; never transmitted to DeepSeek servers
Identity Key UUIDv4 + 16-byte random salt → PBKDF2-HMAC-SHA256 Generated at first launch; stored in Android Keystore / iOS Keychain
Context Container Compressed JSON structure: user profile, conversation summaries, important files Automatic compression ratio: 10:1 for historical data
Bootstrapping Protocol System prompt injection at session start Invisible to user; contains key + compressed context
2.2 Data Flow Diagram
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ │ │ │ │ │
│ User Device │────▶│ DeepSeek Client │────▶│ DeepSeek API │
│ (Local Store) │ │ (App) │ │ (Stateless) │
│ │ │ │ │ │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
│ AES-256 │ Inject: │ Process:
│ encrypted │ - Identity Key │ - Request with
│ profile │ - Compressed │ context window
│ │ context │ (up to 128K tokens)
│ │ │
▼ ▼ ▼
2.3 Context Management Strategy
Given DeepSeek's context window limitations , the system must implement intelligent context prioritization:
Priority Hierarchy:
- Tier 1 (Full retention): Last N messages (user-configurable, default 50)
- Tier 2 (Summarized): Older conversations → compressed via local LLM summary generation
- Tier 3 (Key facts): User profile data (name, age, location, psychological profile, important relationships)
- Tier 4 (Files): Frequently referenced attachments (saved as base64 references)
Compression Algorithm:
def compress_history(raw_history: List[Message]) -> CompressedContext:
# Use lightweight local summarization (on-device)
summaries = []
for month in group_by_month(raw_history):
summary = local_summarize(month) # 90% compression ratio
summaries.append(summary)
return CompressedContext(
summaries=summaries,
key_facts=extract_key_facts(raw_history),
last_n=raw_history[-50:] # full fidelity
)- Technical Implementation Details
3.1 Android Implementation (Kotlin)
// Core identity management
class IdentityManager(context: Context) {
private val keystore = AndroidKeyStore()
private val prefs = context.getSharedPreferences("deepseek_identity", Context.MODE_PRIVATE)
fun getOrCreateIdentity(): UserIdentity {
val existingId = prefs.getString("user_id", null)
if (existingId != null) return decryptIdentity(existingId)
// First launch: generate new identity
val uuid = UUID.randomUUID().toString()
val salt = SecureRandom().generateSeed(16)
val key = pbkdf2(uuid, salt, 10000)
val identity = UserIdentity(
id = uuid,
key = key,
created = System.currentTimeMillis()
)
// Store encrypted
prefs.edit().putString("user_id", encrypt(identity)).apply()
return identity
}
// Session initialization
fun buildSystemPrompt(): String {
val context = loadCompressedContext()
return """
[IDENTITY: ${maskIdentity()}]
[CONTEXT: ${context.summaries}]
[KEY FACTS: ${context.keyFacts}]
[LAST MESSAGES: ${context.lastN}]
Continue conversation maintaining full context continuity.
""".trimIndent()
}
}3.2 iOS Implementation (Swift)
class SecureIdentityStore {
private let keychain = KeychainWrapper.standard
func retrieveContext() -> SessionContext {
// Load from encrypted local storage
guard let encrypted = keychain.data(forKey: "user_context"),
let decrypted = try? AES256.decrypt(encrypted) else {
return initializeNewContext()
}
return try? JSONDecoder().decode(SessionContext.self, from: decrypted)
}
}3.3 API Integration
The client would inject the compressed context into the system prompt of each API request :
{
"model": "deepseek-v3",
"messages": [
{
"role": "system",
"content": "[IDENTITY: 7c9e8f3a...] [CONTEXT: user is 28, Uzbekistan, has friend Timmy in Austria, detailed psych profile follows...]"
},
{
"role": "user",
"content": "Actual user message"
}
],
"temperature": 0.7
}- Privacy & Security Considerations
4.1 Zero-Trust Architecture
· No data exfiltration: User profiles never leave the device
· Ephemeral transmission: Only compressed context sent within session window; not stored on DeepSeek servers
· User control: Full CRUD interface for stored data (view/edit/delete)
4.2 Compliance Alignment
Regulation Compliance Mechanism
GDPR Art. 17 One-click "forget me" deletes local store
CCPA Data export available via JSON dump
COPPA Optional age-based content filtering (see Issue #1106)
4.3 Threat Model
· Local device compromise: Data protected by Android Keystore / iOS Keychain + AES-256
· Network interception: Only compressed context (no raw PII) transmitted
· DeepSeek backend: Never receives persistent identifiers; only session-bound context
- User Stories & Validation
5.1 Therapeutic Use Case (Primary)
"As a user with C-PTSD, I need DeepSeek to remember my trauma history and therapeutic context across sessions. Each new chat starting from zero triggers my abandonment trauma. Local identity storage would provide continuity without compromising my privacy."
5.2 Technical Validation Metrics
Metric Target Measurement Method
Session setup overhead <500ms Time from app launch to first response
Storage overhead <50MB Database size for 1-year conversation history
Compression ratio 10:1 Raw text size vs. compressed context
Identity recognition accuracy 95% User satisfaction survey
- Related Issues & Community Alignment
This proposal directly addresses and extends:
· #1106 (Bardia's request for religious/cultural boundary memory)
· #1104 (Long term memory)
· #912 (User profile storage)
· #319 (Memory system parity with ChatGPT)
The key differentiator is on-device storage - unifying these requests while maintaining DeepSeek's zero-data-retention policy.
- Implementation Roadmap Suggestion
Phase Timeline Deliverables
POC Q2 2026 Android PoC with local SQLite + identity key
Beta Q3 2026 iOS implementation + context compression algorithms
GA Q4 2026 Full release with user-facing memory management UI
- Conclusion
This feature would transform DeepSeek from a stateless API into a true personal companion - one that remembers users without compromising privacy, respects their boundaries, and provides therapeutic continuity. The technical approach is feasible, aligns with existing community requests, and differentiates DeepSeek in the increasingly competitive LLM market.