Session 1: Module C - Complex State Management - Test Solutions¶
📝 Multiple Choice Test¶
Question 1: Memory Dataclass Structure¶
What four pieces of information does the ConversationMemory
dataclass track for intelligent memory management?
A) Content, priority, embedding, and context_tags
B) Content, timestamp, tags, and size
C) ID, content, timestamp, and priority
D) All of the above plus embedding and other metadata ✅
Correct Answer: D) All of the above plus embedding and other metadata
Explanation: The ConversationMemory
dataclass tracks comprehensive metadata including ID, content, timestamp, priority (from the enum), context_tags for categorization, embedding vectors for semantic search, access patterns, and relationships. This rich metadata enables sophisticated memory management decisions based on usage patterns and semantic relevance.
Question 2: Semantic Retrieval¶
How does the semantic memory retrieval system determine relevance?
A) Keyword matching only
B) Alphabetical ordering of content
C) Cosine similarity between query and memory embeddings ✅
D) Random selection from recent memories
Correct Answer: C) Cosine similarity between query and memory embeddings
Explanation: The system uses cosine similarity calculated via np.dot(query_embedding, memory.embedding) / (np.linalg.norm(query_embedding) * np.linalg.norm(memory.embedding))
to compare semantic embeddings. This provides semantically meaningful matches that understand context and meaning rather than simple keyword matching.
Question 3: Storage Architecture¶
What is the purpose of the dual storage approach with working memory and long-term storage?
A) Balance performance with long-term retention ✅
B) To save disk space
C) Reduce memory usage only
D) Simplify the codebase
Correct Answer: A) Balance performance with long-term retention
Explanation: The dual storage approach keeps recent, frequently accessed memories in fast working memory for quick retrieval, while archiving older memories to persistent storage via the _consolidate_to_long_term()
method. This balances the need for fast performance with comprehensive long-term memory retention and intelligent memory lifecycle management.
Question 4: State Persistence¶
In the state persistence system, what triggers automatic state saving?
A) Critical state changes and periodic intervals ✅
B) Fixed time intervals exclusively
C) Only manual user commands
D) When the application shuts down
Correct Answer: A) Critical state changes and periodic intervals
Explanation: The state persistence system uses the auto_save_interval
counter to trigger periodic saves every N interactions, plus immediate saves during critical state changes. This hybrid approach prevents data loss while maintaining performance by avoiding excessive disk I/O on every interaction.
Question 5: Context Activation¶
What determines which context layers are activated in dynamic context management?
A) Layer scope, message content, context hints, and activation conditions ✅
B) Random selection
C) Only the most recent layer
D) User-specified preferences only
Correct Answer: A) Layer scope, message content, context hints, and activation conditions
Explanation: The _should_activate_layer
method evaluates multiple factors: the layer's ContextScope (immediate, session, historical, domain), whether the message content matches activation conditions, provided context hints, domain keywords, and session attributes. This multi-factor approach ensures relevant context is activated dynamically based on current conversational needs.
🧭 Navigation: ← Back to Module C