@personize/sdk 0.6.1 → 0.6.2

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/README.md CHANGED
@@ -134,7 +134,7 @@ const byok = await client.ai.prompt({
134
134
  model: 'anthropic/claude-sonnet-4-20250514',
135
135
  provider: 'openrouter',
136
136
  });
137
- // BYOK billing: time-based (10 credits base + 10/extra minute) instead of per-token
137
+ // BYOK billing: flat 5 credits/call no per-token charge, you pay your provider directly
138
138
  // Without BYOK, model/provider are rejected — use tier to control quality level
139
139
 
140
140
  // Multi-step instructions with evaluation
@@ -216,6 +216,32 @@ const fast = await client.memory.smartRecall({
216
216
  // min_results: 10 (default in fast_mode — always returns top N even below score threshold)
217
217
  });
218
218
 
219
+ // Custom keys — bring your own identifier for any entity type
220
+ // Use customKeyName/customKeyValue when email or websiteUrl don't apply.
221
+ // The recordId is generated deterministically from orgId + type + key — same key always resolves to the same record.
222
+ await client.memory.memorize({
223
+ content: 'Student enrolled in Advanced AI course. GPA 3.8, Dean\'s List.',
224
+ type: 'Student',
225
+ customKeyName: 'studentNumber',
226
+ customKeyValue: 'S-2024-1234',
227
+ enhanced: true,
228
+ });
229
+
230
+ // More examples: LinkedIn profiles, web pages, code files, products...
231
+ await client.memory.memorize({ content: '...', type: 'Person', customKeyName: 'linkedinUrl', customKeyValue: 'https://linkedin.com/in/johndoe' });
232
+ await client.memory.memorize({ content: '...', type: 'Webpage', customKeyName: 'pageUrl', customKeyValue: 'https://docs.example.com/api/auth' });
233
+ await client.memory.memorize({ content: '...', type: 'File', customKeyName: 'filePath', customKeyValue: 'src/auth/oauth.ts' });
234
+ await client.memory.memorize({ content: '...', type: 'Product', customKeyName: 'sku', customKeyValue: 'PRD-X100-BLK' });
235
+
236
+ // Recall by the same custom key — no need to know the recordId
237
+ const student = await client.memory.smartRecall({
238
+ query: 'What courses is this student enrolled in?',
239
+ type: 'Student',
240
+ customKeyName: 'studentNumber',
241
+ customKeyValue: 'S-2024-1234',
242
+ fast_mode: true,
243
+ });
244
+
219
245
  // Direct recall — DynamoDB lookup: properties + freeform memories (no AI, type required)
220
246
  const direct = await client.memory.recall({
221
247
  query: 'What do we know about Acme?',
@@ -225,7 +251,15 @@ const direct = await client.memory.recall({
225
251
  // direct.data.memories — structured properties from Snapshot
226
252
  // direct.data.freeformMemories — AI-extracted memories from Freeform table
227
253
 
228
- // Search/filter records by property conditions
254
+ // Direct recall by custom key
255
+ const student = await client.memory.recall({
256
+ query: 'Academic record',
257
+ type: 'Student',
258
+ customKeyName: 'studentNumber',
259
+ customKeyValue: 'S-2024-1234',
260
+ });
261
+
262
+ // Search/filter records by property conditions — works with any type value
229
263
  const found = await client.memory.search({
230
264
  groups: [{
231
265
  conditions: [{ property: 'company-name', operator: 'equals', value: 'Acme Corp' }],
@@ -234,6 +268,23 @@ const found = await client.memory.search({
234
268
  pageSize: 50,
235
269
  });
236
270
 
271
+ // Search across a custom entity type
272
+ const deansList = await client.memory.search({
273
+ type: 'Student',
274
+ returnRecords: true,
275
+ groups: [{
276
+ conditions: [{ property: 'gpa', operator: 'GTE', value: 3.5 }],
277
+ }],
278
+ });
279
+
280
+ // Access property values: records[recordId][propertyName].value (plain string)
281
+ for (const [recordId, props] of Object.entries(found.data?.records ?? {})) {
282
+ const email = props['email']?.value; // plain string — whatever was stored
283
+ const company = props['company-name']?.value;
284
+ console.log(`${recordId}: ${email} at ${company}`);
285
+ }
286
+ // Note: 'email' and 'company-name' must match the property names in your collection definition
287
+
237
288
  // Batch sync — unified call with per-property extractMemories control
238
289
  // IMPORTANT: Set extractMemories: true on rich text fields (notes, transcripts, descriptions)
239
290
  // to enable AI extraction and semantic search. Without it, only structured storage occurs.
@@ -241,6 +292,9 @@ await client.memory.memorizeBatch({
241
292
  source: 'Hubspot',
242
293
  mapping: {
243
294
  entityType: 'contact',
295
+ // email: 'email' means "use the 'email' field from each row as the contact identifier"
296
+ // The value must match the key name in your rows array (e.g., row.email)
297
+ // Use websiteUrl instead for Company records, or recordId for direct ID matching
244
298
  email: 'email',
245
299
  properties: {
246
300
  email: { sourceField: 'email', collectionId: 'col_std', collectionName: 'Standard', extractMemories: false },
@@ -253,6 +307,25 @@ await client.memory.memorizeBatch({
253
307
  ],
254
308
  });
255
309
 
310
+ // Batch sync with custom keys — for non-Contact/Company entity types
311
+ await client.memory.memorizeBatch({
312
+ source: 'University DB',
313
+ mapping: {
314
+ entityType: 'Student',
315
+ customKeyName: 'studentNumber', // the identifier name
316
+ customKey: 'student_id', // source field in rows holding the value
317
+ properties: {
318
+ full_name: { sourceField: 'name', collectionId: 'col_std', collectionName: 'Standard', extractMemories: false },
319
+ gpa: { sourceField: 'gpa', collectionId: 'col_std', collectionName: 'Standard', extractMemories: false },
320
+ notes: { sourceField: 'notes', collectionId: 'col_gen', collectionName: 'Generated', extractMemories: true },
321
+ },
322
+ },
323
+ rows: [
324
+ { student_id: 'S-2024-1234', name: 'Alice Chen', gpa: '3.8', notes: 'Dean\'s List, AI research focus' },
325
+ { student_id: 'S-2024-5678', name: 'Bob Park', gpa: '3.5', notes: 'Full-stack internship at Stripe' },
326
+ ],
327
+ });
328
+
256
329
  // Smart memory digest — compiled context for an entity
257
330
  const digest = await client.memory.smartDigest({
258
331
  email: 'john@acme.com',
@@ -325,27 +398,29 @@ console.log(evaluation.data.summary.propertiesOptimized);
325
398
 
326
399
  | Tier | Input Credits/1K tokens | Output Credits/1K tokens | Best For |
327
400
  | :--- | :--- | :--- | :--- |
328
- | `basic` | 0.2 | 0.4 | High-volume, simple tasks |
329
- | `pro` | 0.5 | 1.0 | Balanced quality & cost (default) |
330
- | `ultra` | 1.0 | 2.5 | Complex reasoning, highest quality |
401
+ | `basic` | 1.0 | 2.0 | High-volume, simple tasks |
402
+ | `pro` | 1.0 | 3.0 | Balanced quality & cost (default) |
403
+ | `ultra` | 1.0 | 5.0 | Complex reasoning, highest quality |
331
404
 
332
405
  ### Memorize Tiers
333
406
 
334
407
  | Tier | Credits/1K tokens | Best For |
335
408
  | :--- | :--- | :--- |
336
- | `basic` | 1.0 | Bulk imports, simple data |
337
- | `pro` | 2.5 | General use (default) |
338
- | `pro_fast` | 3.5 | Pro quality, lower latency |
339
- | `ultra` | 7.0 | Maximum extraction quality |
409
+ | `basic` | 1 | Bulk imports, simple data |
410
+ | `pro` | 3 | General use (default) |
411
+ | `pro_fast` | 5 | Pro quality, lower latency |
412
+ | `ultra` | 12 | Maximum extraction quality |
340
413
 
341
414
  ### Retrieval (Recall & Smart Guidelines)
342
415
 
343
416
  | Operation | Mode | Credits/Call |
344
417
  | :--- | :--- | :--- |
345
- | Smart Recall | `fast_mode: true` | 0.1 |
346
- | Smart Recall | `fast_mode: false` (deep) | 0.2 |
347
- | Smart Guidelines | `mode: 'fast'` | 0.1 |
348
- | Smart Guidelines | `mode: 'deep'` | 0.5 |
418
+ | Smart Recall | `fast_mode: true` | 1 |
419
+ | Smart Recall | `fast_mode: false` (deep) | 1 |
420
+ | Smart Guidelines | `mode: 'fast'` | 1 |
421
+ | Smart Guidelines | `mode: 'deep'` | 1 |
422
+
423
+ All read operations (recall, smart recall, smart guidelines, smart context) charge a flat **1 credit per call** regardless of mode. Mode choice affects latency and depth, not cost.
349
424
 
350
425
  1 credit = $0.01.
351
426
 
@@ -353,7 +428,7 @@ console.log(evaluation.data.summary.propertiesOptimized);
353
428
 
354
429
  ### BYOK (Bring Your Own Key)
355
430
 
356
- Pro and Enterprise plans can pass their own API key. Billing switches to time-based: **10 credits base + 10 credits per additional minute**.
431
+ Pro and Enterprise plans can pass their own API key. Billing switches to a flat **5 credits per call** (no per-token charge — you pay your provider directly).
357
432
 
358
433
  When using BYOK, you **must** provide both `model` and `provider`. Without BYOK, `model` and `provider` are rejected — use `tier` to control quality level.
359
434
 
@@ -378,7 +453,7 @@ await client.ai.prompt({
378
453
  - `openrouterApiKey` without `model`/`provider` → `400 model and provider required`
379
454
  - BYOK on a plan that doesn't allow it → `403 byok_not_allowed`
380
455
 
381
- Response metadata includes `byok: true` and `creditsCharged` reflecting time-based billing.
456
+ Response metadata includes `byok: true` and `creditsCharged` reflecting the flat 5-credit charge.
382
457
 
383
458
  ## Best Practices: Query Crafting for smartRecall
384
459
 
package/dist/types.d.ts CHANGED
@@ -551,6 +551,16 @@ export interface MemorizeOptions {
551
551
  email?: string;
552
552
  /** Website URL for CRM linking. */
553
553
  website_url?: string;
554
+ /** Entity type (e.g. 'Contact', 'Company', 'Student', 'Webpage'). */
555
+ type?: string;
556
+ /**
557
+ * Custom key name — for entity types with domain-specific unique IDs.
558
+ * Examples: 'studentNumber', 'linkedinUrl', 'employeeId', 'pageUrl', 'productSku'.
559
+ * Used with customKeyValue to identify the record when email/websiteUrl don't apply.
560
+ */
561
+ customKeyName?: string;
562
+ /** Custom key value — the unique identifier value (e.g. 'S12345', 'https://linkedin.com/in/johndoe'). */
563
+ customKeyValue?: string;
554
564
  /** Enable enhanced dual extraction (structured + free-form). */
555
565
  enhanced?: boolean;
556
566
  /** Tags for property selection. */
@@ -587,6 +597,10 @@ export interface SmartRecallOptions {
587
597
  websiteUrl?: string;
588
598
  /** Entity type filter (e.g. 'Contact', 'Company'). */
589
599
  type?: string;
600
+ /** Custom key name — for entity types with domain-specific unique IDs. */
601
+ customKeyName?: string;
602
+ /** Custom key value — the unique identifier value. */
603
+ customKeyValue?: string;
590
604
  /** Scope results to specific collections by ID. */
591
605
  collectionIds?: string[];
592
606
  /** Scope results to specific collections by name (resolved server-side, case-insensitive). */
@@ -635,6 +649,10 @@ export interface RecallOptions {
635
649
  website_url?: string;
636
650
  /** Website URL (camelCase alias). */
637
651
  websiteUrl?: string;
652
+ /** Custom key name — for entity types with domain-specific unique IDs. */
653
+ customKeyName?: string;
654
+ /** Custom key value — the unique identifier value. */
655
+ customKeyValue?: string;
638
656
  /** Additional filters. */
639
657
  filters?: Record<string, unknown>;
640
658
  }
@@ -649,12 +667,19 @@ export interface BatchMemorizePropertyMapping {
649
667
  extractMemories?: boolean;
650
668
  }
651
669
  export interface BatchMemorizeMapping {
652
- /** Entity type (e.g. 'contact', 'company') */
670
+ /** Entity type (e.g. 'contact', 'company', 'Student', 'Webpage') */
653
671
  entityType: string;
654
672
  /** Source field name that contains the email (e.g. 'email') */
655
673
  email?: string;
656
674
  /** Source field name that contains the website URL (e.g. 'company_website_url') */
657
675
  website?: string;
676
+ /**
677
+ * Custom key name — the identifier name for custom entity types (e.g. 'studentNumber', 'linkedinUrl').
678
+ * Use with `customKey` to specify which source field holds the identifier value.
679
+ */
680
+ customKeyName?: string;
681
+ /** Source field name that contains the custom key value (e.g. 'student_id', 'linkedin_url') */
682
+ customKey?: string;
658
683
  /** Run name for tracking (e.g. 'hubspot Sync (contact) - <uuid>') */
659
684
  runName?: string;
660
685
  /** Property mappings: target property name → mapping config */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@personize/sdk",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "Official Personize SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",