aifastdb 2.7.2 → 2.8.1
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/aifastdb.win32-x64-msvc.node +0 -0
- package/dist/connectme-adapter.d.ts +4 -5
- package/dist/connectme-adapter.d.ts.map +1 -1
- package/dist/connectme-adapter.js +2 -3
- package/dist/connectme-adapter.js.map +1 -1
- package/dist/family-tree.d.ts +3 -4
- package/dist/family-tree.d.ts.map +1 -1
- package/dist/family-tree.js +3 -4
- package/dist/family-tree.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/social-graph-v2.d.ts +713 -1
- package/dist/social-graph-v2.d.ts.map +1 -1
- package/dist/social-graph-v2.js +698 -1
- package/dist/social-graph-v2.js.map +1 -1
- package/package.json +3 -3
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
* - Batch operations for maximum throughput
|
|
13
13
|
* - Real-time performance monitoring
|
|
14
14
|
*/
|
|
15
|
-
import type { Entity, Relation, PersonInput, PersonFilter, FriendConfig, TagInput, TagFilter, RelationFilter, ItemInput, AttributeInput, ExportGraphOptions, ExportedGraph, PathOptions, PathResult, AllPathsResult, DegreeContacts, RelationshipStrength, SuggestionConfig, ConnectionSuggestion, NetworkStats, ItemMatchResult, SharedItemResult, SharedAttributeDetail, AttributeMatchConfig, AttributeMatchResult, CompatibilityResult, PaginatedResult, ExportGraphPaginatedOptions, PaginatedExportedGraph, EntityGroupAggregation } from './social-types';
|
|
15
|
+
import type { Entity, Relation, PersonInput, PersonFilter, FriendConfig, TagInput, TagFilter, RelationFilter, ItemInput, AttributeInput, ExportGraphOptions, ExportedGraph, PathOptions, PathResult, AllPathsResult, DegreeContacts, RelationshipStrength, SuggestionConfig, ConnectionSuggestion, NetworkStats, ItemMatchResult, SharedItemResult, SharedAttributeDetail, AttributeMatchConfig, AttributeMatchResult, CompatibilityResult, PaginatedResult, ExportGraphPaginatedOptions, PaginatedExportedGraph, EntityGroupAggregation, BirthdayMatchResult, BirthdayStats } from './social-types';
|
|
16
|
+
import type { Gender, FamilyPath, FamilyTree as FamilyTreeData, FamilyStats, SpouseInfo } from './family-types';
|
|
16
17
|
/**
|
|
17
18
|
* Configuration for vector similarity search (HNSW parameters).
|
|
18
19
|
*
|
|
@@ -415,6 +416,366 @@ export declare class SocialGraphV2 {
|
|
|
415
416
|
* Remove a person's birthday
|
|
416
417
|
*/
|
|
417
418
|
removeBirthday(personId: string): boolean;
|
|
419
|
+
/**
|
|
420
|
+
* Find people with exact same birthday (same year-month-day)
|
|
421
|
+
*
|
|
422
|
+
* @param birthday - Birthday in YYYY-MM-DD format
|
|
423
|
+
* @returns Array of person entities with matching birthday
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```typescript
|
|
427
|
+
* const matches = social.findSameBirthdayExact('1990-03-15');
|
|
428
|
+
* console.log(`${matches.length} people born on 1990-03-15`);
|
|
429
|
+
* ```
|
|
430
|
+
*/
|
|
431
|
+
findSameBirthdayExact(birthday: string): Entity[];
|
|
432
|
+
/**
|
|
433
|
+
* Find people with same month-day birthday (different years allowed)
|
|
434
|
+
*
|
|
435
|
+
* @param birthday - Birthday in YYYY-MM-DD or MM-DD format
|
|
436
|
+
* @returns Array of person entities with matching month-day
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* ```typescript
|
|
440
|
+
* const matches = social.findSameBirthdayDayMonth('03-15');
|
|
441
|
+
* console.log(`${matches.length} people born on March 15th`);
|
|
442
|
+
* ```
|
|
443
|
+
*/
|
|
444
|
+
findSameBirthdayDayMonth(birthday: string): Entity[];
|
|
445
|
+
/**
|
|
446
|
+
* Find people with same exact birthday as a given person
|
|
447
|
+
*
|
|
448
|
+
* @param personId - The person ID to match against
|
|
449
|
+
* @returns Array of person entities (excludes the person themselves)
|
|
450
|
+
*
|
|
451
|
+
* @example
|
|
452
|
+
* ```typescript
|
|
453
|
+
* const twins = social.findSameBirthdayAsPersonExact(alice.id);
|
|
454
|
+
* console.log(`${twins.length} people share Alice's exact birthday`);
|
|
455
|
+
* ```
|
|
456
|
+
*/
|
|
457
|
+
findSameBirthdayAsPersonExact(personId: string): Entity[];
|
|
458
|
+
/**
|
|
459
|
+
* Find people with same month-day birthday as a given person (different years allowed)
|
|
460
|
+
*
|
|
461
|
+
* @param personId - The person ID to match against
|
|
462
|
+
* @returns Array of person entities (excludes the person themselves)
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* ```typescript
|
|
466
|
+
* const matches = social.findSameBirthdayAsPerson(alice.id);
|
|
467
|
+
* console.log(`${matches.length} people share Alice's birthday (any year)`);
|
|
468
|
+
* ```
|
|
469
|
+
*/
|
|
470
|
+
findSameBirthdayAsPerson(personId: string): Entity[];
|
|
471
|
+
/**
|
|
472
|
+
* Recommend birthday matches for a person
|
|
473
|
+
*
|
|
474
|
+
* Returns matches sorted by priority: exact match (same year-month-day) > same month-day.
|
|
475
|
+
*
|
|
476
|
+
* @param personId - The person ID to find matches for
|
|
477
|
+
* @param limit - Maximum number of results (default: 10)
|
|
478
|
+
* @returns Array of birthday match results with match type
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* ```typescript
|
|
482
|
+
* const matches = social.recommendBirthdayMatches(alice.id, 5);
|
|
483
|
+
* for (const m of matches) {
|
|
484
|
+
* console.log(`${m.person.name}: ${m.birthday} (${m.matchType})`);
|
|
485
|
+
* }
|
|
486
|
+
* ```
|
|
487
|
+
*/
|
|
488
|
+
recommendBirthdayMatches(personId: string, limit?: number): BirthdayMatchResult[];
|
|
489
|
+
/**
|
|
490
|
+
* Find people with birthdays in the next N days
|
|
491
|
+
*
|
|
492
|
+
* @param days - Number of days to look ahead
|
|
493
|
+
* @returns Array of birthday match results
|
|
494
|
+
*
|
|
495
|
+
* @example
|
|
496
|
+
* ```typescript
|
|
497
|
+
* const upcoming = social.findUpcomingBirthdays(7);
|
|
498
|
+
* console.log(`${upcoming.length} birthdays in the next week`);
|
|
499
|
+
* ```
|
|
500
|
+
*/
|
|
501
|
+
findUpcomingBirthdays(days: number): BirthdayMatchResult[];
|
|
502
|
+
/**
|
|
503
|
+
* Find people with birthdays today
|
|
504
|
+
*
|
|
505
|
+
* @returns Array of person entities whose birthday is today
|
|
506
|
+
*
|
|
507
|
+
* @example
|
|
508
|
+
* ```typescript
|
|
509
|
+
* const todayBirthdays = social.findTodayBirthdays();
|
|
510
|
+
* for (const p of todayBirthdays) {
|
|
511
|
+
* console.log(`🎂 Happy birthday, ${p.name}!`);
|
|
512
|
+
* }
|
|
513
|
+
* ```
|
|
514
|
+
*/
|
|
515
|
+
findTodayBirthdays(): Entity[];
|
|
516
|
+
/**
|
|
517
|
+
* Find people with birthdays in a specific month
|
|
518
|
+
*
|
|
519
|
+
* @param month - Month number (1-12)
|
|
520
|
+
* @returns Array of person entities born in that month
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
523
|
+
* ```typescript
|
|
524
|
+
* const marchBirthdays = social.findBirthdaysInMonth(3);
|
|
525
|
+
* console.log(`${marchBirthdays.length} people have March birthdays`);
|
|
526
|
+
* ```
|
|
527
|
+
*/
|
|
528
|
+
findBirthdaysInMonth(month: number): Entity[];
|
|
529
|
+
/**
|
|
530
|
+
* Get birthday statistics
|
|
531
|
+
*
|
|
532
|
+
* @returns Statistics object with total count, most common dates, and monthly distribution
|
|
533
|
+
*
|
|
534
|
+
* @example
|
|
535
|
+
* ```typescript
|
|
536
|
+
* const stats = social.getBirthdayStats();
|
|
537
|
+
* console.log(`Total with birthday: ${stats.totalWithBirthday}`);
|
|
538
|
+
* console.log('Most common dates:', stats.mostCommonDates);
|
|
539
|
+
* console.log('By month:', stats.byMonth);
|
|
540
|
+
* ```
|
|
541
|
+
*/
|
|
542
|
+
getBirthdayStats(): BirthdayStats;
|
|
543
|
+
/**
|
|
544
|
+
* Check if two people have the same birthday
|
|
545
|
+
*
|
|
546
|
+
* @param personA - First person ID
|
|
547
|
+
* @param personB - Second person ID
|
|
548
|
+
* @param exact - If true, compare year+month+day; if false (default), compare month+day only
|
|
549
|
+
* @returns true if birthdays match
|
|
550
|
+
*
|
|
551
|
+
* @example
|
|
552
|
+
* ```typescript
|
|
553
|
+
* const sameDay = social.isSameBirthday(alice.id, bob.id); // month+day only
|
|
554
|
+
* const sameExact = social.isSameBirthday(alice.id, bob.id, true); // exact date
|
|
555
|
+
* ```
|
|
556
|
+
*/
|
|
557
|
+
isSameBirthday(personA: string, personB: string, exact?: boolean): boolean;
|
|
558
|
+
/**
|
|
559
|
+
* Rebuild birthday index from all person entities
|
|
560
|
+
*
|
|
561
|
+
* Useful after bulk imports or data recovery. Scans all persons
|
|
562
|
+
* and re-indexes their birthday properties.
|
|
563
|
+
*
|
|
564
|
+
* @example
|
|
565
|
+
* ```typescript
|
|
566
|
+
* // After bulk import of persons with birthday properties
|
|
567
|
+
* social.rebuildBirthdayIndex();
|
|
568
|
+
* ```
|
|
569
|
+
*/
|
|
570
|
+
rebuildBirthdayIndex(): void;
|
|
571
|
+
/**
|
|
572
|
+
* Add parent-child relationship.
|
|
573
|
+
* Automatically determines father/mother based on parent's gender property.
|
|
574
|
+
* @param parentId - The parent's entity ID
|
|
575
|
+
* @param childId - The child's entity ID
|
|
576
|
+
* @returns The created relation, or null if failed
|
|
577
|
+
*/
|
|
578
|
+
addParentChild(parentId: string, childId: string): Relation | null;
|
|
579
|
+
/**
|
|
580
|
+
* Add spouse relationship (bidirectional).
|
|
581
|
+
* @param personA - First person's ID
|
|
582
|
+
* @param personB - Second person's ID
|
|
583
|
+
*/
|
|
584
|
+
addSpouse(personA: string, personB: string): Relation | null;
|
|
585
|
+
/**
|
|
586
|
+
* Add sibling relationship (bidirectional).
|
|
587
|
+
* @param personA - First person's ID
|
|
588
|
+
* @param personB - Second person's ID
|
|
589
|
+
* @param halfSibling - Whether this is a half-sibling relationship (default: false)
|
|
590
|
+
*/
|
|
591
|
+
addSibling(personA: string, personB: string, halfSibling?: boolean): Relation | null;
|
|
592
|
+
/**
|
|
593
|
+
* Remove family relationship between two people.
|
|
594
|
+
* @returns True if any relationship was removed
|
|
595
|
+
*/
|
|
596
|
+
removeFamilyRelation(personA: string, personB: string): boolean;
|
|
597
|
+
/**
|
|
598
|
+
* Add step-parent to step-child relationship (继父母-继子女).
|
|
599
|
+
*/
|
|
600
|
+
addStepParentChild(stepParentId: string, stepChildId: string): Relation | null;
|
|
601
|
+
/**
|
|
602
|
+
* Add adoptive parent to adopted child relationship (养父母-养子女).
|
|
603
|
+
*/
|
|
604
|
+
addAdoptiveParentChild(adoptiveParentId: string, adoptedChildId: string): Relation | null;
|
|
605
|
+
/**
|
|
606
|
+
* Add ex-spouse relationship (前配偶).
|
|
607
|
+
*/
|
|
608
|
+
addExSpouse(personA: string, personB: string): Relation | null;
|
|
609
|
+
/** Get parents of a person */
|
|
610
|
+
getParents(personId: string): Entity[];
|
|
611
|
+
/** Get father of a person */
|
|
612
|
+
getFather(personId: string): Entity | null;
|
|
613
|
+
/** Get mother of a person */
|
|
614
|
+
getMother(personId: string): Entity | null;
|
|
615
|
+
/** Get children of a person */
|
|
616
|
+
getChildren(personId: string): Entity[];
|
|
617
|
+
/** Get sons of a person */
|
|
618
|
+
getSons(personId: string): Entity[];
|
|
619
|
+
/** Get daughters of a person */
|
|
620
|
+
getDaughters(personId: string): Entity[];
|
|
621
|
+
/** Get current spouse of a person */
|
|
622
|
+
getSpouse(personId: string): Entity | null;
|
|
623
|
+
/** Get all spouses including ex-spouses, with isEx flag */
|
|
624
|
+
getAllSpouses(personId: string): SpouseInfo[];
|
|
625
|
+
/** Get step-parents (继父母) */
|
|
626
|
+
getStepParents(personId: string): Entity[];
|
|
627
|
+
/** Get step-father (继父) */
|
|
628
|
+
getStepFather(personId: string): Entity | null;
|
|
629
|
+
/** Get step-mother (继母) */
|
|
630
|
+
getStepMother(personId: string): Entity | null;
|
|
631
|
+
/** Get step-children (继子女) */
|
|
632
|
+
getStepChildren(personId: string): Entity[];
|
|
633
|
+
/** Get adoptive parents (养父母) */
|
|
634
|
+
getAdoptiveParents(personId: string): Entity[];
|
|
635
|
+
/** Get adoptive father (养父) */
|
|
636
|
+
getAdoptiveFather(personId: string): Entity | null;
|
|
637
|
+
/** Get adoptive mother (养母) */
|
|
638
|
+
getAdoptiveMother(personId: string): Entity | null;
|
|
639
|
+
/** Get adopted children (养子女) */
|
|
640
|
+
getAdoptedChildren(personId: string): Entity[];
|
|
641
|
+
/**
|
|
642
|
+
* Get all parents with type (biological/step/adoptive).
|
|
643
|
+
* @returns Array of { person, type } objects
|
|
644
|
+
*/
|
|
645
|
+
getAllParentsWithType(personId: string): Array<{
|
|
646
|
+
person: Entity;
|
|
647
|
+
type: 'biological' | 'step' | 'adoptive';
|
|
648
|
+
}>;
|
|
649
|
+
/**
|
|
650
|
+
* Get all children with type (biological/step/adopted).
|
|
651
|
+
* @returns Array of { person, type } objects
|
|
652
|
+
*/
|
|
653
|
+
getAllChildrenWithType(personId: string): Array<{
|
|
654
|
+
person: Entity;
|
|
655
|
+
type: 'biological' | 'step' | 'adopted';
|
|
656
|
+
}>;
|
|
657
|
+
/** Get siblings */
|
|
658
|
+
getSiblings(personId: string): Entity[];
|
|
659
|
+
/** Get brothers */
|
|
660
|
+
getBrothers(personId: string): Entity[];
|
|
661
|
+
/** Get sisters */
|
|
662
|
+
getSisters(personId: string): Entity[];
|
|
663
|
+
/**
|
|
664
|
+
* Get all ancestors (traversing upward).
|
|
665
|
+
* @param maxGenerations - Maximum generations to traverse (default: 10)
|
|
666
|
+
*/
|
|
667
|
+
getAncestors(personId: string, maxGenerations?: number): Entity[];
|
|
668
|
+
/**
|
|
669
|
+
* Get all descendants (traversing downward).
|
|
670
|
+
* @param maxGenerations - Maximum generations to traverse (default: 10)
|
|
671
|
+
*/
|
|
672
|
+
getDescendants(personId: string, maxGenerations?: number): Entity[];
|
|
673
|
+
/** Get grandparents */
|
|
674
|
+
getGrandparents(personId: string): Entity[];
|
|
675
|
+
/** Get paternal grandfather (爷爷) */
|
|
676
|
+
getPaternalGrandfather(personId: string): Entity | null;
|
|
677
|
+
/** Get paternal grandmother (奶奶) */
|
|
678
|
+
getPaternalGrandmother(personId: string): Entity | null;
|
|
679
|
+
/** Get maternal grandfather (外公/姥爷) */
|
|
680
|
+
getMaternalGrandfather(personId: string): Entity | null;
|
|
681
|
+
/** Get maternal grandmother (外婆/姥姥) */
|
|
682
|
+
getMaternalGrandmother(personId: string): Entity | null;
|
|
683
|
+
/** Get grandchildren */
|
|
684
|
+
getGrandchildren(personId: string): Entity[];
|
|
685
|
+
/** Get uncles and aunts (叔伯姑姨舅) */
|
|
686
|
+
getUnclesAunts(personId: string): Entity[];
|
|
687
|
+
/** Get paternal uncles (叔叔/伯伯) */
|
|
688
|
+
getPaternalUncles(personId: string): Entity[];
|
|
689
|
+
/** Get paternal aunts (姑姑) */
|
|
690
|
+
getPaternalAunts(personId: string): Entity[];
|
|
691
|
+
/** Get maternal uncles (舅舅) */
|
|
692
|
+
getMaternalUncles(personId: string): Entity[];
|
|
693
|
+
/** Get maternal aunts (姨妈) */
|
|
694
|
+
getMaternalAunts(personId: string): Entity[];
|
|
695
|
+
/** Get nephews and nieces (侄子/侄女/外甥/外甥女) */
|
|
696
|
+
getNephewsNieces(personId: string): Entity[];
|
|
697
|
+
/** Get cousins (堂/表兄弟姐妹) */
|
|
698
|
+
getCousins(personId: string): Entity[];
|
|
699
|
+
/** Get paternal cousins (堂兄弟姐妹) */
|
|
700
|
+
getPaternalCousins(personId: string): Entity[];
|
|
701
|
+
/** Get maternal cousins (表兄弟姐妹) */
|
|
702
|
+
getMaternalCousins(personId: string): Entity[];
|
|
703
|
+
/** Get father-in-law (公公/岳父) */
|
|
704
|
+
getFatherInLaw(personId: string): Entity | null;
|
|
705
|
+
/** Get mother-in-law (婆婆/岳母) */
|
|
706
|
+
getMotherInLaw(personId: string): Entity | null;
|
|
707
|
+
/** Get siblings-in-law */
|
|
708
|
+
getSiblingsInLaw(personId: string): Entity[];
|
|
709
|
+
/** Get children-in-law (儿媳/女婿) */
|
|
710
|
+
getChildrenInLaw(personId: string): Entity[];
|
|
711
|
+
/**
|
|
712
|
+
* Calculate the family relationship between two people.
|
|
713
|
+
* Returns the full path including Chinese relationship title,
|
|
714
|
+
* generation difference, and blood distance.
|
|
715
|
+
* @param fromId - Starting person's ID
|
|
716
|
+
* @param toId - Ending person's ID
|
|
717
|
+
*/
|
|
718
|
+
calculateFamilyRelationship(fromId: string, toId: string): FamilyPath | null;
|
|
719
|
+
/**
|
|
720
|
+
* Get the Chinese relationship title between two people.
|
|
721
|
+
* @example
|
|
722
|
+
* ```typescript
|
|
723
|
+
* const title = social.getRelationshipTitle(child.id, father.id);
|
|
724
|
+
* // Returns: "父亲"
|
|
725
|
+
* ```
|
|
726
|
+
*/
|
|
727
|
+
getRelationshipTitle(fromId: string, toId: string): string | null;
|
|
728
|
+
/** Find the closest common ancestor of two people */
|
|
729
|
+
findCommonAncestor(personA: string, personB: string): Entity | null;
|
|
730
|
+
/**
|
|
731
|
+
* Calculate the blood distance between two people.
|
|
732
|
+
* Blood distance = number of parent-child links through common ancestor.
|
|
733
|
+
*/
|
|
734
|
+
calculateBloodDistance(personA: string, personB: string): number | null;
|
|
735
|
+
/** Check if two people are direct blood relatives (ancestor/descendant) */
|
|
736
|
+
isDirectBloodRelative(personA: string, personB: string): boolean;
|
|
737
|
+
/**
|
|
738
|
+
* Build a family tree centered on a person.
|
|
739
|
+
* @param personId - Center person's ID
|
|
740
|
+
* @param generationsUp - Generations to traverse upward (default: 3)
|
|
741
|
+
* @param generationsDown - Generations to traverse downward (default: 3)
|
|
742
|
+
*/
|
|
743
|
+
buildFamilyTree(personId: string, generationsUp?: number, generationsDown?: number): FamilyTreeData | null;
|
|
744
|
+
/**
|
|
745
|
+
* Get generation number of a person relative to a root.
|
|
746
|
+
* 0 = same as root, positive = younger, negative = older.
|
|
747
|
+
*/
|
|
748
|
+
getGeneration(personId: string, rootId: string): number | null;
|
|
749
|
+
/** Get all people in the same generation (siblings, cousins, spouse) */
|
|
750
|
+
getSameGeneration(personId: string): Entity[];
|
|
751
|
+
/**
|
|
752
|
+
* Get paternal lineage (父系血统): father → grandfather → great-grandfather → ...
|
|
753
|
+
* @param maxGenerations - Maximum generations to trace (default: 10)
|
|
754
|
+
*/
|
|
755
|
+
getPaternalLineage(personId: string, maxGenerations?: number): Entity[];
|
|
756
|
+
/**
|
|
757
|
+
* Get maternal lineage (母系血统): mother → grandmother → great-grandmother → ...
|
|
758
|
+
* @param maxGenerations - Maximum generations to trace (default: 10)
|
|
759
|
+
*/
|
|
760
|
+
getMaternalLineage(personId: string, maxGenerations?: number): Entity[];
|
|
761
|
+
/** Get same surname relatives (同姓族人) */
|
|
762
|
+
getSameSurnameRelatives(personId: string): Entity[];
|
|
763
|
+
/**
|
|
764
|
+
* Get paternal clan members (父系宗族成员).
|
|
765
|
+
* Traditional Chinese "宗族" — all connected through paternal line.
|
|
766
|
+
* @param maxGenerations - Maximum generations to include (default: 5)
|
|
767
|
+
*/
|
|
768
|
+
getPaternalClan(personId: string, maxGenerations?: number): Entity[];
|
|
769
|
+
/**
|
|
770
|
+
* Get family statistics for a tree rooted at the given person.
|
|
771
|
+
* @returns { total_members, total_generations, male_count, female_count, ... }
|
|
772
|
+
*/
|
|
773
|
+
getFamilyStats(rootId: string): FamilyStats | null;
|
|
774
|
+
/**
|
|
775
|
+
* Set the gender of a person.
|
|
776
|
+
* @param gender - 'male', 'female', or 'unknown'
|
|
777
|
+
*/
|
|
778
|
+
setPersonGender(personId: string, gender: Gender): boolean;
|
|
418
779
|
/**
|
|
419
780
|
* Delete any entity by ID (person, tag, attribute, item, etc.)
|
|
420
781
|
*
|
|
@@ -1162,6 +1523,131 @@ export declare class SocialGraphV2 {
|
|
|
1162
1523
|
* Check if an entity is in shadow (demoted) state.
|
|
1163
1524
|
*/
|
|
1164
1525
|
isShadowEntity(entityId: string): boolean;
|
|
1526
|
+
/**
|
|
1527
|
+
* Decompose text into a memory sub-graph using the rule-based decomposer.
|
|
1528
|
+
*
|
|
1529
|
+
* The decomposer splits text into atomic entities (facts, concepts, etc.)
|
|
1530
|
+
* connected by typed relations (CONTAINS, RELATES, etc.), forming a
|
|
1531
|
+
* knowledge sub-graph suitable for graph-based memory storage.
|
|
1532
|
+
*
|
|
1533
|
+
* @param text - The input text to decompose
|
|
1534
|
+
* @param context - Optional context string (e.g., "phase-7 development")
|
|
1535
|
+
* @param userId - User identifier
|
|
1536
|
+
* @returns DecompositionResult with episode root, entities, and relations
|
|
1537
|
+
*
|
|
1538
|
+
* @example
|
|
1539
|
+
* ```typescript
|
|
1540
|
+
* const result = graph.memoryTreeDecompose(
|
|
1541
|
+
* "We decided to use Store Trait to unify heterogeneous storage backends.",
|
|
1542
|
+
* "architecture-discussion",
|
|
1543
|
+
* "user-1"
|
|
1544
|
+
* );
|
|
1545
|
+
* console.log(result.episode); // Episode root entity
|
|
1546
|
+
* console.log(result.entities); // Atomic entities (facts, etc.)
|
|
1547
|
+
* console.log(result.relations); // Typed relations
|
|
1548
|
+
* ```
|
|
1549
|
+
*/
|
|
1550
|
+
memoryTreeDecompose(text: string, context?: string, userId?: string): DecompositionResult;
|
|
1551
|
+
/**
|
|
1552
|
+
* Parse an LLM-generated JSON decomposition into a DecompositionResult.
|
|
1553
|
+
*
|
|
1554
|
+
* Use this when an external LLM (e.g., GPT-4, Claude) produces the
|
|
1555
|
+
* decomposition JSON instead of the built-in rule-based decomposer.
|
|
1556
|
+
*
|
|
1557
|
+
* @param jsonStr - The LLM's JSON output string
|
|
1558
|
+
* @param userId - User identifier
|
|
1559
|
+
* @param context - Optional context string
|
|
1560
|
+
* @param sourceText - The original text that was decomposed
|
|
1561
|
+
* @returns Parsed DecompositionResult
|
|
1562
|
+
*/
|
|
1563
|
+
memoryTreeParseLlmDecomposition(jsonStr: string, userId: string, context?: string, sourceText?: string): DecompositionResult;
|
|
1564
|
+
/**
|
|
1565
|
+
* Store a decomposed memory tree sub-graph into the graph.
|
|
1566
|
+
*
|
|
1567
|
+
* Pipeline:
|
|
1568
|
+
* 1. Store episode root entity
|
|
1569
|
+
* 2. Store all atomic entities (facts, concepts, etc.)
|
|
1570
|
+
* 3. Store all typed relations (CONTAINS, CAUSES, ENABLES, etc.)
|
|
1571
|
+
* 4. Index vectors for entities that have embeddings
|
|
1572
|
+
* 5. Run conflict detection against existing memories
|
|
1573
|
+
*
|
|
1574
|
+
* @param decomposition - DecompositionResult (from memoryTreeDecompose)
|
|
1575
|
+
* @param embeddings - Array of { entityId, embedding } pairs for vector indexing
|
|
1576
|
+
* @param config - Optional MemoryTreeConfig
|
|
1577
|
+
* @returns MemoryTreeStoreResult with counts
|
|
1578
|
+
*
|
|
1579
|
+
* @example
|
|
1580
|
+
* ```typescript
|
|
1581
|
+
* const decomp = graph.memoryTreeDecompose(text, ctx, userId);
|
|
1582
|
+
* // Generate embeddings for each entity (using your embedding model)
|
|
1583
|
+
* const embeddings = decomp.entities.map(e => ({
|
|
1584
|
+
* entityId: e.id,
|
|
1585
|
+
* embedding: await embed(e.content),
|
|
1586
|
+
* }));
|
|
1587
|
+
* const result = graph.memoryTreeStore(decomp, embeddings);
|
|
1588
|
+
* console.log(result.entitiesStored, result.relationsStored);
|
|
1589
|
+
* ```
|
|
1590
|
+
*/
|
|
1591
|
+
memoryTreeStore(decomposition: DecompositionResult, embeddings: MemoryTreeEmbeddingInput[], config?: MemoryTreeConfig): MemoryTreeStoreResult;
|
|
1592
|
+
/**
|
|
1593
|
+
* Search memories using the memory tree activation engine.
|
|
1594
|
+
*
|
|
1595
|
+
* Combines vector search with N-hop graph traversal for richer recall:
|
|
1596
|
+
* 1. Vector Search: Find top-K entities most similar to the query
|
|
1597
|
+
* 2. Subgraph Expansion: Extract 2-hop subgraph for each hit
|
|
1598
|
+
* 3. Scoring: Combined score = α*vector + β*proximity + γ*weight
|
|
1599
|
+
* 4. Dedup & Sort: Merge overlapping subgraphs, sort by score
|
|
1600
|
+
*
|
|
1601
|
+
* @param queryEmbedding - Vector representation of the query
|
|
1602
|
+
* @param userId - Filter by user
|
|
1603
|
+
* @param config - Optional MemoryTreeConfig
|
|
1604
|
+
* @returns ActivationResult with scored activated memories
|
|
1605
|
+
*
|
|
1606
|
+
* @example
|
|
1607
|
+
* ```typescript
|
|
1608
|
+
* const queryEmb = await embed("What architecture decisions were made?");
|
|
1609
|
+
* const result = graph.memoryTreeSearch(queryEmb, "user-1");
|
|
1610
|
+
* for (const mem of result.memories) {
|
|
1611
|
+
* console.log(mem.content, mem.score.combined);
|
|
1612
|
+
* }
|
|
1613
|
+
* ```
|
|
1614
|
+
*/
|
|
1615
|
+
memoryTreeSearch(queryEmbedding: number[], userId: string, config?: MemoryTreeConfig): ActivationResult;
|
|
1616
|
+
/**
|
|
1617
|
+
* Run Hebbian weight strengthening for co-activated memories.
|
|
1618
|
+
*
|
|
1619
|
+
* Should be called after a query retrieves multiple memories that are
|
|
1620
|
+
* used together in the same response. This strengthens the relations
|
|
1621
|
+
* between co-activated entities, implementing "neurons that fire together
|
|
1622
|
+
* wire together".
|
|
1623
|
+
*
|
|
1624
|
+
* @param activatedIds - List of entity IDs that were co-activated
|
|
1625
|
+
* @param config - Optional MemoryTreeConfig
|
|
1626
|
+
* @returns Number of relation weights updated
|
|
1627
|
+
*/
|
|
1628
|
+
memoryTreeStrengthen(activatedIds: string[], config?: MemoryTreeConfig): number;
|
|
1629
|
+
/**
|
|
1630
|
+
* Run a memory lifecycle scan (promote hot, demote cold).
|
|
1631
|
+
*
|
|
1632
|
+
* Should be called periodically (e.g., every N conversations).
|
|
1633
|
+
* Uses DynamicNodeManager under the hood with memory-tree-aware config.
|
|
1634
|
+
*
|
|
1635
|
+
* @param config - Optional MemoryTreeConfig
|
|
1636
|
+
* @returns MemoryScanReport with promoted/demoted/summaries counts
|
|
1637
|
+
*/
|
|
1638
|
+
memoryTreeLifecycle(config?: MemoryTreeConfig): MemoryScanReport;
|
|
1639
|
+
/**
|
|
1640
|
+
* Detect and resolve conflicts between new entities and existing memories.
|
|
1641
|
+
*
|
|
1642
|
+
* This is a standalone API; conflict detection also runs automatically
|
|
1643
|
+
* inside `memoryTreeStore()`.
|
|
1644
|
+
*
|
|
1645
|
+
* @param entities - Array of DecomposedEntity objects to check
|
|
1646
|
+
* @param embeddings - Array of { entityId, embedding } pairs
|
|
1647
|
+
* @param config - Optional MemoryTreeConfig
|
|
1648
|
+
* @returns ConflictResult with detected conflicts and created relations
|
|
1649
|
+
*/
|
|
1650
|
+
memoryTreeDetectConflicts(entities: DecomposedEntity[], embeddings: MemoryTreeEmbeddingInput[], config?: MemoryTreeConfig): ConflictResult;
|
|
1165
1651
|
}
|
|
1166
1652
|
/**
|
|
1167
1653
|
* Graph mutation for batch operations
|
|
@@ -1356,6 +1842,232 @@ export interface WalCompactReport {
|
|
|
1356
1842
|
/** Per-shard compaction results */
|
|
1357
1843
|
shardResults: WalCompactShardResult[];
|
|
1358
1844
|
}
|
|
1845
|
+
/**
|
|
1846
|
+
* Configuration for the memory tree system.
|
|
1847
|
+
*/
|
|
1848
|
+
export interface MemoryTreeConfig {
|
|
1849
|
+
/** Alpha weight for vector score in activation scoring (default: 0.5) */
|
|
1850
|
+
activationAlpha?: number;
|
|
1851
|
+
/** Beta weight for graph proximity in activation scoring (default: 0.3) */
|
|
1852
|
+
activationBeta?: number;
|
|
1853
|
+
/** Gamma weight for relation weight in activation scoring (default: 0.2) */
|
|
1854
|
+
activationGamma?: number;
|
|
1855
|
+
/** Max hops for subgraph extraction during activation (default: 2) */
|
|
1856
|
+
activationMaxHops?: number;
|
|
1857
|
+
/** Max nodes per subgraph during activation (default: 50) */
|
|
1858
|
+
activationMaxNodes?: number;
|
|
1859
|
+
/** Top-K vector search results to expand (default: 10) */
|
|
1860
|
+
activationTopK?: number;
|
|
1861
|
+
/** Minimum vector similarity for conflict detection (default: 0.8) */
|
|
1862
|
+
conflictMinSimilarity?: number;
|
|
1863
|
+
/** Whether to enable automatic Hebbian weight strengthening (default: true) */
|
|
1864
|
+
hebbianEnabled?: boolean;
|
|
1865
|
+
/** Hebbian weight increment per co-activation (default: 0.05) */
|
|
1866
|
+
hebbianIncrement?: number;
|
|
1867
|
+
/** Maximum relation weight cap (default: 1.0) */
|
|
1868
|
+
hebbianMaxWeight?: number;
|
|
1869
|
+
/** DynamicNode promote threshold (hit count) (default: 5) */
|
|
1870
|
+
promoteHitThreshold?: number;
|
|
1871
|
+
/** DynamicNode demote idle timeout in seconds (default: 604800 = 7 days) */
|
|
1872
|
+
demoteIdleTimeoutSecs?: number;
|
|
1873
|
+
/** Entity types that should never be demoted */
|
|
1874
|
+
preserveEntityTypes?: string[];
|
|
1875
|
+
}
|
|
1876
|
+
/**
|
|
1877
|
+
* A decomposed entity extracted from text.
|
|
1878
|
+
*/
|
|
1879
|
+
export interface DecomposedEntity {
|
|
1880
|
+
/** Unique entity ID */
|
|
1881
|
+
id: string;
|
|
1882
|
+
/** Entity type (e.g., "episode", "fact", "concept", "decision", "actor") */
|
|
1883
|
+
entity_type: string;
|
|
1884
|
+
/** Content text */
|
|
1885
|
+
content: string;
|
|
1886
|
+
/** Optional entity name */
|
|
1887
|
+
name?: string;
|
|
1888
|
+
/** Confidence score (0.0 ~ 1.0) */
|
|
1889
|
+
confidence: number;
|
|
1890
|
+
/** Additional properties */
|
|
1891
|
+
properties: Record<string, unknown>;
|
|
1892
|
+
}
|
|
1893
|
+
/**
|
|
1894
|
+
* A decomposed relation extracted from text.
|
|
1895
|
+
*/
|
|
1896
|
+
export interface DecomposedRelation {
|
|
1897
|
+
/** Unique relation ID */
|
|
1898
|
+
id: string;
|
|
1899
|
+
/** Source entity ID */
|
|
1900
|
+
source: string;
|
|
1901
|
+
/** Target entity ID */
|
|
1902
|
+
target: string;
|
|
1903
|
+
/** Relation type (e.g., "CONTAINS", "CAUSES", "ENABLES", "RELATES") */
|
|
1904
|
+
relation_type: string;
|
|
1905
|
+
/** Relation weight (0.0 ~ 1.0) */
|
|
1906
|
+
weight: number;
|
|
1907
|
+
/** Additional metadata */
|
|
1908
|
+
metadata: Record<string, unknown>;
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* Result of text decomposition into a memory sub-graph.
|
|
1912
|
+
*/
|
|
1913
|
+
export interface DecompositionResult {
|
|
1914
|
+
/** Episode root entity */
|
|
1915
|
+
episode: DecomposedEntity;
|
|
1916
|
+
/** Atomic entities extracted from text */
|
|
1917
|
+
entities: DecomposedEntity[];
|
|
1918
|
+
/** Typed relations between entities */
|
|
1919
|
+
relations: DecomposedRelation[];
|
|
1920
|
+
/** Original source text */
|
|
1921
|
+
source_text: string;
|
|
1922
|
+
}
|
|
1923
|
+
/**
|
|
1924
|
+
* Embedding input for memory tree operations.
|
|
1925
|
+
*/
|
|
1926
|
+
export interface MemoryTreeEmbeddingInput {
|
|
1927
|
+
/** Entity ID this embedding belongs to */
|
|
1928
|
+
entityId: string;
|
|
1929
|
+
/** The embedding vector (float array) */
|
|
1930
|
+
embedding: number[];
|
|
1931
|
+
}
|
|
1932
|
+
/**
|
|
1933
|
+
* Result of storing a memory tree sub-graph.
|
|
1934
|
+
*/
|
|
1935
|
+
export interface MemoryTreeStoreResult {
|
|
1936
|
+
/** ID of the episode root entity */
|
|
1937
|
+
episode_id: string;
|
|
1938
|
+
/** Number of entities stored */
|
|
1939
|
+
entities_stored: number;
|
|
1940
|
+
/** Number of relations stored */
|
|
1941
|
+
relations_stored: number;
|
|
1942
|
+
/** Number of vectors indexed */
|
|
1943
|
+
vectors_indexed: number;
|
|
1944
|
+
/** Number of conflicts detected */
|
|
1945
|
+
conflicts_detected: number;
|
|
1946
|
+
/** Number of SUPERSEDES/CONFLICTS relations created */
|
|
1947
|
+
relations_created_by_conflict: number;
|
|
1948
|
+
}
|
|
1949
|
+
/**
|
|
1950
|
+
* Score breakdown for an activated memory.
|
|
1951
|
+
*/
|
|
1952
|
+
export interface ActivationScore {
|
|
1953
|
+
/** Vector similarity score component */
|
|
1954
|
+
vector_score: number;
|
|
1955
|
+
/** Graph proximity score component */
|
|
1956
|
+
proximity_score: number;
|
|
1957
|
+
/** Relation weight score component */
|
|
1958
|
+
weight_score: number;
|
|
1959
|
+
/** Combined weighted score */
|
|
1960
|
+
combined: number;
|
|
1961
|
+
}
|
|
1962
|
+
/**
|
|
1963
|
+
* A relation in the activated subgraph.
|
|
1964
|
+
*/
|
|
1965
|
+
export interface ActivatedRelation {
|
|
1966
|
+
/** Relation ID */
|
|
1967
|
+
relation_id: string;
|
|
1968
|
+
/** Source entity ID */
|
|
1969
|
+
source: string;
|
|
1970
|
+
/** Target entity ID */
|
|
1971
|
+
target: string;
|
|
1972
|
+
/** Relation type */
|
|
1973
|
+
relation_type: string;
|
|
1974
|
+
/** Relation weight */
|
|
1975
|
+
weight: number;
|
|
1976
|
+
}
|
|
1977
|
+
/**
|
|
1978
|
+
* An activated memory entity from the memory tree search.
|
|
1979
|
+
*/
|
|
1980
|
+
export interface ActivatedMemory {
|
|
1981
|
+
/** Entity ID */
|
|
1982
|
+
entity_id: string;
|
|
1983
|
+
/** Entity type */
|
|
1984
|
+
entity_type: string;
|
|
1985
|
+
/** Entity content */
|
|
1986
|
+
content: string;
|
|
1987
|
+
/** Activation score breakdown */
|
|
1988
|
+
score: ActivationScore;
|
|
1989
|
+
/** Hop distance from the nearest vector anchor */
|
|
1990
|
+
hop_distance: number;
|
|
1991
|
+
/** Relations connecting this entity to other activated entities */
|
|
1992
|
+
connected_relations: ActivatedRelation[];
|
|
1993
|
+
}
|
|
1994
|
+
/**
|
|
1995
|
+
* Result of a memory activation (search) query.
|
|
1996
|
+
*/
|
|
1997
|
+
export interface ActivationResult {
|
|
1998
|
+
/** Activated memories, sorted by combined score (descending) */
|
|
1999
|
+
memories: ActivatedMemory[];
|
|
2000
|
+
/** Total entities explored during activation */
|
|
2001
|
+
entities_explored: number;
|
|
2002
|
+
/** Total subgraphs extracted */
|
|
2003
|
+
subgraphs_extracted: number;
|
|
2004
|
+
/** Vector search anchor IDs (the top-K vector hits) */
|
|
2005
|
+
anchor_ids: string[];
|
|
2006
|
+
}
|
|
2007
|
+
/**
|
|
2008
|
+
* Report from a memory lifecycle scan.
|
|
2009
|
+
*/
|
|
2010
|
+
export interface MemoryScanReport {
|
|
2011
|
+
/** Number of entities promoted (strengthened) */
|
|
2012
|
+
promoted: number;
|
|
2013
|
+
/** Number of entities demoted (forgotten) */
|
|
2014
|
+
demoted: number;
|
|
2015
|
+
/** Number of summaries created for demoted entities */
|
|
2016
|
+
summaries_created: number;
|
|
2017
|
+
/** Number of Hebbian weight updates applied */
|
|
2018
|
+
hebbian_updates: number;
|
|
2019
|
+
/** Total entities scanned */
|
|
2020
|
+
entities_scanned: number;
|
|
2021
|
+
}
|
|
2022
|
+
/**
|
|
2023
|
+
* A detected memory conflict.
|
|
2024
|
+
*/
|
|
2025
|
+
export interface MemoryConflict {
|
|
2026
|
+
/** New entity ID */
|
|
2027
|
+
new_entity_id: string;
|
|
2028
|
+
/** Existing entity ID */
|
|
2029
|
+
existing_entity_id: string;
|
|
2030
|
+
/** Similarity score between the two */
|
|
2031
|
+
similarity: number;
|
|
2032
|
+
/** Conflict type: "supersedes" | "contradicts" | "supplements" */
|
|
2033
|
+
conflict_type: string;
|
|
2034
|
+
/** Relation created (if any) */
|
|
2035
|
+
relation_created?: string;
|
|
2036
|
+
}
|
|
2037
|
+
/**
|
|
2038
|
+
* Result of conflict detection.
|
|
2039
|
+
*/
|
|
2040
|
+
export interface ConflictResult {
|
|
2041
|
+
/** Detected conflicts */
|
|
2042
|
+
conflicts: MemoryConflict[];
|
|
2043
|
+
/** Number of entities checked */
|
|
2044
|
+
entities_checked: number;
|
|
2045
|
+
/** Number of relations created */
|
|
2046
|
+
relations_created: number;
|
|
2047
|
+
}
|
|
2048
|
+
/**
|
|
2049
|
+
* Memory Tree entity type constants.
|
|
2050
|
+
*/
|
|
2051
|
+
export declare const MemoryEntityTypes: {
|
|
2052
|
+
readonly EPISODE: "episode";
|
|
2053
|
+
readonly FACT: "fact";
|
|
2054
|
+
readonly CONCEPT: "concept";
|
|
2055
|
+
readonly DECISION: "decision";
|
|
2056
|
+
readonly ACTOR: "actor";
|
|
2057
|
+
readonly PREFERENCE: "preference";
|
|
2058
|
+
};
|
|
2059
|
+
/**
|
|
2060
|
+
* Memory Tree relation type constants.
|
|
2061
|
+
*/
|
|
2062
|
+
export declare const MemoryRelationTypes: {
|
|
2063
|
+
readonly CONTAINS: "CONTAINS";
|
|
2064
|
+
readonly CAUSES: "CAUSES";
|
|
2065
|
+
readonly ENABLES: "ENABLES";
|
|
2066
|
+
readonly RELATES: "RELATES";
|
|
2067
|
+
readonly SUPERSEDES: "SUPERSEDES";
|
|
2068
|
+
readonly CONFLICTS: "CONFLICTS";
|
|
2069
|
+
readonly SUPPLEMENTS: "SUPPLEMENTS";
|
|
2070
|
+
};
|
|
1359
2071
|
/**
|
|
1360
2072
|
* Create a SocialGraphV2 instance with default configuration
|
|
1361
2073
|
*/
|