@superatomai/sdk-node 0.0.24 → 0.0.26

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/dist/index.d.mts CHANGED
@@ -395,6 +395,7 @@ declare const UserSchema: z.ZodObject<{
395
395
  password: z.ZodString;
396
396
  fullname: z.ZodOptional<z.ZodString>;
397
397
  role: z.ZodOptional<z.ZodString>;
398
+ userInfo: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
398
399
  wsIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
399
400
  }, "strip", z.ZodTypeAny, {
400
401
  username: string;
@@ -402,6 +403,7 @@ declare const UserSchema: z.ZodObject<{
402
403
  email?: string | undefined;
403
404
  fullname?: string | undefined;
404
405
  role?: string | undefined;
406
+ userInfo?: Record<string, unknown> | undefined;
405
407
  wsIds?: string[] | undefined;
406
408
  }, {
407
409
  username: string;
@@ -409,6 +411,7 @@ declare const UserSchema: z.ZodObject<{
409
411
  email?: string | undefined;
410
412
  fullname?: string | undefined;
411
413
  role?: string | undefined;
414
+ userInfo?: Record<string, unknown> | undefined;
412
415
  wsIds?: string[] | undefined;
413
416
  }>;
414
417
  type User = z.infer<typeof UserSchema>;
@@ -419,6 +422,7 @@ declare const UsersDataSchema: z.ZodObject<{
419
422
  password: z.ZodString;
420
423
  fullname: z.ZodOptional<z.ZodString>;
421
424
  role: z.ZodOptional<z.ZodString>;
425
+ userInfo: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
422
426
  wsIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
423
427
  }, "strip", z.ZodTypeAny, {
424
428
  username: string;
@@ -426,6 +430,7 @@ declare const UsersDataSchema: z.ZodObject<{
426
430
  email?: string | undefined;
427
431
  fullname?: string | undefined;
428
432
  role?: string | undefined;
433
+ userInfo?: Record<string, unknown> | undefined;
429
434
  wsIds?: string[] | undefined;
430
435
  }, {
431
436
  username: string;
@@ -433,6 +438,7 @@ declare const UsersDataSchema: z.ZodObject<{
433
438
  email?: string | undefined;
434
439
  fullname?: string | undefined;
435
440
  role?: string | undefined;
441
+ userInfo?: Record<string, unknown> | undefined;
436
442
  wsIds?: string[] | undefined;
437
443
  }>, "many">;
438
444
  }, "strip", z.ZodTypeAny, {
@@ -442,6 +448,7 @@ declare const UsersDataSchema: z.ZodObject<{
442
448
  email?: string | undefined;
443
449
  fullname?: string | undefined;
444
450
  role?: string | undefined;
451
+ userInfo?: Record<string, unknown> | undefined;
445
452
  wsIds?: string[] | undefined;
446
453
  }[];
447
454
  }, {
@@ -451,6 +458,7 @@ declare const UsersDataSchema: z.ZodObject<{
451
458
  email?: string | undefined;
452
459
  fullname?: string | undefined;
453
460
  role?: string | undefined;
461
+ userInfo?: Record<string, unknown> | undefined;
454
462
  wsIds?: string[] | undefined;
455
463
  }[];
456
464
  }>;
@@ -1483,6 +1491,134 @@ declare const CONTEXT_CONFIG: {
1483
1491
  MAX_CONVERSATION_CONTEXT_BLOCKS: number;
1484
1492
  };
1485
1493
 
1494
+ /**
1495
+ * BM25L Reranker for hybrid semantic search
1496
+ *
1497
+ * BM25L is an improved variant of BM25 that provides better handling of
1498
+ * long documents and term frequency saturation. This implementation is
1499
+ * designed to rerank semantic search results from ChromaDB.
1500
+ *
1501
+ * The hybrid approach combines:
1502
+ * 1. Semantic similarity from ChromaDB embeddings (dense vectors)
1503
+ * 2. Lexical matching from BM25L (sparse, keyword-based)
1504
+ *
1505
+ * This addresses the weakness of pure semantic search which may miss
1506
+ * exact keyword matches that are important for user intent.
1507
+ */
1508
+ interface BM25LOptions {
1509
+ /** Term frequency saturation parameter (default: 1.5) */
1510
+ k1?: number;
1511
+ /** Length normalization parameter (default: 0.75) */
1512
+ b?: number;
1513
+ /** Lower-bound adjustment from BM25L paper (default: 0.5) */
1514
+ delta?: number;
1515
+ }
1516
+ interface RerankedResult<T> {
1517
+ item: T;
1518
+ originalIndex: number;
1519
+ semanticScore: number;
1520
+ bm25Score: number;
1521
+ hybridScore: number;
1522
+ }
1523
+ interface HybridSearchOptions extends BM25LOptions {
1524
+ /** Weight for semantic score (0-1, default: 0.7) */
1525
+ semanticWeight?: number;
1526
+ /** Weight for BM25 score (0-1, default: 0.3) */
1527
+ bm25Weight?: number;
1528
+ /** Minimum hybrid score threshold (0-1, default: 0) */
1529
+ minScore?: number;
1530
+ }
1531
+ /**
1532
+ * BM25L implementation for lexical scoring
1533
+ */
1534
+ declare class BM25L {
1535
+ private k1;
1536
+ private b;
1537
+ private delta;
1538
+ private documents;
1539
+ private docLengths;
1540
+ private avgDocLength;
1541
+ private termDocFreq;
1542
+ /**
1543
+ * @param documents - Array of raw documents (strings)
1544
+ * @param opts - Optional BM25L parameters
1545
+ */
1546
+ constructor(documents?: string[], opts?: BM25LOptions);
1547
+ /**
1548
+ * Tokenize text into lowercase alphanumeric tokens
1549
+ */
1550
+ tokenize(text: string): string[];
1551
+ /**
1552
+ * Compute IDF (Inverse Document Frequency) with smoothing
1553
+ */
1554
+ private idf;
1555
+ /**
1556
+ * Compute BM25L score for a single document
1557
+ */
1558
+ score(query: string, docIndex: number): number;
1559
+ /**
1560
+ * Search and rank all documents
1561
+ */
1562
+ search(query: string): Array<{
1563
+ index: number;
1564
+ score: number;
1565
+ }>;
1566
+ }
1567
+ /**
1568
+ * Hybrid reranker that combines semantic and BM25L scores
1569
+ *
1570
+ * @param query - The search query
1571
+ * @param items - Array of items to rerank
1572
+ * @param getDocument - Function to extract document text from an item
1573
+ * @param getSemanticScore - Function to extract semantic similarity score from an item
1574
+ * @param options - Hybrid search options
1575
+ * @returns Reranked items with hybrid scores
1576
+ */
1577
+ declare function hybridRerank<T>(query: string, items: T[], getDocument: (item: T) => string, getSemanticScore: (item: T) => number, options?: HybridSearchOptions): RerankedResult<T>[];
1578
+ /**
1579
+ * Simple reranking function for ChromaDB results
1580
+ *
1581
+ * This is a convenience wrapper for reranking ChromaDB query results
1582
+ * that follow the standard { ids, documents, metadatas, distances } format.
1583
+ *
1584
+ * @param query - The search query
1585
+ * @param chromaResults - ChromaDB query results
1586
+ * @param options - Hybrid search options
1587
+ * @returns Reranked results with hybrid scores
1588
+ */
1589
+ declare function rerankChromaResults(query: string, chromaResults: {
1590
+ ids: string[][];
1591
+ documents: (string | null)[][];
1592
+ metadatas: Record<string, any>[][];
1593
+ distances: number[][];
1594
+ }, options?: HybridSearchOptions): Array<{
1595
+ id: string;
1596
+ document: string | null;
1597
+ metadata: Record<string, any>;
1598
+ distance: number;
1599
+ semanticScore: number;
1600
+ bm25Score: number;
1601
+ hybridScore: number;
1602
+ }>;
1603
+ /**
1604
+ * Rerank conversation search results specifically
1605
+ *
1606
+ * This function is designed to work with the conversation-history.search collection
1607
+ * where we need to fetch more results initially and then rerank them.
1608
+ *
1609
+ * @param query - The user's search query
1610
+ * @param results - Array of conversation search results from ChromaDB
1611
+ * @param options - Hybrid search options
1612
+ * @returns Reranked results sorted by hybrid score
1613
+ */
1614
+ declare function rerankConversationResults<T extends {
1615
+ userPrompt?: string;
1616
+ similarity?: number;
1617
+ }>(query: string, results: T[], options?: HybridSearchOptions): Array<T & {
1618
+ hybridScore: number;
1619
+ bm25Score: number;
1620
+ }>;
1621
+
1486
1622
  declare const SDK_VERSION = "0.0.8";
1487
1623
  type MessageTypeHandler = (message: IncomingMessage) => void | Promise<void>;
1488
1624
  declare class SuperatomSDK {
@@ -1587,4 +1723,4 @@ declare class SuperatomSDK {
1587
1723
  getTools(): Tool$1[];
1588
1724
  }
1589
1725
 
1590
- export { type Action, CONTEXT_CONFIG, type CapturedLog, CleanupService, type CollectionHandler, type CollectionOperation, type DBUIBlock, type IncomingMessage, type KbNodesQueryFilters, type KbNodesRequestPayload, LLM, type LogLevel, type Message, SDK_VERSION, STORAGE_CONFIG, SuperatomSDK, type SuperatomSDKConfig, Thread, ThreadManager, type Tool$1 as Tool, UIBlock, UILogCollector, type User, UserManager, type UsersData, logger };
1726
+ export { type Action, BM25L, type BM25LOptions, CONTEXT_CONFIG, type CapturedLog, CleanupService, type CollectionHandler, type CollectionOperation, type DBUIBlock, type HybridSearchOptions, type IncomingMessage, type KbNodesQueryFilters, type KbNodesRequestPayload, LLM, type LogLevel, type Message, type RerankedResult, SDK_VERSION, STORAGE_CONFIG, SuperatomSDK, type SuperatomSDKConfig, Thread, ThreadManager, type Tool$1 as Tool, UIBlock, UILogCollector, type User, UserManager, type UsersData, hybridRerank, logger, rerankChromaResults, rerankConversationResults };
package/dist/index.d.ts CHANGED
@@ -395,6 +395,7 @@ declare const UserSchema: z.ZodObject<{
395
395
  password: z.ZodString;
396
396
  fullname: z.ZodOptional<z.ZodString>;
397
397
  role: z.ZodOptional<z.ZodString>;
398
+ userInfo: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
398
399
  wsIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
399
400
  }, "strip", z.ZodTypeAny, {
400
401
  username: string;
@@ -402,6 +403,7 @@ declare const UserSchema: z.ZodObject<{
402
403
  email?: string | undefined;
403
404
  fullname?: string | undefined;
404
405
  role?: string | undefined;
406
+ userInfo?: Record<string, unknown> | undefined;
405
407
  wsIds?: string[] | undefined;
406
408
  }, {
407
409
  username: string;
@@ -409,6 +411,7 @@ declare const UserSchema: z.ZodObject<{
409
411
  email?: string | undefined;
410
412
  fullname?: string | undefined;
411
413
  role?: string | undefined;
414
+ userInfo?: Record<string, unknown> | undefined;
412
415
  wsIds?: string[] | undefined;
413
416
  }>;
414
417
  type User = z.infer<typeof UserSchema>;
@@ -419,6 +422,7 @@ declare const UsersDataSchema: z.ZodObject<{
419
422
  password: z.ZodString;
420
423
  fullname: z.ZodOptional<z.ZodString>;
421
424
  role: z.ZodOptional<z.ZodString>;
425
+ userInfo: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
422
426
  wsIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
423
427
  }, "strip", z.ZodTypeAny, {
424
428
  username: string;
@@ -426,6 +430,7 @@ declare const UsersDataSchema: z.ZodObject<{
426
430
  email?: string | undefined;
427
431
  fullname?: string | undefined;
428
432
  role?: string | undefined;
433
+ userInfo?: Record<string, unknown> | undefined;
429
434
  wsIds?: string[] | undefined;
430
435
  }, {
431
436
  username: string;
@@ -433,6 +438,7 @@ declare const UsersDataSchema: z.ZodObject<{
433
438
  email?: string | undefined;
434
439
  fullname?: string | undefined;
435
440
  role?: string | undefined;
441
+ userInfo?: Record<string, unknown> | undefined;
436
442
  wsIds?: string[] | undefined;
437
443
  }>, "many">;
438
444
  }, "strip", z.ZodTypeAny, {
@@ -442,6 +448,7 @@ declare const UsersDataSchema: z.ZodObject<{
442
448
  email?: string | undefined;
443
449
  fullname?: string | undefined;
444
450
  role?: string | undefined;
451
+ userInfo?: Record<string, unknown> | undefined;
445
452
  wsIds?: string[] | undefined;
446
453
  }[];
447
454
  }, {
@@ -451,6 +458,7 @@ declare const UsersDataSchema: z.ZodObject<{
451
458
  email?: string | undefined;
452
459
  fullname?: string | undefined;
453
460
  role?: string | undefined;
461
+ userInfo?: Record<string, unknown> | undefined;
454
462
  wsIds?: string[] | undefined;
455
463
  }[];
456
464
  }>;
@@ -1483,6 +1491,134 @@ declare const CONTEXT_CONFIG: {
1483
1491
  MAX_CONVERSATION_CONTEXT_BLOCKS: number;
1484
1492
  };
1485
1493
 
1494
+ /**
1495
+ * BM25L Reranker for hybrid semantic search
1496
+ *
1497
+ * BM25L is an improved variant of BM25 that provides better handling of
1498
+ * long documents and term frequency saturation. This implementation is
1499
+ * designed to rerank semantic search results from ChromaDB.
1500
+ *
1501
+ * The hybrid approach combines:
1502
+ * 1. Semantic similarity from ChromaDB embeddings (dense vectors)
1503
+ * 2. Lexical matching from BM25L (sparse, keyword-based)
1504
+ *
1505
+ * This addresses the weakness of pure semantic search which may miss
1506
+ * exact keyword matches that are important for user intent.
1507
+ */
1508
+ interface BM25LOptions {
1509
+ /** Term frequency saturation parameter (default: 1.5) */
1510
+ k1?: number;
1511
+ /** Length normalization parameter (default: 0.75) */
1512
+ b?: number;
1513
+ /** Lower-bound adjustment from BM25L paper (default: 0.5) */
1514
+ delta?: number;
1515
+ }
1516
+ interface RerankedResult<T> {
1517
+ item: T;
1518
+ originalIndex: number;
1519
+ semanticScore: number;
1520
+ bm25Score: number;
1521
+ hybridScore: number;
1522
+ }
1523
+ interface HybridSearchOptions extends BM25LOptions {
1524
+ /** Weight for semantic score (0-1, default: 0.7) */
1525
+ semanticWeight?: number;
1526
+ /** Weight for BM25 score (0-1, default: 0.3) */
1527
+ bm25Weight?: number;
1528
+ /** Minimum hybrid score threshold (0-1, default: 0) */
1529
+ minScore?: number;
1530
+ }
1531
+ /**
1532
+ * BM25L implementation for lexical scoring
1533
+ */
1534
+ declare class BM25L {
1535
+ private k1;
1536
+ private b;
1537
+ private delta;
1538
+ private documents;
1539
+ private docLengths;
1540
+ private avgDocLength;
1541
+ private termDocFreq;
1542
+ /**
1543
+ * @param documents - Array of raw documents (strings)
1544
+ * @param opts - Optional BM25L parameters
1545
+ */
1546
+ constructor(documents?: string[], opts?: BM25LOptions);
1547
+ /**
1548
+ * Tokenize text into lowercase alphanumeric tokens
1549
+ */
1550
+ tokenize(text: string): string[];
1551
+ /**
1552
+ * Compute IDF (Inverse Document Frequency) with smoothing
1553
+ */
1554
+ private idf;
1555
+ /**
1556
+ * Compute BM25L score for a single document
1557
+ */
1558
+ score(query: string, docIndex: number): number;
1559
+ /**
1560
+ * Search and rank all documents
1561
+ */
1562
+ search(query: string): Array<{
1563
+ index: number;
1564
+ score: number;
1565
+ }>;
1566
+ }
1567
+ /**
1568
+ * Hybrid reranker that combines semantic and BM25L scores
1569
+ *
1570
+ * @param query - The search query
1571
+ * @param items - Array of items to rerank
1572
+ * @param getDocument - Function to extract document text from an item
1573
+ * @param getSemanticScore - Function to extract semantic similarity score from an item
1574
+ * @param options - Hybrid search options
1575
+ * @returns Reranked items with hybrid scores
1576
+ */
1577
+ declare function hybridRerank<T>(query: string, items: T[], getDocument: (item: T) => string, getSemanticScore: (item: T) => number, options?: HybridSearchOptions): RerankedResult<T>[];
1578
+ /**
1579
+ * Simple reranking function for ChromaDB results
1580
+ *
1581
+ * This is a convenience wrapper for reranking ChromaDB query results
1582
+ * that follow the standard { ids, documents, metadatas, distances } format.
1583
+ *
1584
+ * @param query - The search query
1585
+ * @param chromaResults - ChromaDB query results
1586
+ * @param options - Hybrid search options
1587
+ * @returns Reranked results with hybrid scores
1588
+ */
1589
+ declare function rerankChromaResults(query: string, chromaResults: {
1590
+ ids: string[][];
1591
+ documents: (string | null)[][];
1592
+ metadatas: Record<string, any>[][];
1593
+ distances: number[][];
1594
+ }, options?: HybridSearchOptions): Array<{
1595
+ id: string;
1596
+ document: string | null;
1597
+ metadata: Record<string, any>;
1598
+ distance: number;
1599
+ semanticScore: number;
1600
+ bm25Score: number;
1601
+ hybridScore: number;
1602
+ }>;
1603
+ /**
1604
+ * Rerank conversation search results specifically
1605
+ *
1606
+ * This function is designed to work with the conversation-history.search collection
1607
+ * where we need to fetch more results initially and then rerank them.
1608
+ *
1609
+ * @param query - The user's search query
1610
+ * @param results - Array of conversation search results from ChromaDB
1611
+ * @param options - Hybrid search options
1612
+ * @returns Reranked results sorted by hybrid score
1613
+ */
1614
+ declare function rerankConversationResults<T extends {
1615
+ userPrompt?: string;
1616
+ similarity?: number;
1617
+ }>(query: string, results: T[], options?: HybridSearchOptions): Array<T & {
1618
+ hybridScore: number;
1619
+ bm25Score: number;
1620
+ }>;
1621
+
1486
1622
  declare const SDK_VERSION = "0.0.8";
1487
1623
  type MessageTypeHandler = (message: IncomingMessage) => void | Promise<void>;
1488
1624
  declare class SuperatomSDK {
@@ -1587,4 +1723,4 @@ declare class SuperatomSDK {
1587
1723
  getTools(): Tool$1[];
1588
1724
  }
1589
1725
 
1590
- export { type Action, CONTEXT_CONFIG, type CapturedLog, CleanupService, type CollectionHandler, type CollectionOperation, type DBUIBlock, type IncomingMessage, type KbNodesQueryFilters, type KbNodesRequestPayload, LLM, type LogLevel, type Message, SDK_VERSION, STORAGE_CONFIG, SuperatomSDK, type SuperatomSDKConfig, Thread, ThreadManager, type Tool$1 as Tool, UIBlock, UILogCollector, type User, UserManager, type UsersData, logger };
1726
+ export { type Action, BM25L, type BM25LOptions, CONTEXT_CONFIG, type CapturedLog, CleanupService, type CollectionHandler, type CollectionOperation, type DBUIBlock, type HybridSearchOptions, type IncomingMessage, type KbNodesQueryFilters, type KbNodesRequestPayload, LLM, type LogLevel, type Message, type RerankedResult, SDK_VERSION, STORAGE_CONFIG, SuperatomSDK, type SuperatomSDKConfig, Thread, ThreadManager, type Tool$1 as Tool, UIBlock, UILogCollector, type User, UserManager, type UsersData, hybridRerank, logger, rerankChromaResults, rerankConversationResults };