@cmdoss/memwal-sdk 0.7.0 → 0.8.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 (192) hide show
  1. package/README.md +129 -0
  2. package/dist/client/ClientMemoryManager.js +2 -2
  3. package/dist/client/ClientMemoryManager.js.map +1 -1
  4. package/dist/client/PersonalDataWallet.d.ts.map +1 -1
  5. package/dist/client/SimplePDWClient.d.ts +28 -0
  6. package/dist/client/SimplePDWClient.d.ts.map +1 -1
  7. package/dist/client/SimplePDWClient.js +29 -6
  8. package/dist/client/SimplePDWClient.js.map +1 -1
  9. package/dist/client/namespaces/MemoryNamespace.d.ts +4 -0
  10. package/dist/client/namespaces/MemoryNamespace.d.ts.map +1 -1
  11. package/dist/client/namespaces/MemoryNamespace.js +168 -39
  12. package/dist/client/namespaces/MemoryNamespace.js.map +1 -1
  13. package/dist/client/namespaces/consolidated/BlockchainNamespace.d.ts +12 -2
  14. package/dist/client/namespaces/consolidated/BlockchainNamespace.d.ts.map +1 -1
  15. package/dist/client/namespaces/consolidated/BlockchainNamespace.js +40 -2
  16. package/dist/client/namespaces/consolidated/BlockchainNamespace.js.map +1 -1
  17. package/dist/client/namespaces/consolidated/StorageNamespace.d.ts +67 -2
  18. package/dist/client/namespaces/consolidated/StorageNamespace.d.ts.map +1 -1
  19. package/dist/client/namespaces/consolidated/StorageNamespace.js +549 -16
  20. package/dist/client/namespaces/consolidated/StorageNamespace.js.map +1 -1
  21. package/dist/config/ConfigurationHelper.js +61 -61
  22. package/dist/config/defaults.js +2 -2
  23. package/dist/config/defaults.js.map +1 -1
  24. package/dist/graph/GraphService.js +20 -20
  25. package/dist/infrastructure/seal/EncryptionService.d.ts +9 -5
  26. package/dist/infrastructure/seal/EncryptionService.d.ts.map +1 -1
  27. package/dist/infrastructure/seal/EncryptionService.js +37 -15
  28. package/dist/infrastructure/seal/EncryptionService.js.map +1 -1
  29. package/dist/infrastructure/seal/SealService.d.ts +13 -5
  30. package/dist/infrastructure/seal/SealService.d.ts.map +1 -1
  31. package/dist/infrastructure/seal/SealService.js +36 -34
  32. package/dist/infrastructure/seal/SealService.js.map +1 -1
  33. package/dist/langchain/createPDWRAG.js +30 -30
  34. package/dist/retrieval/MemoryDecryptionPipeline.d.ts.map +1 -1
  35. package/dist/retrieval/MemoryDecryptionPipeline.js +2 -1
  36. package/dist/retrieval/MemoryDecryptionPipeline.js.map +1 -1
  37. package/dist/services/CapabilityService.d.ts.map +1 -1
  38. package/dist/services/CapabilityService.js +30 -14
  39. package/dist/services/CapabilityService.js.map +1 -1
  40. package/dist/services/CrossContextPermissionService.d.ts.map +1 -1
  41. package/dist/services/CrossContextPermissionService.js +9 -7
  42. package/dist/services/CrossContextPermissionService.js.map +1 -1
  43. package/dist/services/EncryptionService.d.ts.map +1 -1
  44. package/dist/services/EncryptionService.js +6 -5
  45. package/dist/services/EncryptionService.js.map +1 -1
  46. package/dist/services/GeminiAIService.js +309 -309
  47. package/dist/services/StorageService.d.ts +1 -0
  48. package/dist/services/StorageService.d.ts.map +1 -1
  49. package/dist/services/StorageService.js +60 -10
  50. package/dist/services/StorageService.js.map +1 -1
  51. package/dist/services/TransactionService.d.ts +20 -0
  52. package/dist/services/TransactionService.d.ts.map +1 -1
  53. package/dist/services/TransactionService.js +43 -0
  54. package/dist/services/TransactionService.js.map +1 -1
  55. package/dist/services/ViewService.js +2 -2
  56. package/dist/services/ViewService.js.map +1 -1
  57. package/package.json +1 -1
  58. package/src/access/PermissionService.ts +635 -635
  59. package/src/access/index.ts +8 -8
  60. package/src/aggregation/AggregationService.ts +389 -389
  61. package/src/aggregation/index.ts +8 -8
  62. package/src/ai-sdk/PDWVectorStore.ts +715 -715
  63. package/src/ai-sdk/index.ts +65 -65
  64. package/src/ai-sdk/tools.ts +460 -460
  65. package/src/ai-sdk/types.ts +404 -404
  66. package/src/batch/BatchManager.ts +597 -597
  67. package/src/batch/BatchingService.ts +429 -429
  68. package/src/batch/MemoryProcessingCache.ts +492 -492
  69. package/src/batch/index.ts +30 -30
  70. package/src/browser.ts +200 -200
  71. package/src/client/ClientMemoryManager.ts +987 -987
  72. package/src/client/PersonalDataWallet.ts +345 -345
  73. package/src/client/SimplePDWClient.ts +1289 -1237
  74. package/src/client/factory.ts +154 -154
  75. package/src/client/namespaces/AnalyticsNamespace.ts +377 -377
  76. package/src/client/namespaces/BatchNamespace.ts +356 -356
  77. package/src/client/namespaces/CacheNamespace.ts +123 -123
  78. package/src/client/namespaces/CapabilityNamespace.ts +217 -217
  79. package/src/client/namespaces/ClassifyNamespace.ts +169 -169
  80. package/src/client/namespaces/ContextNamespace.ts +297 -297
  81. package/src/client/namespaces/EmbeddingsNamespace.ts +99 -99
  82. package/src/client/namespaces/EncryptionNamespace.ts +221 -221
  83. package/src/client/namespaces/GraphNamespace.ts +468 -468
  84. package/src/client/namespaces/IndexNamespace.ts +361 -361
  85. package/src/client/namespaces/MemoryNamespace.ts +1422 -1272
  86. package/src/client/namespaces/PermissionsNamespace.ts +254 -254
  87. package/src/client/namespaces/PipelineNamespace.ts +220 -220
  88. package/src/client/namespaces/SearchNamespace.ts +1049 -1049
  89. package/src/client/namespaces/StorageNamespace.ts +458 -458
  90. package/src/client/namespaces/TxNamespace.ts +260 -260
  91. package/src/client/namespaces/WalletNamespace.ts +243 -243
  92. package/src/client/namespaces/consolidated/AINamespace.ts +449 -449
  93. package/src/client/namespaces/consolidated/BlockchainNamespace.ts +607 -564
  94. package/src/client/namespaces/consolidated/SecurityNamespace.ts +648 -648
  95. package/src/client/namespaces/consolidated/StorageNamespace.ts +1141 -497
  96. package/src/client/namespaces/consolidated/index.ts +39 -39
  97. package/src/client/signers/DappKitSigner.ts +207 -207
  98. package/src/client/signers/KeypairSigner.ts +108 -108
  99. package/src/client/signers/UnifiedSigner.ts +110 -110
  100. package/src/client/signers/WalletAdapterSigner.ts +159 -159
  101. package/src/client/signers/index.ts +26 -26
  102. package/src/config/ConfigurationHelper.ts +412 -412
  103. package/src/config/defaults.ts +51 -51
  104. package/src/config/index.ts +8 -8
  105. package/src/config/validation.ts +70 -70
  106. package/src/core/index.ts +14 -14
  107. package/src/core/interfaces/IService.ts +307 -307
  108. package/src/core/interfaces/index.ts +8 -8
  109. package/src/core/types/capability.ts +297 -297
  110. package/src/core/types/index.ts +870 -870
  111. package/src/core/types/wallet.ts +270 -270
  112. package/src/core/types.ts +9 -9
  113. package/src/core/wallet.ts +222 -222
  114. package/src/embedding/index.ts +19 -19
  115. package/src/embedding/types.ts +357 -357
  116. package/src/errors/index.ts +602 -602
  117. package/src/errors/recovery.ts +461 -461
  118. package/src/errors/validation.ts +567 -567
  119. package/src/generated/pdw/capability.ts +319 -319
  120. package/src/generated/pdw/deps/sui/object.ts +12 -12
  121. package/src/generated/pdw/deps/sui/vec_map.ts +32 -32
  122. package/src/generated/pdw/memory.ts +1087 -1087
  123. package/src/generated/pdw/wallet.ts +123 -123
  124. package/src/generated/utils/index.ts +159 -159
  125. package/src/graph/GraphService.ts +887 -887
  126. package/src/graph/KnowledgeGraphManager.ts +728 -728
  127. package/src/graph/index.ts +25 -25
  128. package/src/index.ts +498 -498
  129. package/src/infrastructure/index.ts +22 -22
  130. package/src/infrastructure/seal/EncryptionService.ts +628 -603
  131. package/src/infrastructure/seal/SealService.ts +613 -615
  132. package/src/infrastructure/seal/index.ts +9 -9
  133. package/src/infrastructure/sui/BlockchainManager.ts +627 -627
  134. package/src/infrastructure/sui/SuiService.ts +888 -888
  135. package/src/infrastructure/sui/index.ts +9 -9
  136. package/src/infrastructure/walrus/StorageManager.ts +604 -604
  137. package/src/infrastructure/walrus/WalrusStorageService.ts +612 -612
  138. package/src/infrastructure/walrus/index.ts +9 -9
  139. package/src/langchain/PDWEmbeddings.ts +145 -145
  140. package/src/langchain/PDWVectorStore.ts +456 -456
  141. package/src/langchain/createPDWRAG.ts +303 -303
  142. package/src/langchain/index.ts +47 -47
  143. package/src/permissions/ConsentRepository.browser.ts +249 -249
  144. package/src/permissions/ConsentRepository.ts +364 -364
  145. package/src/permissions/index.ts +9 -9
  146. package/src/pipeline/MemoryPipeline.ts +862 -862
  147. package/src/pipeline/PipelineManager.ts +683 -683
  148. package/src/pipeline/index.ts +26 -26
  149. package/src/retrieval/AdvancedSearchService.ts +629 -629
  150. package/src/retrieval/MemoryAnalyticsService.ts +711 -711
  151. package/src/retrieval/MemoryDecryptionPipeline.ts +825 -824
  152. package/src/retrieval/MemoryRetrievalService.ts +904 -904
  153. package/src/retrieval/index.ts +42 -42
  154. package/src/services/BatchService.ts +352 -352
  155. package/src/services/CapabilityService.ts +464 -448
  156. package/src/services/ClassifierService.ts +465 -465
  157. package/src/services/CrossContextPermissionService.ts +486 -484
  158. package/src/services/EmbeddingService.ts +771 -771
  159. package/src/services/EncryptionService.ts +712 -711
  160. package/src/services/GeminiAIService.ts +753 -753
  161. package/src/services/IndexManager.ts +977 -977
  162. package/src/services/MemoryIndexService.ts +1003 -1003
  163. package/src/services/MemoryService.ts +369 -369
  164. package/src/services/QueryService.ts +890 -890
  165. package/src/services/StorageService.ts +1182 -1126
  166. package/src/services/TransactionService.ts +838 -790
  167. package/src/services/VectorService.ts +462 -462
  168. package/src/services/ViewService.ts +484 -484
  169. package/src/services/index.ts +25 -25
  170. package/src/services/storage/BlobAttributesManager.ts +333 -333
  171. package/src/services/storage/KnowledgeGraphManager.ts +425 -425
  172. package/src/services/storage/MemorySearchManager.ts +387 -387
  173. package/src/services/storage/QuiltBatchManager.ts +1130 -1130
  174. package/src/services/storage/WalrusMetadataManager.ts +268 -268
  175. package/src/services/storage/WalrusStorageManager.ts +287 -287
  176. package/src/services/storage/index.ts +57 -57
  177. package/src/types/index.ts +13 -13
  178. package/src/utils/LRUCache.ts +378 -378
  179. package/src/utils/index.ts +76 -76
  180. package/src/utils/memoryIndexOnChain.ts +507 -507
  181. package/src/utils/rebuildIndex.ts +290 -290
  182. package/src/utils/rebuildIndexNode.ts +771 -771
  183. package/src/vector/BrowserHnswIndexService.ts +758 -758
  184. package/src/vector/HnswWasmService.ts +731 -731
  185. package/src/vector/IHnswService.ts +233 -233
  186. package/src/vector/NodeHnswService.ts +833 -833
  187. package/src/vector/VectorManager.ts +478 -478
  188. package/src/vector/createHnswService.ts +135 -135
  189. package/src/vector/index.ts +56 -56
  190. package/src/wallet/ContextWalletService.ts +656 -656
  191. package/src/wallet/MainWalletService.ts +317 -317
  192. package/src/wallet/index.ts +17 -17
@@ -130,15 +130,15 @@ export class GeminiAIService {
130
130
  */
131
131
  async analyzeContent(content) {
132
132
  try {
133
- const prompt = `
134
- Analyze the following text and provide a JSON response with:
135
- - "categories": array of relevant categories (max 3)
136
- - "sentiment": "positive", "negative", or "neutral"
137
- - "topics": array of main topics/themes (max 5)
138
- - "confidence": overall analysis confidence (0.0-1.0)
139
-
140
- TEXT: ${content}
141
-
133
+ const prompt = `
134
+ Analyze the following text and provide a JSON response with:
135
+ - "categories": array of relevant categories (max 3)
136
+ - "sentiment": "positive", "negative", or "neutral"
137
+ - "topics": array of main topics/themes (max 5)
138
+ - "confidence": overall analysis confidence (0.0-1.0)
139
+
140
+ TEXT: ${content}
141
+
142
142
  JSON:`;
143
143
  const text = await this.callOpenRouter(prompt);
144
144
  return this.parseAnalysisResponse(text);
@@ -156,291 +156,291 @@ JSON:`;
156
156
  // ==================== PRIVATE METHODS ====================
157
157
  buildExtractionPrompt(content, context) {
158
158
  const contextSection = context ? `\nCONTEXT: ${context}\n` : '';
159
- return `
160
- You are a knowledge graph extraction system for a Personal Data Wallet application. Your task is to extract meaningful entities and relationships from personal memories, notes, and user statements.
161
-
162
- ## CRITICAL RULE: User Entity
163
- ALWAYS include a "user" entity to represent the person who wrote this memory:
164
- {
165
- "id": "user",
166
- "label": "User",
167
- "type": "person",
168
- "confidence": 1.0
169
- }
170
- This "user" entity should be the source or target of relationships describing personal preferences, attributes, or experiences.
171
-
172
- ## Entity Types (Comprehensive List)
173
-
174
- ### People & Social
175
- - **person**: Individual people, including the user themselves
176
- - Examples: "user", "john_doe", "my_mother", "boss"
177
- - Properties: name, role, relationship_to_user
178
-
179
- ### Organizations & Groups
180
- - **organization**: Companies, institutions, teams, communities
181
- - Examples: "google", "harvard_university", "local_gym"
182
- - Properties: industry, size, location
183
-
184
- ### Locations & Places
185
- - **location**: Geographic places, addresses, venues
186
- - Examples: "ho_chi_minh_city", "vietnam", "my_office", "central_park"
187
- - Properties: type (city/country/venue), coordinates
188
-
189
- ### Food & Dining
190
- - **food**: Foods, dishes, cuisines, beverages, ingredients
191
- - Examples: "spaghetti", "vietnamese_cuisine", "coffee", "chocolate"
192
- - Properties: cuisine_type, meal_type, dietary_info
193
- - **restaurant**: Eating establishments
194
- - Examples: "starbucks", "local_pho_shop"
195
- - Properties: cuisine, price_range
196
-
197
- ### Preferences & Interests
198
- - **preference**: General likes, dislikes, favorites
199
- - Examples: "blue_color", "morning_routine", "minimalist_style"
200
- - Properties: sentiment (positive/negative/neutral), intensity (1-10)
201
- - **hobby**: Recreational activities, pastimes
202
- - Examples: "playing_guitar", "photography", "hiking", "gaming"
203
- - Properties: frequency, skill_level
204
- - **interest**: Topics of curiosity or passion
205
- - Examples: "artificial_intelligence", "history", "cooking"
206
- - Properties: depth (casual/moderate/deep)
207
-
208
- ### Skills & Abilities
209
- - **skill**: Technical or soft skills, expertise areas
210
- - Examples: "python_programming", "public_speaking", "cooking"
211
- - Properties: proficiency (beginner/intermediate/expert)
212
- - **language**: Languages known or being learned
213
- - Examples: "english", "vietnamese", "japanese"
214
- - Properties: proficiency, native (true/false)
215
-
216
- ### Objects & Possessions
217
- - **object**: Physical items, products, tools
218
- - Examples: "macbook_pro", "my_car", "guitar"
219
- - Properties: brand, model, acquisition_date
220
- - **digital_product**: Software, apps, digital services
221
- - Examples: "spotify", "notion", "chatgpt"
222
- - Properties: category, usage_frequency
223
-
224
- ### Time & Events
225
- - **event**: Occasions, milestones, meetings
226
- - Examples: "birthday_2024", "job_interview", "vacation_trip"
227
- - Properties: date, duration, importance
228
- - **routine**: Regular activities or habits
229
- - Examples: "morning_workout", "weekly_meeting", "daily_meditation"
230
- - Properties: frequency, time_of_day
231
-
232
- ### Abstract & Conceptual
233
- - **concept**: Ideas, topics, abstract things
234
- - Examples: "work_life_balance", "productivity", "happiness"
235
- - **goal**: Objectives, aspirations, plans
236
- - Examples: "learn_japanese", "run_marathon", "save_money"
237
- - Properties: deadline, priority, status
238
- - **emotion**: Feelings, moods, emotional states
239
- - Examples: "happiness", "stress", "excitement"
240
- - Properties: intensity, trigger
241
-
242
- ### Health & Wellness
243
- - **health_condition**: Medical conditions, allergies
244
- - Examples: "lactose_intolerance", "migraine", "allergy_to_peanuts"
245
- - **medication**: Medicines, supplements
246
- - Examples: "vitamin_d", "aspirin"
247
- - **exercise**: Physical activities for health
248
- - Examples: "running", "yoga", "weight_training"
249
-
250
- ### Media & Entertainment
251
- - **music**: Songs, artists, genres, albums
252
- - Examples: "jazz_music", "beatles", "classical_piano"
253
- - **movie**: Films, TV shows, documentaries
254
- - Examples: "inception", "game_of_thrones"
255
- - **book**: Books, authors, genres
256
- - Examples: "atomic_habits", "fiction_genre"
257
- - **game**: Video games, board games
258
- - Examples: "chess", "minecraft"
259
-
260
- ## Relationship Types (Comprehensive List)
261
-
262
- ### Preference Relationships (source: usually "user")
263
- - **loves**: Strong positive preference (intensity 9-10)
264
- - **likes**: Moderate positive preference (intensity 6-8)
265
- - **enjoys**: Positive experience with something
266
- - **prefers**: Comparative preference
267
- - **favorite**: Top choice in a category
268
- - **interested_in**: Curiosity or engagement
269
- - **dislikes**: Moderate negative preference
270
- - **hates**: Strong negative preference (intensity 9-10)
271
- - **avoids**: Intentionally stays away from
272
- - **allergic_to**: Medical/physical aversion
273
-
274
- ### Affiliation Relationships
275
- - **works_at**: Employment relationship
276
- - **studies_at**: Educational institution
277
- - **member_of**: Group membership
278
- - **belongs_to**: General affiliation
279
- - **founded**: Created an organization
280
- - **leads**: Leadership role
281
-
282
- ### Location Relationships
283
- - **lives_in**: Current residence
284
- - **from**: Origin/hometown
285
- - **located_in**: Physical location
286
- - **visited**: Past travel
287
- - **wants_to_visit**: Travel aspiration
288
-
289
- ### Social Relationships
290
- - **knows**: Acquaintance
291
- - **friends_with**: Friendship
292
- - **family_of**: Family relationship (specify: parent, sibling, child, spouse)
293
- - **works_with**: Professional relationship
294
- - **mentored_by**: Learning relationship
295
-
296
- ### Skill & Knowledge Relationships
297
- - **has_skill**: Possesses ability
298
- - **expert_in**: High proficiency
299
- - **learning**: Currently acquiring
300
- - **wants_to_learn**: Aspiration to learn
301
- - **teaches**: Instructing others
302
- - **certified_in**: Formal qualification
303
-
304
- ### Possession & Usage
305
- - **owns**: Ownership
306
- - **uses**: Regular usage
307
- - **wants**: Desire to acquire
308
- - **recommends**: Positive endorsement
309
-
310
- ### Temporal Relationships
311
- - **started_on**: Beginning date
312
- - **ended_on**: Ending date
313
- - **scheduled_for**: Future event
314
- - **happens_during**: Temporal context
315
-
316
- ### Causal & Descriptive
317
- - **causes**: Causal relationship
318
- - **related_to**: General association
319
- - **part_of**: Component relationship
320
- - **similar_to**: Similarity
321
- - **opposite_of**: Contrast
322
-
323
- ## Output Format
324
-
325
- Return ONLY valid JSON with this structure:
326
- {
327
- "entities": [
328
- {
329
- "id": "snake_case_identifier",
330
- "label": "Human Readable Name",
331
- "type": "entity_type_from_list_above",
332
- "confidence": 0.0-1.0,
333
- "properties": { "optional": "attributes" }
334
- }
335
- ],
336
- "relationships": [
337
- {
338
- "source": "source_entity_id",
339
- "target": "target_entity_id",
340
- "label": "relationship_type_from_list_above",
341
- "confidence": 0.0-1.0,
342
- "type": "optional_category"
343
- }
344
- ]
345
- }
346
-
347
- ## Examples
348
-
349
- ### Example 1: Food Preference
350
- Input: "i love spaghetti"
351
- Output:
352
- {
353
- "entities": [
354
- {"id": "user", "label": "User", "type": "person", "confidence": 1.0},
355
- {"id": "spaghetti", "label": "Spaghetti", "type": "food", "confidence": 0.95, "properties": {"cuisine": "italian", "meal_type": "main_course"}}
356
- ],
357
- "relationships": [
358
- {"source": "user", "target": "spaghetti", "label": "loves", "confidence": 0.95, "type": "preference"}
359
- ]
360
- }
361
-
362
- ### Example 2: Multiple Preferences
363
- Input: "i like hamburgers but hate vegetables"
364
- Output:
365
- {
366
- "entities": [
367
- {"id": "user", "label": "User", "type": "person", "confidence": 1.0},
368
- {"id": "hamburgers", "label": "Hamburgers", "type": "food", "confidence": 0.95},
369
- {"id": "vegetables", "label": "Vegetables", "type": "food", "confidence": 0.95}
370
- ],
371
- "relationships": [
372
- {"source": "user", "target": "hamburgers", "label": "likes", "confidence": 0.9, "type": "preference"},
373
- {"source": "user", "target": "vegetables", "label": "dislikes", "confidence": 0.9, "type": "preference"}
374
- ]
375
- }
376
-
377
- ### Example 3: Work Information
378
- Input: "i work at Google as a software engineer in Mountain View"
379
- Output:
380
- {
381
- "entities": [
382
- {"id": "user", "label": "User", "type": "person", "confidence": 1.0, "properties": {"role": "software_engineer"}},
383
- {"id": "google", "label": "Google", "type": "organization", "confidence": 0.98, "properties": {"industry": "technology"}},
384
- {"id": "software_engineer", "label": "Software Engineer", "type": "skill", "confidence": 0.9},
385
- {"id": "mountain_view", "label": "Mountain View", "type": "location", "confidence": 0.95, "properties": {"type": "city"}}
386
- ],
387
- "relationships": [
388
- {"source": "user", "target": "google", "label": "works_at", "confidence": 0.98, "type": "affiliation"},
389
- {"source": "user", "target": "software_engineer", "label": "has_skill", "confidence": 0.9, "type": "skill"},
390
- {"source": "google", "target": "mountain_view", "label": "located_in", "confidence": 0.85, "type": "location"}
391
- ]
392
- }
393
-
394
- ### Example 4: Personal Life
395
- Input: "my name is Aaron and I live in Ho Chi Minh City with my wife"
396
- Output:
397
- {
398
- "entities": [
399
- {"id": "user", "label": "Aaron", "type": "person", "confidence": 1.0, "properties": {"name": "Aaron"}},
400
- {"id": "ho_chi_minh_city", "label": "Ho Chi Minh City", "type": "location", "confidence": 0.98, "properties": {"type": "city", "country": "Vietnam"}},
401
- {"id": "wife", "label": "Wife", "type": "person", "confidence": 0.9, "properties": {"relationship": "spouse"}}
402
- ],
403
- "relationships": [
404
- {"source": "user", "target": "ho_chi_minh_city", "label": "lives_in", "confidence": 0.98, "type": "location"},
405
- {"source": "user", "target": "wife", "label": "family_of", "confidence": 0.95, "type": "social", "properties": {"relationship_type": "spouse"}}
406
- ]
407
- }
408
-
409
- ### Example 5: Hobbies and Interests
410
- Input: "i enjoy playing guitar and listening to jazz music on weekends"
411
- Output:
412
- {
413
- "entities": [
414
- {"id": "user", "label": "User", "type": "person", "confidence": 1.0},
415
- {"id": "playing_guitar", "label": "Playing Guitar", "type": "hobby", "confidence": 0.95},
416
- {"id": "guitar", "label": "Guitar", "type": "object", "confidence": 0.9, "properties": {"category": "musical_instrument"}},
417
- {"id": "jazz_music", "label": "Jazz Music", "type": "music", "confidence": 0.95, "properties": {"genre": "jazz"}},
418
- {"id": "weekends", "label": "Weekends", "type": "routine", "confidence": 0.8, "properties": {"frequency": "weekly"}}
419
- ],
420
- "relationships": [
421
- {"source": "user", "target": "playing_guitar", "label": "enjoys", "confidence": 0.95, "type": "hobby"},
422
- {"source": "playing_guitar", "target": "guitar", "label": "uses", "confidence": 0.9, "type": "activity"},
423
- {"source": "user", "target": "jazz_music", "label": "enjoys", "confidence": 0.9, "type": "preference"},
424
- {"source": "playing_guitar", "target": "weekends", "label": "happens_during", "confidence": 0.8, "type": "temporal"}
425
- ]
426
- }
427
-
428
- ## Guidelines
429
-
430
- 1. **Always include "user" entity** for personal statements (first-person: "I", "my", "me")
431
- 2. **Extract implicit information**: "i'm a doctor" implies medical skill
432
- 3. **Handle negations properly**: "don't like" = dislikes relationship
433
- 4. **Capture intensity**: "love" vs "like" vs "enjoy" = different confidence/intensity
434
- 5. **Include relevant properties**: cuisine type for food, location type for places
435
- 6. **Create bidirectional relationships when applicable**: if A works_at B, B employs A
436
- 7. **Minimum confidence threshold**: 0.5 for entities, 0.5 for relationships
437
- 8. **Be comprehensive**: Extract ALL meaningful entities, even from short texts
438
- 9. **Handle multilingual content**: Vietnamese, English, etc.
439
- 10. **Infer entity types from context**: "spaghetti" = food, "Python" = skill/language based on context
440
- ${contextSection}
441
- ## TEXT TO ANALYZE:
442
- ${content}
443
-
159
+ return `
160
+ You are a knowledge graph extraction system for a Personal Data Wallet application. Your task is to extract meaningful entities and relationships from personal memories, notes, and user statements.
161
+
162
+ ## CRITICAL RULE: User Entity
163
+ ALWAYS include a "user" entity to represent the person who wrote this memory:
164
+ {
165
+ "id": "user",
166
+ "label": "User",
167
+ "type": "person",
168
+ "confidence": 1.0
169
+ }
170
+ This "user" entity should be the source or target of relationships describing personal preferences, attributes, or experiences.
171
+
172
+ ## Entity Types (Comprehensive List)
173
+
174
+ ### People & Social
175
+ - **person**: Individual people, including the user themselves
176
+ - Examples: "user", "john_doe", "my_mother", "boss"
177
+ - Properties: name, role, relationship_to_user
178
+
179
+ ### Organizations & Groups
180
+ - **organization**: Companies, institutions, teams, communities
181
+ - Examples: "google", "harvard_university", "local_gym"
182
+ - Properties: industry, size, location
183
+
184
+ ### Locations & Places
185
+ - **location**: Geographic places, addresses, venues
186
+ - Examples: "ho_chi_minh_city", "vietnam", "my_office", "central_park"
187
+ - Properties: type (city/country/venue), coordinates
188
+
189
+ ### Food & Dining
190
+ - **food**: Foods, dishes, cuisines, beverages, ingredients
191
+ - Examples: "spaghetti", "vietnamese_cuisine", "coffee", "chocolate"
192
+ - Properties: cuisine_type, meal_type, dietary_info
193
+ - **restaurant**: Eating establishments
194
+ - Examples: "starbucks", "local_pho_shop"
195
+ - Properties: cuisine, price_range
196
+
197
+ ### Preferences & Interests
198
+ - **preference**: General likes, dislikes, favorites
199
+ - Examples: "blue_color", "morning_routine", "minimalist_style"
200
+ - Properties: sentiment (positive/negative/neutral), intensity (1-10)
201
+ - **hobby**: Recreational activities, pastimes
202
+ - Examples: "playing_guitar", "photography", "hiking", "gaming"
203
+ - Properties: frequency, skill_level
204
+ - **interest**: Topics of curiosity or passion
205
+ - Examples: "artificial_intelligence", "history", "cooking"
206
+ - Properties: depth (casual/moderate/deep)
207
+
208
+ ### Skills & Abilities
209
+ - **skill**: Technical or soft skills, expertise areas
210
+ - Examples: "python_programming", "public_speaking", "cooking"
211
+ - Properties: proficiency (beginner/intermediate/expert)
212
+ - **language**: Languages known or being learned
213
+ - Examples: "english", "vietnamese", "japanese"
214
+ - Properties: proficiency, native (true/false)
215
+
216
+ ### Objects & Possessions
217
+ - **object**: Physical items, products, tools
218
+ - Examples: "macbook_pro", "my_car", "guitar"
219
+ - Properties: brand, model, acquisition_date
220
+ - **digital_product**: Software, apps, digital services
221
+ - Examples: "spotify", "notion", "chatgpt"
222
+ - Properties: category, usage_frequency
223
+
224
+ ### Time & Events
225
+ - **event**: Occasions, milestones, meetings
226
+ - Examples: "birthday_2024", "job_interview", "vacation_trip"
227
+ - Properties: date, duration, importance
228
+ - **routine**: Regular activities or habits
229
+ - Examples: "morning_workout", "weekly_meeting", "daily_meditation"
230
+ - Properties: frequency, time_of_day
231
+
232
+ ### Abstract & Conceptual
233
+ - **concept**: Ideas, topics, abstract things
234
+ - Examples: "work_life_balance", "productivity", "happiness"
235
+ - **goal**: Objectives, aspirations, plans
236
+ - Examples: "learn_japanese", "run_marathon", "save_money"
237
+ - Properties: deadline, priority, status
238
+ - **emotion**: Feelings, moods, emotional states
239
+ - Examples: "happiness", "stress", "excitement"
240
+ - Properties: intensity, trigger
241
+
242
+ ### Health & Wellness
243
+ - **health_condition**: Medical conditions, allergies
244
+ - Examples: "lactose_intolerance", "migraine", "allergy_to_peanuts"
245
+ - **medication**: Medicines, supplements
246
+ - Examples: "vitamin_d", "aspirin"
247
+ - **exercise**: Physical activities for health
248
+ - Examples: "running", "yoga", "weight_training"
249
+
250
+ ### Media & Entertainment
251
+ - **music**: Songs, artists, genres, albums
252
+ - Examples: "jazz_music", "beatles", "classical_piano"
253
+ - **movie**: Films, TV shows, documentaries
254
+ - Examples: "inception", "game_of_thrones"
255
+ - **book**: Books, authors, genres
256
+ - Examples: "atomic_habits", "fiction_genre"
257
+ - **game**: Video games, board games
258
+ - Examples: "chess", "minecraft"
259
+
260
+ ## Relationship Types (Comprehensive List)
261
+
262
+ ### Preference Relationships (source: usually "user")
263
+ - **loves**: Strong positive preference (intensity 9-10)
264
+ - **likes**: Moderate positive preference (intensity 6-8)
265
+ - **enjoys**: Positive experience with something
266
+ - **prefers**: Comparative preference
267
+ - **favorite**: Top choice in a category
268
+ - **interested_in**: Curiosity or engagement
269
+ - **dislikes**: Moderate negative preference
270
+ - **hates**: Strong negative preference (intensity 9-10)
271
+ - **avoids**: Intentionally stays away from
272
+ - **allergic_to**: Medical/physical aversion
273
+
274
+ ### Affiliation Relationships
275
+ - **works_at**: Employment relationship
276
+ - **studies_at**: Educational institution
277
+ - **member_of**: Group membership
278
+ - **belongs_to**: General affiliation
279
+ - **founded**: Created an organization
280
+ - **leads**: Leadership role
281
+
282
+ ### Location Relationships
283
+ - **lives_in**: Current residence
284
+ - **from**: Origin/hometown
285
+ - **located_in**: Physical location
286
+ - **visited**: Past travel
287
+ - **wants_to_visit**: Travel aspiration
288
+
289
+ ### Social Relationships
290
+ - **knows**: Acquaintance
291
+ - **friends_with**: Friendship
292
+ - **family_of**: Family relationship (specify: parent, sibling, child, spouse)
293
+ - **works_with**: Professional relationship
294
+ - **mentored_by**: Learning relationship
295
+
296
+ ### Skill & Knowledge Relationships
297
+ - **has_skill**: Possesses ability
298
+ - **expert_in**: High proficiency
299
+ - **learning**: Currently acquiring
300
+ - **wants_to_learn**: Aspiration to learn
301
+ - **teaches**: Instructing others
302
+ - **certified_in**: Formal qualification
303
+
304
+ ### Possession & Usage
305
+ - **owns**: Ownership
306
+ - **uses**: Regular usage
307
+ - **wants**: Desire to acquire
308
+ - **recommends**: Positive endorsement
309
+
310
+ ### Temporal Relationships
311
+ - **started_on**: Beginning date
312
+ - **ended_on**: Ending date
313
+ - **scheduled_for**: Future event
314
+ - **happens_during**: Temporal context
315
+
316
+ ### Causal & Descriptive
317
+ - **causes**: Causal relationship
318
+ - **related_to**: General association
319
+ - **part_of**: Component relationship
320
+ - **similar_to**: Similarity
321
+ - **opposite_of**: Contrast
322
+
323
+ ## Output Format
324
+
325
+ Return ONLY valid JSON with this structure:
326
+ {
327
+ "entities": [
328
+ {
329
+ "id": "snake_case_identifier",
330
+ "label": "Human Readable Name",
331
+ "type": "entity_type_from_list_above",
332
+ "confidence": 0.0-1.0,
333
+ "properties": { "optional": "attributes" }
334
+ }
335
+ ],
336
+ "relationships": [
337
+ {
338
+ "source": "source_entity_id",
339
+ "target": "target_entity_id",
340
+ "label": "relationship_type_from_list_above",
341
+ "confidence": 0.0-1.0,
342
+ "type": "optional_category"
343
+ }
344
+ ]
345
+ }
346
+
347
+ ## Examples
348
+
349
+ ### Example 1: Food Preference
350
+ Input: "i love spaghetti"
351
+ Output:
352
+ {
353
+ "entities": [
354
+ {"id": "user", "label": "User", "type": "person", "confidence": 1.0},
355
+ {"id": "spaghetti", "label": "Spaghetti", "type": "food", "confidence": 0.95, "properties": {"cuisine": "italian", "meal_type": "main_course"}}
356
+ ],
357
+ "relationships": [
358
+ {"source": "user", "target": "spaghetti", "label": "loves", "confidence": 0.95, "type": "preference"}
359
+ ]
360
+ }
361
+
362
+ ### Example 2: Multiple Preferences
363
+ Input: "i like hamburgers but hate vegetables"
364
+ Output:
365
+ {
366
+ "entities": [
367
+ {"id": "user", "label": "User", "type": "person", "confidence": 1.0},
368
+ {"id": "hamburgers", "label": "Hamburgers", "type": "food", "confidence": 0.95},
369
+ {"id": "vegetables", "label": "Vegetables", "type": "food", "confidence": 0.95}
370
+ ],
371
+ "relationships": [
372
+ {"source": "user", "target": "hamburgers", "label": "likes", "confidence": 0.9, "type": "preference"},
373
+ {"source": "user", "target": "vegetables", "label": "dislikes", "confidence": 0.9, "type": "preference"}
374
+ ]
375
+ }
376
+
377
+ ### Example 3: Work Information
378
+ Input: "i work at Google as a software engineer in Mountain View"
379
+ Output:
380
+ {
381
+ "entities": [
382
+ {"id": "user", "label": "User", "type": "person", "confidence": 1.0, "properties": {"role": "software_engineer"}},
383
+ {"id": "google", "label": "Google", "type": "organization", "confidence": 0.98, "properties": {"industry": "technology"}},
384
+ {"id": "software_engineer", "label": "Software Engineer", "type": "skill", "confidence": 0.9},
385
+ {"id": "mountain_view", "label": "Mountain View", "type": "location", "confidence": 0.95, "properties": {"type": "city"}}
386
+ ],
387
+ "relationships": [
388
+ {"source": "user", "target": "google", "label": "works_at", "confidence": 0.98, "type": "affiliation"},
389
+ {"source": "user", "target": "software_engineer", "label": "has_skill", "confidence": 0.9, "type": "skill"},
390
+ {"source": "google", "target": "mountain_view", "label": "located_in", "confidence": 0.85, "type": "location"}
391
+ ]
392
+ }
393
+
394
+ ### Example 4: Personal Life
395
+ Input: "my name is Aaron and I live in Ho Chi Minh City with my wife"
396
+ Output:
397
+ {
398
+ "entities": [
399
+ {"id": "user", "label": "Aaron", "type": "person", "confidence": 1.0, "properties": {"name": "Aaron"}},
400
+ {"id": "ho_chi_minh_city", "label": "Ho Chi Minh City", "type": "location", "confidence": 0.98, "properties": {"type": "city", "country": "Vietnam"}},
401
+ {"id": "wife", "label": "Wife", "type": "person", "confidence": 0.9, "properties": {"relationship": "spouse"}}
402
+ ],
403
+ "relationships": [
404
+ {"source": "user", "target": "ho_chi_minh_city", "label": "lives_in", "confidence": 0.98, "type": "location"},
405
+ {"source": "user", "target": "wife", "label": "family_of", "confidence": 0.95, "type": "social", "properties": {"relationship_type": "spouse"}}
406
+ ]
407
+ }
408
+
409
+ ### Example 5: Hobbies and Interests
410
+ Input: "i enjoy playing guitar and listening to jazz music on weekends"
411
+ Output:
412
+ {
413
+ "entities": [
414
+ {"id": "user", "label": "User", "type": "person", "confidence": 1.0},
415
+ {"id": "playing_guitar", "label": "Playing Guitar", "type": "hobby", "confidence": 0.95},
416
+ {"id": "guitar", "label": "Guitar", "type": "object", "confidence": 0.9, "properties": {"category": "musical_instrument"}},
417
+ {"id": "jazz_music", "label": "Jazz Music", "type": "music", "confidence": 0.95, "properties": {"genre": "jazz"}},
418
+ {"id": "weekends", "label": "Weekends", "type": "routine", "confidence": 0.8, "properties": {"frequency": "weekly"}}
419
+ ],
420
+ "relationships": [
421
+ {"source": "user", "target": "playing_guitar", "label": "enjoys", "confidence": 0.95, "type": "hobby"},
422
+ {"source": "playing_guitar", "target": "guitar", "label": "uses", "confidence": 0.9, "type": "activity"},
423
+ {"source": "user", "target": "jazz_music", "label": "enjoys", "confidence": 0.9, "type": "preference"},
424
+ {"source": "playing_guitar", "target": "weekends", "label": "happens_during", "confidence": 0.8, "type": "temporal"}
425
+ ]
426
+ }
427
+
428
+ ## Guidelines
429
+
430
+ 1. **Always include "user" entity** for personal statements (first-person: "I", "my", "me")
431
+ 2. **Extract implicit information**: "i'm a doctor" implies medical skill
432
+ 3. **Handle negations properly**: "don't like" = dislikes relationship
433
+ 4. **Capture intensity**: "love" vs "like" vs "enjoy" = different confidence/intensity
434
+ 5. **Include relevant properties**: cuisine type for food, location type for places
435
+ 6. **Create bidirectional relationships when applicable**: if A works_at B, B employs A
436
+ 7. **Minimum confidence threshold**: 0.5 for entities, 0.5 for relationships
437
+ 8. **Be comprehensive**: Extract ALL meaningful entities, even from short texts
438
+ 9. **Handle multilingual content**: Vietnamese, English, etc.
439
+ 10. **Infer entity types from context**: "spaghetti" = food, "Python" = skill/language based on context
440
+ ${contextSection}
441
+ ## TEXT TO ANALYZE:
442
+ ${content}
443
+
444
444
  ## JSON OUTPUT:`;
445
445
  }
446
446
  parseExtractionResponse(response) {
@@ -534,21 +534,21 @@ ${content}
534
534
  */
535
535
  async extractRichMetadata(content, categoryHint) {
536
536
  try {
537
- const prompt = `
538
- Analyze the following text and extract rich metadata in JSON format:
539
- - "importance": relevance/importance score from 1-10 (1=trivial, 10=critical)
540
- - "topic": concise topic/title (max 100 chars)
541
- - "summary": brief summary (max 200 chars)
542
- - "category": best-fit category (personal, work, education, health, finance, travel, family, hobbies, goals, ideas)
543
-
544
- Consider:
545
- - Importance: How valuable is this information for future recall?
546
- - Topic: What's the main subject or theme?
547
- - Summary: Key points in 1-2 sentences
548
- ${categoryHint ? `- Prefer category: ${categoryHint}` : ''}
549
-
550
- TEXT: ${content}
551
-
537
+ const prompt = `
538
+ Analyze the following text and extract rich metadata in JSON format:
539
+ - "importance": relevance/importance score from 1-10 (1=trivial, 10=critical)
540
+ - "topic": concise topic/title (max 100 chars)
541
+ - "summary": brief summary (max 200 chars)
542
+ - "category": best-fit category (personal, work, education, health, finance, travel, family, hobbies, goals, ideas)
543
+
544
+ Consider:
545
+ - Importance: How valuable is this information for future recall?
546
+ - Topic: What's the main subject or theme?
547
+ - Summary: Key points in 1-2 sentences
548
+ ${categoryHint ? `- Prefer category: ${categoryHint}` : ''}
549
+
550
+ TEXT: ${content}
551
+
552
552
  JSON:`;
553
553
  const text = await this.callOpenRouter(prompt);
554
554
  return this.parseRichMetadataResponse(text, content, categoryHint);
@@ -178,6 +178,7 @@ export declare class StorageService {
178
178
  embedding: number[];
179
179
  metadata: Record<string, any>;
180
180
  encryptedContent?: Uint8Array;
181
+ encryptedEmbedding?: Uint8Array;
181
182
  encryptionType?: string;
182
183
  identity?: string;
183
184
  }, options: BlobUploadOptions): Promise<WalrusUploadResult>;