@ppagent/memory 0.1.0 → 0.1.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/dist/index.d.ts +231 -122
- package/dist/index.js +410 -160
- package/llms.txt +845 -845
- package/package.json +49 -48
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,27 @@ type MessageType = "text" | "image" | "file";
|
|
|
2
2
|
type FactLevel = "user" | "chat";
|
|
3
3
|
type SearchMode = "fast" | "auto" | "all";
|
|
4
4
|
type SearchScope = "session" | "chat" | "user" | "all";
|
|
5
|
+
/**
|
|
6
|
+
* 分页参数(可选)。
|
|
7
|
+
* - offset:起始偏移,从 0 开始(负数按 0 处理)。
|
|
8
|
+
* - limit:本页最大条数;省略或 <=0 表示「从 offset 起取全部」。
|
|
9
|
+
*/
|
|
10
|
+
interface PageParams {
|
|
11
|
+
offset?: number;
|
|
12
|
+
limit?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 分页结果信封。仅当调用方传入 PageParams 时返回;不传则保持返回纯数组(向后兼容)。
|
|
16
|
+
* - items:当前页数据。
|
|
17
|
+
* - total:过滤后、分页前的总条数(供前端计算总页数)。
|
|
18
|
+
* - offset / limit:实际生效的分页参数(limit 为 0 表示未限制)。
|
|
19
|
+
*/
|
|
20
|
+
interface Paginated<T> {
|
|
21
|
+
items: T[];
|
|
22
|
+
total: number;
|
|
23
|
+
offset: number;
|
|
24
|
+
limit: number;
|
|
25
|
+
}
|
|
5
26
|
/**
|
|
6
27
|
* 多模态消息的单个内容块,与 OpenAI content part 对齐
|
|
7
28
|
*/
|
|
@@ -293,7 +314,7 @@ interface MemoryConfig {
|
|
|
293
314
|
llmBaseUrl: string;
|
|
294
315
|
llmApiKey: string;
|
|
295
316
|
llmModel: string;
|
|
296
|
-
/** LLM / embedding HTTP 请求超时(毫秒,默认
|
|
317
|
+
/** LLM / embedding HTTP 请求超时(毫秒,默认 60000)。超时即中止并按重试策略处理。*/
|
|
297
318
|
httpTimeoutMs?: number;
|
|
298
319
|
/** LLM / embedding 请求失败(网络错误/超时/5xx/429)时的最大重试次数(默认 2,即最多请求 3 次)。*/
|
|
299
320
|
httpMaxRetries?: number;
|
|
@@ -345,10 +366,152 @@ interface MemoryConfig {
|
|
|
345
366
|
graphExtractConcurrency?: number;
|
|
346
367
|
/** waitGraph=true 时等待图谱构建的整体超时(毫秒,默认 120000)*/
|
|
347
368
|
graphBuildTimeoutMs?: number;
|
|
369
|
+
/**
|
|
370
|
+
* init 完成后是否后台执行一次存储压实(碎片合并 + 历史版本清理,默认 true)。
|
|
371
|
+
* 不阻塞启动;嵌入式单进程使用时建议保持开启,否则 LanceDB 版本目录会无限膨胀、启动越来越慢。
|
|
372
|
+
*/
|
|
373
|
+
autoOptimizeOnInit?: boolean;
|
|
374
|
+
/** 压实时保留多久内的历史版本(毫秒,默认 0 即仅保留当前版本)。*/
|
|
375
|
+
optimizeVersionRetentionMs?: number;
|
|
376
|
+
/** 启动时恢复各会话历史窗口的并发数(默认 8,旧行为为逐会话串行)。*/
|
|
377
|
+
restoreConcurrency?: number;
|
|
348
378
|
}
|
|
349
379
|
interface ResolvedConfig extends Required<MemoryConfig> {
|
|
350
380
|
}
|
|
351
381
|
|
|
382
|
+
/** 单表压实结果(compaction + 历史版本清理)*/
|
|
383
|
+
interface StorageOptimizeResult {
|
|
384
|
+
table: string;
|
|
385
|
+
fragmentsRemoved: number;
|
|
386
|
+
fragmentsAdded: number;
|
|
387
|
+
filesRemoved: number;
|
|
388
|
+
oldVersionsRemoved: number;
|
|
389
|
+
bytesRemoved: number;
|
|
390
|
+
}
|
|
391
|
+
declare class LanceService {
|
|
392
|
+
private readonly config;
|
|
393
|
+
private conn;
|
|
394
|
+
private messagesTable;
|
|
395
|
+
private topicsTable;
|
|
396
|
+
private factsTable;
|
|
397
|
+
private sessionsTable;
|
|
398
|
+
private documentsTable;
|
|
399
|
+
private chunksTable;
|
|
400
|
+
private isNewMessagesTable;
|
|
401
|
+
private isNewTopicsTable;
|
|
402
|
+
private isNewSessionsTable;
|
|
403
|
+
private isNewDocumentsTable;
|
|
404
|
+
private isNewChunksTable;
|
|
405
|
+
constructor(config: ResolvedConfig);
|
|
406
|
+
init(): Promise<void>;
|
|
407
|
+
/**
|
|
408
|
+
* 按需补齐索引:先经 listIndices 判存在,缺失的列才 createIndex(且 replace:false)。
|
|
409
|
+
* createIndex 默认 replace:true 会在每次启动时全量重建索引并提交新表版本——
|
|
410
|
+
* 这正是历史上「启动越来越慢 + _versions 目录膨胀」的根源,绝不可回退到无条件 createIndex。
|
|
411
|
+
*/
|
|
412
|
+
private ensureIndexes;
|
|
413
|
+
/**
|
|
414
|
+
* 存储压实:逐表执行碎片合并 + 清理 retentionMs 之前的历史版本。
|
|
415
|
+
* 嵌入式场景下 LanceDB 不会自动做这件事,长期运行后版本/碎片无限累积会显著拖慢启动与查询。
|
|
416
|
+
*/
|
|
417
|
+
optimizeStorage(retentionMs?: number): Promise<StorageOptimizeResult[]>;
|
|
418
|
+
/**
|
|
419
|
+
* 为存量 messages 表添加 parts 列(如果缺失)。
|
|
420
|
+
* LanceDB 0.14+ 支持 addColumns;旧版本会 throw,此时 rowToMessage 的 ?? "[]" 兜底。
|
|
421
|
+
*/
|
|
422
|
+
private _ensurePartsColumn;
|
|
423
|
+
/**
|
|
424
|
+
* 为存量 topics 表添加 title 列(如果缺失)。
|
|
425
|
+
* 旧版本不支持 addColumns 时忽略,读取时 rowToTopic 的 ?? "" 兜底。
|
|
426
|
+
*/
|
|
427
|
+
private _ensureTopicTitleColumn;
|
|
428
|
+
addMessages(messages: StoredMessage[]): Promise<void>;
|
|
429
|
+
addTopic(topic: Topic): Promise<void>;
|
|
430
|
+
updateTopicRecallCount(summaryId: string, count: number): Promise<void>;
|
|
431
|
+
getRecentTopics(chatId: string, userId: string, n1: number, n2: number, n3: number): Promise<{
|
|
432
|
+
detail: Topic[];
|
|
433
|
+
summary: Topic[];
|
|
434
|
+
concise: Topic[];
|
|
435
|
+
}>;
|
|
436
|
+
getMessagesSince(sessionId: string, since: number, limit?: number): Promise<StoredMessage[]>;
|
|
437
|
+
getLatestMessages(sessionId: string, limit: number): Promise<StoredMessage[]>;
|
|
438
|
+
/** 取某会话的全部消息(按 createdAt 升序),供管理面板分页切片使用 */
|
|
439
|
+
getAllMessagesBySession(sessionId: string): Promise<StoredMessage[]>;
|
|
440
|
+
searchMessages(vector: number[], filter?: string, limit?: number): Promise<Array<StoredMessage & {
|
|
441
|
+
_distance: number;
|
|
442
|
+
}>>;
|
|
443
|
+
hybridSearchMessages(query: string, vector: number[], filter?: string, limit?: number): Promise<StoredMessage[]>;
|
|
444
|
+
hybridSearchTopics(query: string, vector: number[], filter?: string, limit?: number): Promise<Topic[]>;
|
|
445
|
+
saveFact(fact: Fact): Promise<void>;
|
|
446
|
+
getAllFacts(): Promise<Fact[]>;
|
|
447
|
+
getAllSessionIds(): Promise<string[]>;
|
|
448
|
+
insertSession(session: Session): Promise<void>;
|
|
449
|
+
upsertSession(session: Session): Promise<void>;
|
|
450
|
+
getAllSessions(): Promise<Session[]>;
|
|
451
|
+
deleteSession(sessionId: string): Promise<void>;
|
|
452
|
+
/** 全量读取 topics(管理面板列表用,不做 recall 加权排序,按 endTime 倒序)*/
|
|
453
|
+
getAllTopics(): Promise<Topic[]>;
|
|
454
|
+
/** 删除单条 fact */
|
|
455
|
+
deleteFact(factId: string): Promise<void>;
|
|
456
|
+
/** 删除某会话下的全部消息(级联删除会话时使用)*/
|
|
457
|
+
deleteMessagesBySession(sessionId: string): Promise<void>;
|
|
458
|
+
/** 删除某会话下的全部 topics(级联删除会话时使用)*/
|
|
459
|
+
deleteTopicsBySession(sessionId: string): Promise<void>;
|
|
460
|
+
/** 各表行数统计(概览卡片用)*/
|
|
461
|
+
countAll(): Promise<{
|
|
462
|
+
sessions: number;
|
|
463
|
+
messages: number;
|
|
464
|
+
topics: number;
|
|
465
|
+
facts: number;
|
|
466
|
+
}>;
|
|
467
|
+
/**
|
|
468
|
+
* 按天聚合最近 days 天的活跃趋势(概览图表用)。
|
|
469
|
+
* 返回连续日期序列(含无数据的零值天),按本地日期分桶。
|
|
470
|
+
*/
|
|
471
|
+
trendDaily(days: number): Promise<{
|
|
472
|
+
date: string;
|
|
473
|
+
sessions: number;
|
|
474
|
+
messages: number;
|
|
475
|
+
facts: number;
|
|
476
|
+
}[]>;
|
|
477
|
+
addDocument(doc: Document): Promise<void>;
|
|
478
|
+
addChunks(chunks: Chunk[]): Promise<void>;
|
|
479
|
+
updateDocumentGraphFlag(docId: string, hasGraph: boolean): Promise<void>;
|
|
480
|
+
getDocument(docId: string): Promise<Document | null>;
|
|
481
|
+
/** 查找同域同 hash 的文档(去重用)*/
|
|
482
|
+
findDocumentByHash(contentHash: string, filter?: string): Promise<Document | null>;
|
|
483
|
+
/** 按域过滤返回 docId 列表(chunkRedundantIds=false 时用于 chunk 过滤)*/
|
|
484
|
+
getDocIdsByDomain(filter?: string): Promise<string[]>;
|
|
485
|
+
/** 文档级粗召回:对摘要向量做向量搜索,定位候选文档 */
|
|
486
|
+
searchDocuments(vector: number[], filter?: string, limit?: number): Promise<Array<Document & {
|
|
487
|
+
_distance: number;
|
|
488
|
+
}>>;
|
|
489
|
+
/** 知识片段混合检索(BM25 + 向量),失败回退纯向量 */
|
|
490
|
+
searchChunks(query: string, vector: number[], filter?: string, limit?: number): Promise<Chunk[]>;
|
|
491
|
+
deleteDocument(docId: string): Promise<void>;
|
|
492
|
+
deleteChunksByDoc(docId: string): Promise<void>;
|
|
493
|
+
/** 全量读取文档(管理面板用),按更新时间倒序 */
|
|
494
|
+
getAllDocuments(): Promise<Document[]>;
|
|
495
|
+
/** 知识库行数统计 */
|
|
496
|
+
countKnowledge(): Promise<{
|
|
497
|
+
documents: number;
|
|
498
|
+
chunks: number;
|
|
499
|
+
}>;
|
|
500
|
+
/**
|
|
501
|
+
* 根据 metadata 字段内容构建 SQL LIKE 过滤条件。
|
|
502
|
+
*
|
|
503
|
+
* metadata 以 JSON 字符串存储,此方法将键值对转换为 SQL LIKE 表达式,
|
|
504
|
+
* 可直接传给 searchMessages / hybridSearchTopics 的 filter 参数。
|
|
505
|
+
*
|
|
506
|
+
* 示例:buildMetadataFilter({ env: "prod", version: 2 })
|
|
507
|
+
* → `metadata LIKE '%"env":"prod"%' AND metadata LIKE '%"version":2%'`
|
|
508
|
+
*
|
|
509
|
+
* 注意:仅适合简单标量值(字符串、数字、布尔)的精确匹配。
|
|
510
|
+
* 复杂嵌套对象或含空格的 JSON 值可能无法可靠匹配。
|
|
511
|
+
*/
|
|
512
|
+
static buildMetadataFilter(conditions: Record<string, string | number | boolean>): string;
|
|
513
|
+
}
|
|
514
|
+
|
|
352
515
|
declare class MemoryManager {
|
|
353
516
|
private readonly config;
|
|
354
517
|
private readonly lance;
|
|
@@ -362,6 +525,11 @@ declare class MemoryManager {
|
|
|
362
525
|
private readonly sessionMap;
|
|
363
526
|
constructor(config: MemoryConfig);
|
|
364
527
|
init(): Promise<void>;
|
|
528
|
+
/**
|
|
529
|
+
* 手动触发存储压实与历史版本清理(init 后台会自动执行一次;上层维护任务也可调用)。
|
|
530
|
+
* @param retentionMs 保留多久内的历史版本,默认取配置 optimizeVersionRetentionMs
|
|
531
|
+
*/
|
|
532
|
+
optimizeStorage(retentionMs?: number): Promise<StorageOptimizeResult[]>;
|
|
365
533
|
private restoreFromStorage;
|
|
366
534
|
updateChat(messages: RawMessage[], opts?: UpdateChatOptions): Promise<void>;
|
|
367
535
|
flushChat(sessionId?: string, opts?: {
|
|
@@ -417,19 +585,39 @@ declare class MemoryManager {
|
|
|
417
585
|
messages: number;
|
|
418
586
|
facts: number;
|
|
419
587
|
}[]>;
|
|
420
|
-
/**
|
|
588
|
+
/**
|
|
589
|
+
* 列出会话,可选按 userId / chatId 过滤,按更新时间倒序。
|
|
590
|
+
* 传入 page 时返回分页信封 {items,total,offset,limit},不传则返回全量数组(向后兼容)。
|
|
591
|
+
*/
|
|
421
592
|
listSessions(filter?: {
|
|
422
593
|
userId?: string;
|
|
423
594
|
chatId?: string;
|
|
424
595
|
}): SessionView[];
|
|
425
|
-
|
|
596
|
+
listSessions(filter: {
|
|
597
|
+
userId?: string;
|
|
598
|
+
chatId?: string;
|
|
599
|
+
} | undefined, page: PageParams): Paginated<SessionView>;
|
|
600
|
+
/**
|
|
601
|
+
* 列出会话内的消息(按时间正序)。
|
|
602
|
+
* 传入 page 时返回分页信封(offset/limit 基于全量消息切片);
|
|
603
|
+
* 仅传 limit(number)时保持旧行为:返回最新 limit 条。
|
|
604
|
+
*/
|
|
426
605
|
listMessages(sessionId: string, limit?: number): Promise<StoredMessage[]>;
|
|
427
|
-
|
|
606
|
+
listMessages(sessionId: string, page: PageParams): Promise<Paginated<StoredMessage>>;
|
|
607
|
+
/**
|
|
608
|
+
* 列出主题/摘要,可选按 sessionId / userId / chatId 过滤。
|
|
609
|
+
* 传入 page 时返回分页信封,不传则返回全量数组(向后兼容)。
|
|
610
|
+
*/
|
|
428
611
|
listTopics(filter?: {
|
|
429
612
|
sessionId?: string;
|
|
430
613
|
userId?: string;
|
|
431
614
|
chatId?: string;
|
|
432
615
|
}): Promise<Topic[]>;
|
|
616
|
+
listTopics(filter: {
|
|
617
|
+
sessionId?: string;
|
|
618
|
+
userId?: string;
|
|
619
|
+
chatId?: string;
|
|
620
|
+
} | undefined, page: PageParams): Promise<Paginated<Topic>>;
|
|
433
621
|
/**
|
|
434
622
|
* 列出事实,按创建时间倒序。过滤遵循 scope 层级包含语义:
|
|
435
623
|
* - 按 chatId 过滤时,除该 chat 级 facts 外,还包含该 chat 所属 user 的 user 级 facts
|
|
@@ -442,16 +630,41 @@ declare class MemoryManager {
|
|
|
442
630
|
userId?: string;
|
|
443
631
|
chatId?: string;
|
|
444
632
|
}): Fact[];
|
|
633
|
+
listFacts(filter: {
|
|
634
|
+
level?: FactLevel;
|
|
635
|
+
userId?: string;
|
|
636
|
+
chatId?: string;
|
|
637
|
+
} | undefined, page: PageParams): Paginated<Fact>;
|
|
445
638
|
/** 由 chatId 反查所属 userId:优先用会话表映射,兜底用 chat 级 fact 自身。 */
|
|
446
639
|
private resolveChatOwner;
|
|
447
640
|
/** 手动新增一条事实 */
|
|
448
641
|
addFact(content: string, level: FactLevel, userId: string, chatId: string, sessionId?: string): Promise<void>;
|
|
449
642
|
/** 删除单条事实,返回是否命中 */
|
|
450
643
|
deleteFact(factId: string): Promise<boolean>;
|
|
451
|
-
/**
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
644
|
+
/**
|
|
645
|
+
* 列出实体(知识图谱节点),可选按 userId / chatId 过滤。
|
|
646
|
+
* 传入 page 时返回分页信封,不传则返回数组(向后兼容)。
|
|
647
|
+
*/
|
|
648
|
+
listEntities(filter?: {
|
|
649
|
+
userId?: string;
|
|
650
|
+
chatId?: string;
|
|
651
|
+
}): Promise<Entity[]>;
|
|
652
|
+
listEntities(filter: {
|
|
653
|
+
userId?: string;
|
|
654
|
+
chatId?: string;
|
|
655
|
+
} | undefined, page: PageParams): Promise<Paginated<Entity>>;
|
|
656
|
+
/**
|
|
657
|
+
* 列出关系(知识图谱边),可选按 userId / chatId 过滤。
|
|
658
|
+
* 传入 page 时返回分页信封,不传则返回数组(向后兼容)。
|
|
659
|
+
*/
|
|
660
|
+
listRelations(filter?: {
|
|
661
|
+
userId?: string;
|
|
662
|
+
chatId?: string;
|
|
663
|
+
}): Promise<Relation[]>;
|
|
664
|
+
listRelations(filter: {
|
|
665
|
+
userId?: string;
|
|
666
|
+
chatId?: string;
|
|
667
|
+
} | undefined, page: PageParams): Promise<Paginated<Relation>>;
|
|
455
668
|
/** 摄入一个文档(markdown)。document 落库即返回,切块/embedding/图谱后台执行(wait=true 可等待)。*/
|
|
456
669
|
addDocument(opts: AddDocumentOptions): Promise<{
|
|
457
670
|
docId: string;
|
|
@@ -462,127 +675,23 @@ declare class MemoryManager {
|
|
|
462
675
|
getDocument(docId: string): Promise<Document | null>;
|
|
463
676
|
/** 删除文档(级联删除其片段与知识图谱痕迹),返回是否命中。*/
|
|
464
677
|
deleteDocument(docId: string): Promise<boolean>;
|
|
465
|
-
/**
|
|
678
|
+
/**
|
|
679
|
+
* 列出文档,可选按 userId / chatId / sessionId 过滤,按更新时间倒序。
|
|
680
|
+
* 传入 page 时返回分页信封,不传则返回数组(向后兼容)。
|
|
681
|
+
*/
|
|
466
682
|
listDocuments(filter?: {
|
|
467
683
|
userId?: string;
|
|
468
684
|
chatId?: string;
|
|
469
685
|
sessionId?: string;
|
|
470
686
|
}): Promise<Document[]>;
|
|
687
|
+
listDocuments(filter: {
|
|
688
|
+
userId?: string;
|
|
689
|
+
chatId?: string;
|
|
690
|
+
sessionId?: string;
|
|
691
|
+
} | undefined, page: PageParams): Promise<Paginated<Document>>;
|
|
471
692
|
destroy(): void;
|
|
472
693
|
}
|
|
473
694
|
|
|
474
|
-
declare class LanceService {
|
|
475
|
-
private readonly config;
|
|
476
|
-
private conn;
|
|
477
|
-
private messagesTable;
|
|
478
|
-
private topicsTable;
|
|
479
|
-
private factsTable;
|
|
480
|
-
private sessionsTable;
|
|
481
|
-
private documentsTable;
|
|
482
|
-
private chunksTable;
|
|
483
|
-
private isNewMessagesTable;
|
|
484
|
-
private isNewSessionsTable;
|
|
485
|
-
private isNewDocumentsTable;
|
|
486
|
-
private isNewChunksTable;
|
|
487
|
-
constructor(config: ResolvedConfig);
|
|
488
|
-
init(): Promise<void>;
|
|
489
|
-
private ensureFtsIndexes;
|
|
490
|
-
/**
|
|
491
|
-
* 为存量 messages 表添加 parts 列(如果缺失)。
|
|
492
|
-
* LanceDB 0.14+ 支持 addColumns;旧版本会 throw,此时 rowToMessage 的 ?? "[]" 兜底。
|
|
493
|
-
*/
|
|
494
|
-
private _ensurePartsColumn;
|
|
495
|
-
/**
|
|
496
|
-
* 为存量 topics 表添加 title 列(如果缺失)。
|
|
497
|
-
* 旧版本不支持 addColumns 时忽略,读取时 rowToTopic 的 ?? "" 兜底。
|
|
498
|
-
*/
|
|
499
|
-
private _ensureTopicTitleColumn;
|
|
500
|
-
private ensureScalarIndex;
|
|
501
|
-
addMessages(messages: StoredMessage[]): Promise<void>;
|
|
502
|
-
addTopic(topic: Topic): Promise<void>;
|
|
503
|
-
updateTopicRecallCount(summaryId: string, count: number): Promise<void>;
|
|
504
|
-
getRecentTopics(chatId: string, userId: string, n1: number, n2: number, n3: number): Promise<{
|
|
505
|
-
detail: Topic[];
|
|
506
|
-
summary: Topic[];
|
|
507
|
-
concise: Topic[];
|
|
508
|
-
}>;
|
|
509
|
-
getMessagesSince(sessionId: string, since: number, limit?: number): Promise<StoredMessage[]>;
|
|
510
|
-
getLatestMessages(sessionId: string, limit: number): Promise<StoredMessage[]>;
|
|
511
|
-
searchMessages(vector: number[], filter?: string, limit?: number): Promise<Array<StoredMessage & {
|
|
512
|
-
_distance: number;
|
|
513
|
-
}>>;
|
|
514
|
-
hybridSearchMessages(query: string, vector: number[], filter?: string, limit?: number): Promise<StoredMessage[]>;
|
|
515
|
-
hybridSearchTopics(query: string, vector: number[], filter?: string, limit?: number): Promise<Topic[]>;
|
|
516
|
-
saveFact(fact: Fact): Promise<void>;
|
|
517
|
-
getAllFacts(): Promise<Fact[]>;
|
|
518
|
-
getAllSessionIds(): Promise<string[]>;
|
|
519
|
-
insertSession(session: Session): Promise<void>;
|
|
520
|
-
upsertSession(session: Session): Promise<void>;
|
|
521
|
-
getAllSessions(): Promise<Session[]>;
|
|
522
|
-
deleteSession(sessionId: string): Promise<void>;
|
|
523
|
-
/** 全量读取 topics(管理面板列表用,不做 recall 加权排序,按 endTime 倒序)*/
|
|
524
|
-
getAllTopics(): Promise<Topic[]>;
|
|
525
|
-
/** 删除单条 fact */
|
|
526
|
-
deleteFact(factId: string): Promise<void>;
|
|
527
|
-
/** 删除某会话下的全部消息(级联删除会话时使用)*/
|
|
528
|
-
deleteMessagesBySession(sessionId: string): Promise<void>;
|
|
529
|
-
/** 删除某会话下的全部 topics(级联删除会话时使用)*/
|
|
530
|
-
deleteTopicsBySession(sessionId: string): Promise<void>;
|
|
531
|
-
/** 各表行数统计(概览卡片用)*/
|
|
532
|
-
countAll(): Promise<{
|
|
533
|
-
sessions: number;
|
|
534
|
-
messages: number;
|
|
535
|
-
topics: number;
|
|
536
|
-
facts: number;
|
|
537
|
-
}>;
|
|
538
|
-
/**
|
|
539
|
-
* 按天聚合最近 days 天的活跃趋势(概览图表用)。
|
|
540
|
-
* 返回连续日期序列(含无数据的零值天),按本地日期分桶。
|
|
541
|
-
*/
|
|
542
|
-
trendDaily(days: number): Promise<{
|
|
543
|
-
date: string;
|
|
544
|
-
sessions: number;
|
|
545
|
-
messages: number;
|
|
546
|
-
facts: number;
|
|
547
|
-
}[]>;
|
|
548
|
-
addDocument(doc: Document): Promise<void>;
|
|
549
|
-
addChunks(chunks: Chunk[]): Promise<void>;
|
|
550
|
-
updateDocumentGraphFlag(docId: string, hasGraph: boolean): Promise<void>;
|
|
551
|
-
getDocument(docId: string): Promise<Document | null>;
|
|
552
|
-
/** 查找同域同 hash 的文档(去重用)*/
|
|
553
|
-
findDocumentByHash(contentHash: string, filter?: string): Promise<Document | null>;
|
|
554
|
-
/** 按域过滤返回 docId 列表(chunkRedundantIds=false 时用于 chunk 过滤)*/
|
|
555
|
-
getDocIdsByDomain(filter?: string): Promise<string[]>;
|
|
556
|
-
/** 文档级粗召回:对摘要向量做向量搜索,定位候选文档 */
|
|
557
|
-
searchDocuments(vector: number[], filter?: string, limit?: number): Promise<Array<Document & {
|
|
558
|
-
_distance: number;
|
|
559
|
-
}>>;
|
|
560
|
-
/** 知识片段混合检索(BM25 + 向量),失败回退纯向量 */
|
|
561
|
-
searchChunks(query: string, vector: number[], filter?: string, limit?: number): Promise<Chunk[]>;
|
|
562
|
-
deleteDocument(docId: string): Promise<void>;
|
|
563
|
-
deleteChunksByDoc(docId: string): Promise<void>;
|
|
564
|
-
/** 全量读取文档(管理面板用),按更新时间倒序 */
|
|
565
|
-
getAllDocuments(): Promise<Document[]>;
|
|
566
|
-
/** 知识库行数统计 */
|
|
567
|
-
countKnowledge(): Promise<{
|
|
568
|
-
documents: number;
|
|
569
|
-
chunks: number;
|
|
570
|
-
}>;
|
|
571
|
-
/**
|
|
572
|
-
* 根据 metadata 字段内容构建 SQL LIKE 过滤条件。
|
|
573
|
-
*
|
|
574
|
-
* metadata 以 JSON 字符串存储,此方法将键值对转换为 SQL LIKE 表达式,
|
|
575
|
-
* 可直接传给 searchMessages / hybridSearchTopics 的 filter 参数。
|
|
576
|
-
*
|
|
577
|
-
* 示例:buildMetadataFilter({ env: "prod", version: 2 })
|
|
578
|
-
* → `metadata LIKE '%"env":"prod"%' AND metadata LIKE '%"version":2%'`
|
|
579
|
-
*
|
|
580
|
-
* 注意:仅适合简单标量值(字符串、数字、布尔)的精确匹配。
|
|
581
|
-
* 复杂嵌套对象或含空格的 JSON 值可能无法可靠匹配。
|
|
582
|
-
*/
|
|
583
|
-
static buildMetadataFilter(conditions: Record<string, string | number | boolean>): string;
|
|
584
|
-
}
|
|
585
|
-
|
|
586
695
|
declare const DEFAULT_NODE_TYPES: readonly ["Person", "Group", "Organization", "Project", "Task", "Decision", "Plan", "Event", "Product", "Technology", "Data", "Document", "Topic", "Concept", "Preference", "Habit", "Goal", "Skill", "Attribute", "Value", "Status", "Time", "Location", "Resource", "Relationship"];
|
|
587
696
|
declare const DEFAULT_RELATION_TYPES: readonly ["is_a", "part_of", "belongs_to", "contains", "has_member", "mentioned_in", "refers_to", "same_as", "alias_of", "related_to", "associated_with", "uses", "creates", "updates", "buys", "owns", "consumes", "works_on", "prefers", "likes", "dislikes", "interested_in", "favorite", "plans", "decides", "habit_of", "tends_to", "avoids", "skilled_in", "learning", "knows", "friends_with", "married_to", "parent_of", "child_of", "lives_with", "depends_on", "built_with", "integrates_with", "deployed_on", "inputs", "outputs", "trained_on", "predicts", "happens_at", "started_at", "ended_at", "affects", "causes", "leads_to", "improves", "reduces", "assigned_to", "executed_by", "blocks", "completes", "describes", "explains", "references"];
|
|
588
697
|
type NodeType = (typeof DEFAULT_NODE_TYPES)[number];
|
|
@@ -591,4 +700,4 @@ type RelationType = (typeof DEFAULT_RELATION_TYPES)[number];
|
|
|
591
700
|
declare const KIND_CONVERSATION = "conversation";
|
|
592
701
|
declare const KIND_KNOWLEDGE = "knowledge";
|
|
593
702
|
|
|
594
|
-
export { type AddDocumentOptions, type BuildGraphMode, type Chunk, type ChunkHit, type ChunkPiece, type CompressOutput, type ContentPart, DEFAULT_NODE_TYPES, DEFAULT_RELATION_TYPES, type Document, type DomainIds, type Entity, type EntityMeta, type Fact, type FactLevel, KIND_CONVERSATION, KIND_KNOWLEDGE, type KnowledgeSearchOptions, type KnowledgeSearchResult, LanceService, type MemoryConfig, MemoryManager, type MessageType, type NodeType, type RawMessage, type Relation, type RelationType, type SearchMode, type SearchOptions, type SearchResult, type SearchScope, type Session, type SessionEntry, type SessionSearchOptions, type SessionView, type StoredMessage, type Topic, type UpdateChatOptions, type UpdateEntityOptions, type UpdateSessionOptions };
|
|
703
|
+
export { type AddDocumentOptions, type BuildGraphMode, type Chunk, type ChunkHit, type ChunkPiece, type CompressOutput, type ContentPart, DEFAULT_NODE_TYPES, DEFAULT_RELATION_TYPES, type Document, type DomainIds, type Entity, type EntityMeta, type Fact, type FactLevel, KIND_CONVERSATION, KIND_KNOWLEDGE, type KnowledgeSearchOptions, type KnowledgeSearchResult, LanceService, type MemoryConfig, MemoryManager, type MessageType, type NodeType, type PageParams, type Paginated, type RawMessage, type Relation, type RelationType, type SearchMode, type SearchOptions, type SearchResult, type SearchScope, type Session, type SessionEntry, type SessionSearchOptions, type SessionView, type StorageOptimizeResult, type StoredMessage, type Topic, type UpdateChatOptions, type UpdateEntityOptions, type UpdateSessionOptions };
|