@prmichaelsen/remember-mcp 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/.env.example +65 -0
  2. package/AGENT.md +840 -0
  3. package/README.md +72 -0
  4. package/agent/design/.gitkeep +0 -0
  5. package/agent/design/access-control-result-pattern.md +458 -0
  6. package/agent/design/action-audit-memory-types.md +637 -0
  7. package/agent/design/common-template-fields.md +282 -0
  8. package/agent/design/complete-tool-set.md +407 -0
  9. package/agent/design/content-types-expansion.md +521 -0
  10. package/agent/design/cross-database-id-strategy.md +358 -0
  11. package/agent/design/default-template-library.md +423 -0
  12. package/agent/design/firestore-wrapper-analysis.md +606 -0
  13. package/agent/design/llm-provider-abstraction.md +691 -0
  14. package/agent/design/location-handling-architecture.md +523 -0
  15. package/agent/design/memory-templates-design.md +364 -0
  16. package/agent/design/permissions-storage-architecture.md +680 -0
  17. package/agent/design/relationship-storage-strategy.md +361 -0
  18. package/agent/design/remember-mcp-implementation-tasks.md +417 -0
  19. package/agent/design/remember-mcp-progress.yaml +141 -0
  20. package/agent/design/requirements-enhancements.md +468 -0
  21. package/agent/design/requirements.md +56 -0
  22. package/agent/design/template-storage-strategy.md +412 -0
  23. package/agent/design/template-suggestion-system.md +853 -0
  24. package/agent/design/trust-escalation-prevention.md +343 -0
  25. package/agent/design/trust-system-implementation.md +592 -0
  26. package/agent/design/user-preferences.md +683 -0
  27. package/agent/design/weaviate-collection-strategy.md +461 -0
  28. package/agent/milestones/.gitkeep +0 -0
  29. package/agent/milestones/milestone-1-project-foundation.md +121 -0
  30. package/agent/milestones/milestone-2-core-memory-system.md +150 -0
  31. package/agent/milestones/milestone-3-relationships-graph.md +116 -0
  32. package/agent/milestones/milestone-4-user-preferences.md +103 -0
  33. package/agent/milestones/milestone-5-template-system.md +126 -0
  34. package/agent/milestones/milestone-6-auth-multi-tenancy.md +124 -0
  35. package/agent/milestones/milestone-7-trust-permissions.md +133 -0
  36. package/agent/milestones/milestone-8-testing-quality.md +137 -0
  37. package/agent/milestones/milestone-9-deployment-documentation.md +147 -0
  38. package/agent/patterns/.gitkeep +0 -0
  39. package/agent/patterns/bootstrap.md +1271 -0
  40. package/agent/patterns/firebase-admin-sdk-v8-usage.md +950 -0
  41. package/agent/patterns/firestore-users-pattern-best-practices.md +347 -0
  42. package/agent/patterns/library-services.md +454 -0
  43. package/agent/patterns/testing-colocated.md +316 -0
  44. package/agent/progress.yaml +395 -0
  45. package/agent/tasks/.gitkeep +0 -0
  46. package/agent/tasks/task-1-initialize-project-structure.md +266 -0
  47. package/agent/tasks/task-2-install-dependencies.md +199 -0
  48. package/agent/tasks/task-3-setup-weaviate-client.md +330 -0
  49. package/agent/tasks/task-4-setup-firestore-client.md +362 -0
  50. package/agent/tasks/task-5-create-basic-mcp-server.md +114 -0
  51. package/agent/tasks/task-6-create-integration-tests.md +195 -0
  52. package/agent/tasks/task-7-finalize-milestone-1.md +363 -0
  53. package/agent/tasks/task-8-setup-utility-scripts.md +382 -0
  54. package/agent/tasks/task-9-create-server-factory.md +404 -0
  55. package/dist/config.d.ts +26 -0
  56. package/dist/constants/content-types.d.ts +60 -0
  57. package/dist/firestore/init.d.ts +14 -0
  58. package/dist/firestore/paths.d.ts +53 -0
  59. package/dist/firestore/paths.spec.d.ts +2 -0
  60. package/dist/server-factory.d.ts +40 -0
  61. package/dist/server-factory.js +1741 -0
  62. package/dist/server-factory.spec.d.ts +2 -0
  63. package/dist/server.d.ts +3 -0
  64. package/dist/server.js +1690 -0
  65. package/dist/tools/create-memory.d.ts +94 -0
  66. package/dist/tools/delete-memory.d.ts +47 -0
  67. package/dist/tools/search-memory.d.ts +88 -0
  68. package/dist/types/memory.d.ts +183 -0
  69. package/dist/utils/logger.d.ts +7 -0
  70. package/dist/weaviate/client.d.ts +39 -0
  71. package/dist/weaviate/client.spec.d.ts +2 -0
  72. package/dist/weaviate/schema.d.ts +29 -0
  73. package/esbuild.build.js +60 -0
  74. package/esbuild.watch.js +25 -0
  75. package/jest.config.js +31 -0
  76. package/jest.e2e.config.js +17 -0
  77. package/package.json +68 -0
  78. package/src/.gitkeep +0 -0
  79. package/src/config.ts +56 -0
  80. package/src/constants/content-types.ts +454 -0
  81. package/src/firestore/init.ts +68 -0
  82. package/src/firestore/paths.spec.ts +75 -0
  83. package/src/firestore/paths.ts +124 -0
  84. package/src/server-factory.spec.ts +60 -0
  85. package/src/server-factory.ts +215 -0
  86. package/src/server.ts +243 -0
  87. package/src/tools/create-memory.ts +198 -0
  88. package/src/tools/delete-memory.ts +126 -0
  89. package/src/tools/search-memory.ts +216 -0
  90. package/src/types/memory.ts +276 -0
  91. package/src/utils/logger.ts +42 -0
  92. package/src/weaviate/client.spec.ts +58 -0
  93. package/src/weaviate/client.ts +114 -0
  94. package/src/weaviate/schema.ts +288 -0
  95. package/tsconfig.json +26 -0
@@ -0,0 +1,853 @@
1
+ # Template Suggestion System
2
+
3
+ **Concept**: Automatic template suggestion when creating memories
4
+ **Created**: 2026-02-11
5
+ **Status**: Design Specification
6
+
7
+ ---
8
+
9
+ ## Overview
10
+
11
+ When a user creates a new memory, the system can automatically suggest relevant templates based on conversation context, keywords, and patterns. This helps users create structured, consistent memories without manual template selection.
12
+
13
+ ---
14
+
15
+ ## Template Suggestion Flow
16
+
17
+ ### 1. User Initiates Memory Creation
18
+
19
+ ```typescript
20
+ // User says: "I just met Sarah at the conference. She's a product manager at Google."
21
+
22
+ // Agent recognizes this should be a memory
23
+ remember_create_memory({
24
+ content: "Met Sarah at conference. Product manager at Google.",
25
+ // No template specified yet
26
+ })
27
+ ```
28
+
29
+ ### 2. System Analyzes Context
30
+
31
+ ```typescript
32
+ async function suggestTemplates(
33
+ content: string,
34
+ context: ConversationContext
35
+ ): Promise<TemplateSuggestion[]> {
36
+ // 1. Extract keywords and entities
37
+ const analysis = await analyzeContent(content);
38
+ // Result: {
39
+ // keywords: ["met", "conference", "product manager", "Google"],
40
+ // entities: ["Sarah", "Google"],
41
+ // intent: "recording_person_information",
42
+ // context_type: "professional_networking"
43
+ // }
44
+
45
+ // 2. Query templates with auto_apply enabled
46
+ const templates = await getTemplatesWithAutoApply(context.user_id);
47
+
48
+ // 3. Score each template
49
+ const scored = templates.map(template => ({
50
+ template,
51
+ score: calculateTemplateScore(template, analysis, context)
52
+ }));
53
+
54
+ // 4. Return top suggestions
55
+ return scored
56
+ .filter(s => s.score > 0.5) // Minimum confidence threshold
57
+ .sort((a, b) => b.score - a.score)
58
+ .slice(0, 3) // Top 3 suggestions
59
+ .map(s => ({
60
+ template_id: s.template.id,
61
+ template_name: s.template.template_name,
62
+ confidence: s.score,
63
+ reason: explainSuggestion(s.template, analysis)
64
+ }));
65
+ }
66
+ ```
67
+
68
+ ### 3. Score Template Relevance
69
+
70
+ ```typescript
71
+ function calculateTemplateScore(
72
+ template: Template,
73
+ analysis: ContentAnalysis,
74
+ context: ConversationContext
75
+ ): number {
76
+ let score = 0;
77
+
78
+ // Keyword matching (0-0.4)
79
+ const keywordMatch = matchKeywords(
80
+ template.trigger_keywords,
81
+ analysis.keywords
82
+ );
83
+ score += keywordMatch * 0.4;
84
+
85
+ // Context pattern matching (0-0.3)
86
+ const contextMatch = matchContext(
87
+ template.trigger_context,
88
+ context
89
+ );
90
+ score += contextMatch * 0.3;
91
+
92
+ // Usage history (0-0.2)
93
+ const usageScore = Math.min(template.usage_count / 100, 1.0);
94
+ score += usageScore * 0.2;
95
+
96
+ // Recent usage (0-0.1)
97
+ if (template.last_used) {
98
+ const daysSince = daysBetween(now(), template.last_used);
99
+ if (daysSince < 7) {
100
+ score += 0.1;
101
+ }
102
+ }
103
+
104
+ return Math.min(score, 1.0);
105
+ }
106
+ ```
107
+
108
+ ### 4. Present Suggestions to User
109
+
110
+ ```typescript
111
+ // System suggests templates
112
+ const suggestions = await suggestTemplates(content, context);
113
+
114
+ // Present to user
115
+ if (suggestions.length > 0) {
116
+ return {
117
+ message: "I found some templates that might help structure this memory:",
118
+ suggestions: [
119
+ {
120
+ template_name: "Person Profile",
121
+ confidence: 0.85,
122
+ reason: "Detected person information with professional context",
123
+ preview_fields: ["name", "company", "job_title", "contact_info"]
124
+ },
125
+ {
126
+ template_name: "Professional Contact",
127
+ confidence: 0.72,
128
+ reason: "Matches professional networking pattern",
129
+ preview_fields: ["name", "company", "linkedin", "notes"]
130
+ }
131
+ ],
132
+ actions: [
133
+ "Use template",
134
+ "Create without template",
135
+ "View template details"
136
+ ]
137
+ };
138
+ }
139
+ ```
140
+
141
+ ### 5. User Selects Template (or Declines)
142
+
143
+ ```typescript
144
+ // Option A: User accepts template
145
+ remember_create_memory({
146
+ template_id: "template_person_profile_123",
147
+ content: {
148
+ name: "Sarah",
149
+ company: "Google",
150
+ job_title: "Product Manager",
151
+ met_at: "Tech Conference 2026",
152
+ notes: "Discussed product management best practices"
153
+ }
154
+ })
155
+
156
+ // Option B: User declines template
157
+ remember_create_memory({
158
+ content: "Met Sarah at conference. Product manager at Google.",
159
+ // No template - free-form memory
160
+ })
161
+ ```
162
+
163
+ ---
164
+
165
+ ## Template Matching Strategies
166
+
167
+ ### 1. Keyword Matching
168
+
169
+ ```typescript
170
+ function matchKeywords(
171
+ template_keywords: string[],
172
+ content_keywords: string[]
173
+ ): number {
174
+ const matches = template_keywords.filter(tk =>
175
+ content_keywords.some(ck =>
176
+ ck.toLowerCase().includes(tk.toLowerCase()) ||
177
+ tk.toLowerCase().includes(ck.toLowerCase())
178
+ )
179
+ );
180
+
181
+ return matches.length / template_keywords.length;
182
+ }
183
+
184
+ // Example
185
+ Template: "Person Profile"
186
+ trigger_keywords: ["met", "person", "contact", "introduced"]
187
+
188
+ Content: "Met Sarah at conference"
189
+ keywords: ["met", "sarah", "conference"]
190
+
191
+ Match: 1/4 = 0.25
192
+ ```
193
+
194
+ ### 2. Context Pattern Matching
195
+
196
+ ```typescript
197
+ function matchContext(
198
+ template_context: TriggerContext,
199
+ actual_context: ConversationContext
200
+ ): number {
201
+ let score = 0;
202
+ let checks = 0;
203
+
204
+ // Check location presence
205
+ if (template_context.location_present !== undefined) {
206
+ checks++;
207
+ if ((template_context.location_present && actual_context.location) ||
208
+ (!template_context.location_present && !actual_context.location)) {
209
+ score++;
210
+ }
211
+ }
212
+
213
+ // Check time of day
214
+ if (template_context.time_of_day) {
215
+ checks++;
216
+ const hour = actual_context.timestamp.getHours();
217
+ const timeOfDay = hour < 12 ? 'morning' : hour < 17 ? 'afternoon' : 'evening';
218
+ if (template_context.time_of_day.includes(timeOfDay)) {
219
+ score++;
220
+ }
221
+ }
222
+
223
+ // Check conversation type
224
+ if (template_context.conversation_type) {
225
+ checks++;
226
+ if (template_context.conversation_type === actual_context.type) {
227
+ score++;
228
+ }
229
+ }
230
+
231
+ return checks > 0 ? score / checks : 0;
232
+ }
233
+ ```
234
+
235
+ ### 3. Semantic Similarity
236
+
237
+ ```typescript
238
+ async function matchSemanticSimilarity(
239
+ template: Template,
240
+ content: string
241
+ ): Promise<number> {
242
+ // Get embedding for content
243
+ const contentEmbedding = await getEmbedding(content);
244
+
245
+ // Get embedding for template description
246
+ const templateEmbedding = await getEmbedding(template.template_description);
247
+
248
+ // Calculate cosine similarity
249
+ return cosineSimilarity(contentEmbedding, templateEmbedding);
250
+ }
251
+ ```
252
+
253
+ ### 4. Usage Pattern Learning
254
+
255
+ ```typescript
256
+ async function learnFromUsage(
257
+ user_id: string,
258
+ content: string,
259
+ selected_template_id: string | null
260
+ ): Promise<void> {
261
+ // Track what templates user selects for what content
262
+ await recordTemplateSelection({
263
+ user_id,
264
+ content_summary: content.substring(0, 200),
265
+ content_keywords: extractKeywords(content),
266
+ selected_template_id,
267
+ timestamp: new Date()
268
+ });
269
+
270
+ // Over time, learn user preferences
271
+ // If user always selects "Person Profile" for networking contexts,
272
+ // boost that template's score in similar contexts
273
+ }
274
+ ```
275
+
276
+ ---
277
+
278
+ ## Template Storage & Retrieval
279
+
280
+ ### Template Collection in Weaviate
281
+
282
+ ```yaml
283
+ # Collection: Template_{user_id}
284
+ Template:
285
+ id: uuid
286
+ user_id: string
287
+ template_name: string
288
+ template_description: string
289
+
290
+ # Fields definition
291
+ fields: array
292
+
293
+ # Auto-suggestion config
294
+ auto_apply: boolean
295
+ trigger_keywords: array
296
+ trigger_context: object
297
+
298
+ # Usage tracking
299
+ usage_count: int
300
+ last_used: datetime
301
+ success_rate: float # How often user accepts suggestion
302
+
303
+ # Metadata
304
+ created_at: datetime
305
+ updated_at: datetime
306
+
307
+ # Vector embedding (for semantic matching)
308
+ embedding: vector
309
+ ```
310
+
311
+ ### Query Templates
312
+
313
+ ```typescript
314
+ async function getRelevantTemplates(
315
+ user_id: string,
316
+ content: string,
317
+ context: ConversationContext
318
+ ): Promise<Template[]> {
319
+ // 1. Get user's templates with auto_apply enabled
320
+ const userTemplates = await weaviateClient.searchDocuments(
321
+ content, // Semantic search based on content
322
+ {
323
+ user_id,
324
+ auto_apply: true
325
+ },
326
+ 10 // Top 10 templates
327
+ );
328
+
329
+ // 2. Also check global/shared templates (if any)
330
+ const globalTemplates = await weaviateClient.searchDocuments(
331
+ content,
332
+ {
333
+ user_id: 'global',
334
+ auto_apply: true,
335
+ is_public: true
336
+ },
337
+ 5 // Top 5 global templates
338
+ );
339
+
340
+ return [...userTemplates, ...globalTemplates];
341
+ }
342
+ ```
343
+
344
+ ---
345
+
346
+ ## Example Scenarios
347
+
348
+ ### Scenario 1: Meeting Notes
349
+
350
+ ```typescript
351
+ // User says: "Had a great meeting with the design team today"
352
+
353
+ // System analyzes
354
+ analysis = {
355
+ keywords: ["meeting", "design team", "today"],
356
+ intent: "recording_meeting",
357
+ context_type: "work"
358
+ }
359
+
360
+ // Templates queried
361
+ templates = [
362
+ {
363
+ name: "Meeting Notes",
364
+ trigger_keywords: ["meeting", "discussed", "team"],
365
+ score: 0.92
366
+ },
367
+ {
368
+ name: "Work Event",
369
+ trigger_keywords: ["work", "team", "project"],
370
+ score: 0.68
371
+ }
372
+ ]
373
+
374
+ // Suggestion presented
375
+ "Would you like to use the 'Meeting Notes' template? It includes fields for:
376
+ - Attendees
377
+ - Agenda items
378
+ - Decisions made
379
+ - Action items"
380
+ ```
381
+
382
+ ### Scenario 2: Restaurant Visit
383
+
384
+ ```typescript
385
+ // User says: "Had amazing sushi at Nobu last night"
386
+
387
+ // System analyzes
388
+ analysis = {
389
+ keywords: ["sushi", "Nobu", "last night"],
390
+ entities: ["Nobu"],
391
+ intent: "recording_experience",
392
+ context_type: "dining",
393
+ location_present: true
394
+ }
395
+
396
+ // Template matched
397
+ template = {
398
+ name: "Restaurant Review",
399
+ trigger_keywords: ["restaurant", "ate at", "dinner", "lunch"],
400
+ trigger_context: {
401
+ location_present: true,
402
+ time_of_day: ["lunch", "dinner"]
403
+ },
404
+ score: 0.88
405
+ }
406
+
407
+ // Suggestion
408
+ "Would you like to use the 'Restaurant Review' template? It includes:
409
+ - Restaurant name
410
+ - Cuisine type
411
+ - Rating (1-5)
412
+ - Favorite dishes
413
+ - Would return?"
414
+ ```
415
+
416
+ ### Scenario 3: Book Finished
417
+
418
+ ```typescript
419
+ // User says: "Just finished reading 'The Pragmatic Programmer'"
420
+
421
+ // System analyzes
422
+ analysis = {
423
+ keywords: ["finished reading", "book"],
424
+ entities: ["The Pragmatic Programmer"],
425
+ intent: "recording_completion",
426
+ context_type: "learning"
427
+ }
428
+
429
+ // Template matched
430
+ template = {
431
+ name: "Book Review",
432
+ trigger_keywords: ["finished reading", "just read", "book"],
433
+ score: 0.95
434
+ }
435
+
436
+ // Suggestion
437
+ "Would you like to use the 'Book Review' template? It includes:
438
+ - Title
439
+ - Author
440
+ - Rating
441
+ - Summary
442
+ - Favorite quotes
443
+ - Would recommend?"
444
+ ```
445
+
446
+ ---
447
+
448
+ ## Template Suggestion API
449
+
450
+ ### New Tool: `remember_suggest_templates`
451
+
452
+ ```typescript
453
+ remember_suggest_templates({
454
+ content: string, // Memory content to analyze
455
+ context: ConversationContext, // Current conversation context
456
+ limit: number // Max suggestions (default: 3)
457
+ }): TemplateSuggestion[]
458
+
459
+ interface TemplateSuggestion {
460
+ template_id: string;
461
+ template_name: string;
462
+ template_description: string;
463
+ confidence: number; // 0-1, how confident in suggestion
464
+ reason: string; // Why this template was suggested
465
+ preview_fields: string[]; // Key fields in template
466
+ usage_count: number; // How many times user has used this
467
+ last_used: Date | null; // When user last used this
468
+ }
469
+ ```
470
+
471
+ ### Integration with `remember_create_memory`
472
+
473
+ ```typescript
474
+ // Option 1: Explicit template selection
475
+ remember_create_memory({
476
+ template_id: "template_person_profile_123",
477
+ content: { /* structured data */ }
478
+ })
479
+
480
+ // Option 2: Auto-suggest (system suggests, user confirms)
481
+ remember_create_memory({
482
+ content: "Met Sarah at conference...",
483
+ auto_suggest_template: true // System will suggest templates
484
+ })
485
+
486
+ // Option 3: No template
487
+ remember_create_memory({
488
+ content: "Random thought about camping",
489
+ use_template: false // Skip template suggestion
490
+ })
491
+ ```
492
+
493
+ ---
494
+
495
+ ## Template Learning & Improvement
496
+
497
+ ### 1. Track Suggestion Acceptance
498
+
499
+ ```typescript
500
+ interface TemplateSuggestionLog {
501
+ user_id: string;
502
+ content_summary: string;
503
+ suggested_templates: array;
504
+ selected_template_id: string | null;
505
+ accepted: boolean;
506
+ timestamp: datetime;
507
+ }
508
+
509
+ // When user accepts/declines
510
+ await logSuggestion({
511
+ user_id,
512
+ content_summary: content.substring(0, 200),
513
+ suggested_templates: suggestions.map(s => s.template_id),
514
+ selected_template_id: user_selected_id,
515
+ accepted: user_selected_id !== null,
516
+ timestamp: new Date()
517
+ });
518
+ ```
519
+
520
+ ### 2. Improve Suggestions Over Time
521
+
522
+ ```typescript
523
+ async function improveTemplateSuggestions(user_id: string): Promise<void> {
524
+ // Analyze user's template selection history
525
+ const history = await getTemplateSuggestionHistory(user_id);
526
+
527
+ // Calculate acceptance rate per template
528
+ const stats = history.reduce((acc, log) => {
529
+ log.suggested_templates.forEach(tid => {
530
+ if (!acc[tid]) {
531
+ acc[tid] = { suggested: 0, accepted: 0 };
532
+ }
533
+ acc[tid].suggested++;
534
+ if (log.selected_template_id === tid) {
535
+ acc[tid].accepted++;
536
+ }
537
+ });
538
+ return acc;
539
+ }, {});
540
+
541
+ // Update template success_rate
542
+ for (const [template_id, stat] of Object.entries(stats)) {
543
+ const success_rate = stat.accepted / stat.suggested;
544
+ await updateTemplate(template_id, {
545
+ success_rate,
546
+ user_preference_score: success_rate // Boost for this user
547
+ });
548
+ }
549
+ }
550
+ ```
551
+
552
+ ### 3. Personalized Template Ranking
553
+
554
+ ```typescript
555
+ function calculatePersonalizedScore(
556
+ template: Template,
557
+ base_score: number,
558
+ user_id: string
559
+ ): number {
560
+ // Get user's history with this template
561
+ const userStats = template.user_stats?.[user_id];
562
+
563
+ if (!userStats) {
564
+ return base_score; // No history, use base score
565
+ }
566
+
567
+ // Boost based on user's acceptance rate
568
+ const personalBoost = userStats.success_rate * 0.3;
569
+
570
+ // Boost based on recent usage
571
+ const daysSinceUse = daysBetween(now(), userStats.last_used);
572
+ const recencyBoost = daysSinceUse < 7 ? 0.2 : daysSinceUse < 30 ? 0.1 : 0;
573
+
574
+ return Math.min(base_score + personalBoost + recencyBoost, 1.0);
575
+ }
576
+ ```
577
+
578
+ ---
579
+
580
+ ## Template Trigger Configuration
581
+
582
+ ### Keyword Triggers
583
+
584
+ ```yaml
585
+ Template: "Restaurant Review"
586
+ trigger_keywords:
587
+ - "restaurant"
588
+ - "ate at"
589
+ - "dinner at"
590
+ - "lunch at"
591
+ - "food at"
592
+ - "tried"
593
+ - "cuisine"
594
+ ```
595
+
596
+ ### Context Triggers
597
+
598
+ ```yaml
599
+ Template: "Restaurant Review"
600
+ trigger_context:
601
+ location_present: true
602
+ time_of_day: ["lunch", "dinner"]
603
+ keywords_required: 1 # At least 1 trigger keyword must match
604
+
605
+ Template: "Meeting Notes"
606
+ trigger_context:
607
+ time_of_day: ["morning", "afternoon"]
608
+ day_of_week: ["monday", "tuesday", "wednesday", "thursday", "friday"]
609
+ keywords_required: 1
610
+ location_type: "office" # If location matches office
611
+ ```
612
+
613
+ ### Entity Triggers
614
+
615
+ ```yaml
616
+ Template: "Book Review"
617
+ trigger_entities:
618
+ - type: "book_title"
619
+ confidence: 0.7
620
+ - type: "author_name"
621
+ confidence: 0.5
622
+
623
+ Template: "Person Profile"
624
+ trigger_entities:
625
+ - type: "person_name"
626
+ confidence: 0.8
627
+ - type: "company_name"
628
+ confidence: 0.6
629
+ ```
630
+
631
+ ---
632
+
633
+ ## Advanced Features
634
+
635
+ ### 1. Multi-Template Suggestions
636
+
637
+ ```typescript
638
+ // User says: "Met Sarah at Nobu for dinner to discuss the project"
639
+
640
+ // Multiple templates could apply
641
+ suggestions = [
642
+ {
643
+ template: "Person Profile",
644
+ confidence: 0.85,
645
+ reason: "Detected person information (Sarah)"
646
+ },
647
+ {
648
+ template: "Restaurant Review",
649
+ confidence: 0.78,
650
+ reason: "Detected dining experience (Nobu, dinner)"
651
+ },
652
+ {
653
+ template: "Meeting Notes",
654
+ confidence: 0.72,
655
+ reason: "Detected discussion context (discuss project)"
656
+ }
657
+ ]
658
+
659
+ // System can suggest creating multiple memories
660
+ "This could be recorded as multiple memories:
661
+ 1. Person Profile for Sarah
662
+ 2. Restaurant Review for Nobu
663
+ 3. Meeting Notes for project discussion
664
+
665
+ Would you like to create all three, or just one?"
666
+ ```
667
+
668
+ ### 2. Template Chaining
669
+
670
+ ```typescript
671
+ // Some templates can trigger related templates
672
+ Template: "Meeting Notes"
673
+ related_templates: [
674
+ {
675
+ template_id: "action_items",
676
+ auto_create: true, // Auto-create if meeting has action items
677
+ condition: "has_action_items"
678
+ },
679
+ {
680
+ template_id: "person_profile",
681
+ suggest: true, // Suggest for new attendees
682
+ condition: "has_new_attendees"
683
+ }
684
+ ]
685
+ ```
686
+
687
+ ### 3. Template Composition
688
+
689
+ ```typescript
690
+ // Combine multiple templates
691
+ Template: "Business Contact"
692
+ composed_from: [
693
+ "Person Profile", // Base template
694
+ "Professional Info" // Additional fields
695
+ ]
696
+
697
+ // Inherits fields from both templates
698
+ fields: [
699
+ ...PersonProfile.fields,
700
+ ...ProfessionalInfo.fields
701
+ ]
702
+ ```
703
+
704
+ ---
705
+
706
+ ## User Experience
707
+
708
+ ### Suggestion Modes
709
+
710
+ #### 1. **Automatic (Default)**
711
+ ```
712
+ User: "Met Sarah at conference"
713
+ System: "💡 Suggestion: Use 'Person Profile' template?
714
+ [Yes] [No] [View Template]"
715
+ ```
716
+
717
+ #### 2. **Manual**
718
+ ```
719
+ User: "Create memory with template"
720
+ System: "Which template would you like to use?
721
+ - Person Profile
722
+ - Meeting Notes
723
+ - Restaurant Review
724
+ [Or create without template]"
725
+ ```
726
+
727
+ #### 3. **Silent**
728
+ ```
729
+ User preference: auto_suggest_templates = false
730
+ System: Creates memory without suggesting templates
731
+ ```
732
+
733
+ ### Template Preview
734
+
735
+ ```typescript
736
+ // User clicks "View Template"
737
+ {
738
+ template_name: "Person Profile",
739
+ description: "Track information about people you meet",
740
+ fields: [
741
+ { name: "name", type: "string", required: true },
742
+ { name: "company", type: "string", required: false },
743
+ { name: "job_title", type: "string", required: false },
744
+ { name: "contact_info", type: "object", required: false },
745
+ { name: "met_at", type: "string", required: false },
746
+ { name: "notes", type: "text", required: false }
747
+ ],
748
+ usage_count: 42,
749
+ last_used: "2026-02-10",
750
+ example: {
751
+ name: "John Doe",
752
+ company: "Acme Corp",
753
+ job_title: "Software Engineer",
754
+ met_at: "Tech Conference 2026"
755
+ }
756
+ }
757
+ ```
758
+
759
+ ---
760
+
761
+ ## Performance Optimization
762
+
763
+ ### 1. Template Caching
764
+
765
+ ```typescript
766
+ // Cache user's templates in memory
767
+ const templateCache = new Map<string, Template[]>();
768
+
769
+ async function getUserTemplates(user_id: string): Promise<Template[]> {
770
+ // Check cache
771
+ if (templateCache.has(user_id)) {
772
+ return templateCache.get(user_id)!;
773
+ }
774
+
775
+ // Fetch from database
776
+ const templates = await weaviateClient.getTemplates(user_id);
777
+
778
+ // Cache for 5 minutes
779
+ templateCache.set(user_id, templates);
780
+ setTimeout(() => templateCache.delete(user_id), 300000);
781
+
782
+ return templates;
783
+ }
784
+ ```
785
+
786
+ ### 2. Precompute Template Embeddings
787
+
788
+ ```typescript
789
+ // When template created, compute embedding once
790
+ async function createTemplate(template: Template): Promise<string> {
791
+ // Compute embedding for template description
792
+ const embedding = await getEmbedding(template.template_description);
793
+
794
+ template.embedding = embedding;
795
+
796
+ return await weaviateClient.addDocument(template);
797
+ }
798
+
799
+ // During suggestion, use precomputed embeddings
800
+ // Much faster than computing on every suggestion
801
+ ```
802
+
803
+ ### 3. Batch Template Scoring
804
+
805
+ ```typescript
806
+ // Score all templates in parallel
807
+ async function scoreTemplates(
808
+ templates: Template[],
809
+ analysis: ContentAnalysis,
810
+ context: ConversationContext
811
+ ): Promise<ScoredTemplate[]> {
812
+ return await Promise.all(
813
+ templates.map(async template => ({
814
+ template,
815
+ score: await calculateTemplateScore(template, analysis, context)
816
+ }))
817
+ );
818
+ }
819
+ ```
820
+
821
+ ---
822
+
823
+ ## Implementation Checklist
824
+
825
+ ### Phase 1: Basic Suggestion
826
+ - [ ] Implement keyword matching
827
+ - [ ] Implement template query
828
+ - [ ] Implement suggestion API
829
+ - [ ] Add to `remember_create_memory` flow
830
+
831
+ ### Phase 2: Smart Matching
832
+ - [ ] Add context pattern matching
833
+ - [ ] Add semantic similarity
834
+ - [ ] Implement scoring algorithm
835
+ - [ ] Add confidence thresholds
836
+
837
+ ### Phase 3: Learning
838
+ - [ ] Track suggestion acceptance
839
+ - [ ] Implement usage pattern learning
840
+ - [ ] Personalized template ranking
841
+ - [ ] Success rate tracking
842
+
843
+ ### Phase 4: Advanced
844
+ - [ ] Multi-template suggestions
845
+ - [ ] Template chaining
846
+ - [ ] Template composition
847
+ - [ ] Auto-fill from context
848
+
849
+ ---
850
+
851
+ **Status**: Design Specification
852
+ **Key Innovation**: Automatic template suggestion based on content analysis and user patterns
853
+ **User Experience**: Seamless - system suggests, user confirms or declines