@cmdoss/memwal-sdk 0.6.2 → 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.
- package/ARCHITECTURE.md +547 -547
- package/BENCHMARKS.md +238 -238
- package/README.md +310 -181
- package/dist/ai-sdk/tools.d.ts +2 -2
- package/dist/ai-sdk/tools.js +2 -2
- package/dist/client/ClientMemoryManager.js +2 -2
- package/dist/client/ClientMemoryManager.js.map +1 -1
- package/dist/client/PersonalDataWallet.d.ts.map +1 -1
- package/dist/client/SimplePDWClient.d.ts +29 -1
- package/dist/client/SimplePDWClient.d.ts.map +1 -1
- package/dist/client/SimplePDWClient.js +45 -13
- package/dist/client/SimplePDWClient.js.map +1 -1
- package/dist/client/namespaces/EmbeddingsNamespace.d.ts +1 -1
- package/dist/client/namespaces/EmbeddingsNamespace.js +1 -1
- package/dist/client/namespaces/MemoryNamespace.d.ts +31 -0
- package/dist/client/namespaces/MemoryNamespace.d.ts.map +1 -1
- package/dist/client/namespaces/MemoryNamespace.js +272 -39
- package/dist/client/namespaces/MemoryNamespace.js.map +1 -1
- package/dist/client/namespaces/consolidated/AINamespace.d.ts +2 -2
- package/dist/client/namespaces/consolidated/AINamespace.js +2 -2
- package/dist/client/namespaces/consolidated/BlockchainNamespace.d.ts +12 -2
- package/dist/client/namespaces/consolidated/BlockchainNamespace.d.ts.map +1 -1
- package/dist/client/namespaces/consolidated/BlockchainNamespace.js +62 -4
- package/dist/client/namespaces/consolidated/BlockchainNamespace.js.map +1 -1
- package/dist/client/namespaces/consolidated/StorageNamespace.d.ts +67 -2
- package/dist/client/namespaces/consolidated/StorageNamespace.d.ts.map +1 -1
- package/dist/client/namespaces/consolidated/StorageNamespace.js +549 -16
- package/dist/client/namespaces/consolidated/StorageNamespace.js.map +1 -1
- package/dist/config/ConfigurationHelper.js +61 -61
- package/dist/config/defaults.js +2 -2
- package/dist/config/defaults.js.map +1 -1
- package/dist/graph/GraphService.js +21 -21
- package/dist/graph/GraphService.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/seal/EncryptionService.d.ts +9 -5
- package/dist/infrastructure/seal/EncryptionService.d.ts.map +1 -1
- package/dist/infrastructure/seal/EncryptionService.js +37 -15
- package/dist/infrastructure/seal/EncryptionService.js.map +1 -1
- package/dist/infrastructure/seal/SealService.d.ts +13 -5
- package/dist/infrastructure/seal/SealService.d.ts.map +1 -1
- package/dist/infrastructure/seal/SealService.js +36 -34
- package/dist/infrastructure/seal/SealService.js.map +1 -1
- package/dist/langchain/createPDWRAG.js +30 -30
- package/dist/retrieval/MemoryDecryptionPipeline.d.ts.map +1 -1
- package/dist/retrieval/MemoryDecryptionPipeline.js +2 -1
- package/dist/retrieval/MemoryDecryptionPipeline.js.map +1 -1
- package/dist/retrieval/MemoryRetrievalService.d.ts +31 -0
- package/dist/retrieval/MemoryRetrievalService.d.ts.map +1 -1
- package/dist/retrieval/MemoryRetrievalService.js +44 -4
- package/dist/retrieval/MemoryRetrievalService.js.map +1 -1
- package/dist/services/CapabilityService.d.ts.map +1 -1
- package/dist/services/CapabilityService.js +30 -14
- package/dist/services/CapabilityService.js.map +1 -1
- package/dist/services/CrossContextPermissionService.d.ts.map +1 -1
- package/dist/services/CrossContextPermissionService.js +9 -7
- package/dist/services/CrossContextPermissionService.js.map +1 -1
- package/dist/services/EmbeddingService.d.ts +28 -1
- package/dist/services/EmbeddingService.d.ts.map +1 -1
- package/dist/services/EmbeddingService.js +54 -0
- package/dist/services/EmbeddingService.js.map +1 -1
- package/dist/services/EncryptionService.d.ts.map +1 -1
- package/dist/services/EncryptionService.js +6 -5
- package/dist/services/EncryptionService.js.map +1 -1
- package/dist/services/GeminiAIService.js +309 -309
- package/dist/services/IndexManager.d.ts +5 -1
- package/dist/services/IndexManager.d.ts.map +1 -1
- package/dist/services/IndexManager.js +17 -40
- package/dist/services/IndexManager.js.map +1 -1
- package/dist/services/QueryService.js +1 -1
- package/dist/services/QueryService.js.map +1 -1
- package/dist/services/StorageService.d.ts +11 -0
- package/dist/services/StorageService.d.ts.map +1 -1
- package/dist/services/StorageService.js +73 -10
- package/dist/services/StorageService.js.map +1 -1
- package/dist/services/TransactionService.d.ts +20 -0
- package/dist/services/TransactionService.d.ts.map +1 -1
- package/dist/services/TransactionService.js +43 -0
- package/dist/services/TransactionService.js.map +1 -1
- package/dist/services/ViewService.js +2 -2
- package/dist/services/ViewService.js.map +1 -1
- package/dist/services/storage/QuiltBatchManager.d.ts +101 -1
- package/dist/services/storage/QuiltBatchManager.d.ts.map +1 -1
- package/dist/services/storage/QuiltBatchManager.js +410 -20
- package/dist/services/storage/QuiltBatchManager.js.map +1 -1
- package/dist/services/storage/index.d.ts +1 -1
- package/dist/services/storage/index.d.ts.map +1 -1
- package/dist/services/storage/index.js.map +1 -1
- package/dist/utils/LRUCache.d.ts +106 -0
- package/dist/utils/LRUCache.d.ts.map +1 -0
- package/dist/utils/LRUCache.js +281 -0
- package/dist/utils/LRUCache.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/memoryIndexOnChain.d.ts +212 -0
- package/dist/utils/memoryIndexOnChain.d.ts.map +1 -0
- package/dist/utils/memoryIndexOnChain.js +312 -0
- package/dist/utils/memoryIndexOnChain.js.map +1 -0
- package/dist/utils/rebuildIndexNode.d.ts +29 -0
- package/dist/utils/rebuildIndexNode.d.ts.map +1 -1
- package/dist/utils/rebuildIndexNode.js +366 -98
- package/dist/utils/rebuildIndexNode.js.map +1 -1
- package/dist/vector/HnswWasmService.d.ts +20 -5
- package/dist/vector/HnswWasmService.d.ts.map +1 -1
- package/dist/vector/HnswWasmService.js +73 -40
- package/dist/vector/HnswWasmService.js.map +1 -1
- package/dist/vector/IHnswService.d.ts +10 -1
- package/dist/vector/IHnswService.d.ts.map +1 -1
- package/dist/vector/IHnswService.js.map +1 -1
- package/dist/vector/NodeHnswService.d.ts +16 -0
- package/dist/vector/NodeHnswService.d.ts.map +1 -1
- package/dist/vector/NodeHnswService.js +84 -5
- package/dist/vector/NodeHnswService.js.map +1 -1
- package/dist/vector/createHnswService.d.ts +1 -1
- package/dist/vector/createHnswService.js +1 -1
- package/dist/vector/index.d.ts +1 -1
- package/dist/vector/index.js +1 -1
- package/package.json +157 -157
- package/src/access/PermissionService.ts +635 -635
- package/src/aggregation/AggregationService.ts +389 -389
- package/src/ai-sdk/PDWVectorStore.ts +715 -715
- package/src/ai-sdk/index.ts +65 -65
- package/src/ai-sdk/tools.ts +460 -460
- package/src/ai-sdk/types.ts +404 -404
- package/src/batch/BatchManager.ts +597 -597
- package/src/batch/BatchingService.ts +429 -429
- package/src/batch/MemoryProcessingCache.ts +492 -492
- package/src/batch/index.ts +30 -30
- package/src/browser.ts +200 -200
- package/src/client/ClientMemoryManager.ts +987 -987
- package/src/client/PersonalDataWallet.ts +345 -345
- package/src/client/SimplePDWClient.ts +1289 -1222
- package/src/client/factory.ts +154 -154
- package/src/client/namespaces/AnalyticsNamespace.ts +377 -377
- package/src/client/namespaces/BatchNamespace.ts +356 -356
- package/src/client/namespaces/CacheNamespace.ts +123 -123
- package/src/client/namespaces/CapabilityNamespace.ts +217 -217
- package/src/client/namespaces/ClassifyNamespace.ts +169 -169
- package/src/client/namespaces/ContextNamespace.ts +297 -297
- package/src/client/namespaces/EmbeddingsNamespace.ts +99 -99
- package/src/client/namespaces/EncryptionNamespace.ts +221 -221
- package/src/client/namespaces/GraphNamespace.ts +468 -468
- package/src/client/namespaces/IndexNamespace.ts +361 -361
- package/src/client/namespaces/MemoryNamespace.ts +1422 -1135
- package/src/client/namespaces/PermissionsNamespace.ts +254 -254
- package/src/client/namespaces/PipelineNamespace.ts +220 -220
- package/src/client/namespaces/SearchNamespace.ts +1049 -1049
- package/src/client/namespaces/StorageNamespace.ts +458 -458
- package/src/client/namespaces/TxNamespace.ts +260 -260
- package/src/client/namespaces/WalletNamespace.ts +243 -243
- package/src/client/namespaces/consolidated/AINamespace.ts +449 -449
- package/src/client/namespaces/consolidated/BlockchainNamespace.ts +607 -546
- package/src/client/namespaces/consolidated/SecurityNamespace.ts +648 -648
- package/src/client/namespaces/consolidated/StorageNamespace.ts +1141 -497
- package/src/client/namespaces/consolidated/index.ts +39 -39
- package/src/client/signers/KeypairSigner.ts +108 -108
- package/src/client/signers/UnifiedSigner.ts +110 -110
- package/src/client/signers/WalletAdapterSigner.ts +159 -159
- package/src/client/signers/index.ts +26 -26
- package/src/config/ConfigurationHelper.ts +412 -412
- package/src/config/defaults.ts +51 -51
- package/src/config/index.ts +8 -8
- package/src/config/validation.ts +70 -70
- package/src/core/index.ts +14 -14
- package/src/core/interfaces/IService.ts +307 -307
- package/src/core/interfaces/index.ts +8 -8
- package/src/core/types/capability.ts +297 -297
- package/src/core/types/index.ts +870 -870
- package/src/core/types/wallet.ts +270 -270
- package/src/core/types.ts +9 -9
- package/src/core/wallet.ts +222 -222
- package/src/embedding/index.ts +19 -19
- package/src/embedding/types.ts +357 -357
- package/src/errors/index.ts +602 -602
- package/src/errors/recovery.ts +461 -461
- package/src/errors/validation.ts +567 -567
- package/src/generated/pdw/capability.ts +319 -319
- package/src/graph/GraphService.ts +887 -887
- package/src/graph/KnowledgeGraphManager.ts +728 -728
- package/src/graph/index.ts +25 -25
- package/src/index.ts +498 -474
- package/src/infrastructure/index.ts +22 -22
- package/src/infrastructure/seal/EncryptionService.ts +628 -603
- package/src/infrastructure/seal/SealService.ts +613 -615
- package/src/infrastructure/seal/index.ts +9 -9
- package/src/infrastructure/sui/BlockchainManager.ts +627 -627
- package/src/infrastructure/sui/SuiService.ts +888 -888
- package/src/infrastructure/sui/index.ts +9 -9
- package/src/infrastructure/walrus/StorageManager.ts +604 -604
- package/src/infrastructure/walrus/WalrusStorageService.ts +612 -612
- package/src/infrastructure/walrus/index.ts +9 -9
- package/src/langchain/PDWEmbeddings.ts +145 -145
- package/src/langchain/PDWVectorStore.ts +456 -456
- package/src/langchain/createPDWRAG.ts +303 -303
- package/src/langchain/index.ts +47 -47
- package/src/permissions/ConsentRepository.browser.ts +249 -249
- package/src/permissions/ConsentRepository.ts +364 -364
- package/src/pipeline/MemoryPipeline.ts +862 -862
- package/src/pipeline/PipelineManager.ts +683 -683
- package/src/pipeline/index.ts +26 -26
- package/src/retrieval/AdvancedSearchService.ts +629 -629
- package/src/retrieval/MemoryAnalyticsService.ts +711 -711
- package/src/retrieval/MemoryDecryptionPipeline.ts +825 -824
- package/src/retrieval/MemoryRetrievalService.ts +904 -830
- package/src/retrieval/index.ts +42 -42
- package/src/services/BatchService.ts +352 -352
- package/src/services/CapabilityService.ts +464 -448
- package/src/services/ClassifierService.ts +465 -465
- package/src/services/CrossContextPermissionService.ts +486 -484
- package/src/services/EmbeddingService.ts +771 -706
- package/src/services/EncryptionService.ts +712 -711
- package/src/services/GeminiAIService.ts +753 -753
- package/src/services/IndexManager.ts +977 -1004
- package/src/services/MemoryIndexService.ts +1003 -1003
- package/src/services/MemoryService.ts +369 -369
- package/src/services/QueryService.ts +890 -890
- package/src/services/StorageService.ts +1182 -1111
- package/src/services/TransactionService.ts +838 -790
- package/src/services/VectorService.ts +462 -462
- package/src/services/ViewService.ts +484 -484
- package/src/services/index.ts +25 -25
- package/src/services/storage/BlobAttributesManager.ts +333 -333
- package/src/services/storage/KnowledgeGraphManager.ts +425 -425
- package/src/services/storage/MemorySearchManager.ts +387 -387
- package/src/services/storage/QuiltBatchManager.ts +1130 -660
- package/src/services/storage/WalrusMetadataManager.ts +268 -268
- package/src/services/storage/WalrusStorageManager.ts +287 -287
- package/src/services/storage/index.ts +57 -52
- package/src/types/index.ts +13 -13
- package/src/utils/LRUCache.ts +378 -0
- package/src/utils/index.ts +76 -68
- package/src/utils/memoryIndexOnChain.ts +507 -0
- package/src/utils/rebuildIndex.ts +290 -290
- package/src/utils/rebuildIndexNode.ts +771 -424
- package/src/vector/BrowserHnswIndexService.ts +758 -758
- package/src/vector/HnswWasmService.ts +731 -679
- package/src/vector/IHnswService.ts +233 -224
- package/src/vector/NodeHnswService.ts +833 -735
- package/src/vector/VectorManager.ts +478 -478
- package/src/vector/createHnswService.ts +135 -135
- package/src/vector/index.ts +56 -56
- package/src/wallet/ContextWalletService.ts +656 -656
- package/src/wallet/MainWalletService.ts +317 -317
|
@@ -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);
|