@ppagent/memory 0.1.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.
@@ -0,0 +1,594 @@
1
+ type MessageType = "text" | "image" | "file";
2
+ type FactLevel = "user" | "chat";
3
+ type SearchMode = "fast" | "auto" | "all";
4
+ type SearchScope = "session" | "chat" | "user" | "all";
5
+ /**
6
+ * 多模态消息的单个内容块,与 OpenAI content part 对齐
7
+ */
8
+ interface ContentPart {
9
+ type: "text" | "image_url" | "file_url";
10
+ /** type 为 "text" 时的文本内容 */
11
+ text?: string;
12
+ /** type 为 "image_url" 时的图片信息 */
13
+ image_url?: {
14
+ url: string;
15
+ };
16
+ /** type 为 "file_url" 时的文件信息 */
17
+ file_url?: {
18
+ url: string;
19
+ name?: string;
20
+ };
21
+ }
22
+ interface RawMessage {
23
+ messageId?: string;
24
+ talkerId?: string;
25
+ chatId?: string;
26
+ userId?: string;
27
+ sessionId?: string;
28
+ type?: MessageType;
29
+ /**
30
+ * 纯文本内容,用于 embedding 和全文检索(必填)。
31
+ * 图片/文件消息填写 alt text,如 "[图片]"。
32
+ */
33
+ content: string;
34
+ /**
35
+ * 多模态结构化内容(可选)。纯文本消息无需传。
36
+ * 序列化后存入 LanceDB 的 parts 字段。
37
+ */
38
+ parts?: ContentPart[];
39
+ usage?: number;
40
+ metadata?: Record<string, unknown>;
41
+ createdAt?: number;
42
+ }
43
+ interface StoredMessage {
44
+ messageId: string;
45
+ talkerId: string;
46
+ chatId: string;
47
+ userId: string;
48
+ sessionId: string;
49
+ type: MessageType;
50
+ /** 纯文本,用于搜索和 embedding */
51
+ content: string;
52
+ /** JSON.stringify(ContentPart[]),纯文本消息为 "[]" */
53
+ parts: string;
54
+ usage: number;
55
+ metadata: string;
56
+ vector: number[];
57
+ createdAt: number;
58
+ }
59
+ interface Topic {
60
+ summaryId: string;
61
+ sessionId: string;
62
+ userId: string;
63
+ chatId: string;
64
+ /** 压缩时自动生成的主题标题(一句话),存量数据可能为空串 */
65
+ title: string;
66
+ detail: string;
67
+ summary: string;
68
+ concise: string;
69
+ startTime: number;
70
+ endTime: number;
71
+ createdAt: number;
72
+ updatedAt: number;
73
+ recallCount: number;
74
+ vector: number[];
75
+ }
76
+ interface Fact {
77
+ factId: string;
78
+ level: FactLevel;
79
+ chatId: string;
80
+ sessionId: string;
81
+ userId: string;
82
+ content: string;
83
+ createdAt: number;
84
+ }
85
+ interface EntityMeta {
86
+ messageId?: string;
87
+ sessionId: string;
88
+ userId: string;
89
+ chatId: string;
90
+ messageTime?: number;
91
+ [key: string]: unknown;
92
+ }
93
+ interface Entity {
94
+ name: string;
95
+ type: string;
96
+ meta: EntityMeta;
97
+ }
98
+ interface Relation {
99
+ from: string;
100
+ to: string;
101
+ type: string;
102
+ happenedAt?: number;
103
+ meta: EntityMeta;
104
+ }
105
+ interface SearchOptions {
106
+ query: string;
107
+ scope?: SearchScope;
108
+ scopeId?: string;
109
+ mode?: SearchMode;
110
+ limit?: number;
111
+ }
112
+ interface SearchResult {
113
+ type: "message" | "topic" | "entity" | "relation";
114
+ content: string;
115
+ score: number;
116
+ meta: Record<string, unknown>;
117
+ }
118
+ interface Session {
119
+ sessionId: string;
120
+ chatId: string;
121
+ userId: string;
122
+ title: string;
123
+ metadata: string;
124
+ createdAt: number;
125
+ updatedAt: number;
126
+ }
127
+ interface SessionView {
128
+ sessionId: string;
129
+ chatId: string;
130
+ userId: string;
131
+ title: string;
132
+ metadata: Record<string, unknown>;
133
+ createdAt: number;
134
+ updatedAt: number;
135
+ }
136
+ interface UpdateSessionOptions {
137
+ title?: string;
138
+ metadata?: Record<string, unknown>;
139
+ }
140
+ interface SessionSearchOptions {
141
+ title?: string;
142
+ userId?: string;
143
+ chatId?: string;
144
+ limit?: number;
145
+ }
146
+ interface UpdateChatOptions {
147
+ userId?: string;
148
+ chatId?: string;
149
+ sessionId?: string;
150
+ sessionTitle?: string;
151
+ sessionMetadata?: Record<string, unknown>;
152
+ }
153
+ interface UpdateEntityOptions {
154
+ sessionId?: string;
155
+ chatId?: string;
156
+ userId?: string;
157
+ }
158
+ interface CompressOutput {
159
+ /** 自动生成的主题标题(一句话) */
160
+ title: string;
161
+ detail: string;
162
+ summary: string;
163
+ concise: string;
164
+ entities: Array<{
165
+ name: string;
166
+ type: string;
167
+ meta: Record<string, unknown>;
168
+ }>;
169
+ relations: Array<{
170
+ from: string;
171
+ to: string;
172
+ type: string;
173
+ happenedAt?: number;
174
+ meta: Record<string, unknown>;
175
+ }>;
176
+ }
177
+ interface SessionEntry {
178
+ messages: StoredMessage[];
179
+ totalTokens: number;
180
+ ids: {
181
+ chatId: string;
182
+ userId: string;
183
+ };
184
+ }
185
+ /** 是否为文档构建知识图谱:true/false 显式控制,"auto" 由内置 LLM 判定 */
186
+ type BuildGraphMode = boolean | "auto";
187
+ /** 文档的领域标记(与会话记忆一致,仅作元信息存储,检索时才决定过滤范围)*/
188
+ interface DomainIds {
189
+ userId: string;
190
+ chatId: string;
191
+ sessionId: string;
192
+ }
193
+ /** 文档(一行一个上传文件)*/
194
+ interface Document {
195
+ docId: string;
196
+ userId: string;
197
+ chatId: string;
198
+ sessionId: string;
199
+ title: string;
200
+ sourceName: string;
201
+ /** 完整 markdown 原文 */
202
+ fullContent: string;
203
+ /** 内容哈希,用于去重 */
204
+ contentHash: string;
205
+ /** LLM 生成的文档级摘要 */
206
+ summary: string;
207
+ /** summary 的 embedding,供文档级粗召回(schema 中列名为 vector)*/
208
+ summaryVector: number[];
209
+ chunkCount: number;
210
+ hasGraph: boolean;
211
+ metadata: Record<string, unknown>;
212
+ createdAt: number;
213
+ updatedAt: number;
214
+ }
215
+ /** 知识片段(一行一个切块,带向量)*/
216
+ interface Chunk {
217
+ chunkId: string;
218
+ docId: string;
219
+ userId: string;
220
+ chatId: string;
221
+ sessionId: string;
222
+ content: string;
223
+ /** content(含 headingPath 前缀)的 embedding */
224
+ vector: number[];
225
+ /** markdown 标题层级路径,如 "安装 / 环境要求 / Node 版本" */
226
+ headingPath: string;
227
+ /** 片段在文档中的顺序号 */
228
+ ordinal: number;
229
+ tokens: number;
230
+ metadata: Record<string, unknown>;
231
+ createdAt: number;
232
+ }
233
+ /** 切块器输出(未带向量/id)*/
234
+ interface ChunkPiece {
235
+ content: string;
236
+ headingPath: string;
237
+ ordinal: number;
238
+ tokens: number;
239
+ }
240
+ interface AddDocumentOptions {
241
+ /** markdown 原文(必填)*/
242
+ content: string;
243
+ userId?: string;
244
+ chatId?: string;
245
+ sessionId?: string;
246
+ /** 不传则从首个 H1 / sourceName 推断 */
247
+ title?: string;
248
+ sourceName?: string;
249
+ metadata?: Record<string, unknown>;
250
+ /** 默认取 config.buildGraphDefault(默认 "auto")*/
251
+ buildGraph?: BuildGraphMode;
252
+ /** 默认 false:document 落库即返回;true 则等切块落库,文档可检索 */
253
+ wait?: boolean;
254
+ /** 默认 false:true 时在 wait 的基础上额外等待知识图谱构建完成 */
255
+ waitGraph?: boolean;
256
+ }
257
+ interface KnowledgeSearchOptions {
258
+ query: string;
259
+ scope?: SearchScope;
260
+ scopeId?: string;
261
+ mode?: SearchMode;
262
+ /** 片段返回上限,默认 config.knowledgeTopK */
263
+ limit?: number;
264
+ }
265
+ /** 命中的知识片段 */
266
+ interface ChunkHit {
267
+ chunkId: string;
268
+ docId: string;
269
+ content: string;
270
+ headingPath: string;
271
+ score: number;
272
+ }
273
+ interface KnowledgeSearchResult {
274
+ /** 命中的知识片段(按相关度倒序)*/
275
+ chunks: ChunkHit[];
276
+ /** 本次涉及的文档及其命中片段数 */
277
+ documents: Array<{
278
+ docId: string;
279
+ title: string;
280
+ matchedChunkCount: number;
281
+ }>;
282
+ /** 图谱命中:mode=auto 命中高置信后扩展 / mode=all 时并发返回 */
283
+ graphHits: SearchResult[];
284
+ }
285
+
286
+ interface MemoryConfig {
287
+ lancedbPath: string;
288
+ grafeoPath: string;
289
+ embeddingBaseUrl: string;
290
+ embeddingApiKey: string;
291
+ embeddingModel: string;
292
+ embeddingDimension: number;
293
+ llmBaseUrl: string;
294
+ llmApiKey: string;
295
+ llmModel: string;
296
+ /** LLM / embedding HTTP 请求超时(毫秒,默认 30000)。超时即中止并按重试策略处理。*/
297
+ httpTimeoutMs?: number;
298
+ /** LLM / embedding 请求失败(网络错误/超时/5xx/429)时的最大重试次数(默认 2,即最多请求 3 次)。*/
299
+ httpMaxRetries?: number;
300
+ /** embedding 单次请求最多包含的文本条数,超出自动分批(默认 20)。*/
301
+ embeddingBatchSize?: number;
302
+ /** embedding 批次并发数(默认 2)。*/
303
+ embeddingConcurrency?: number;
304
+ sessionTokenLimit?: number;
305
+ historyWindowTokenLimit?: number;
306
+ topicRatio?: [number, number, number];
307
+ detailMaxTokens?: number;
308
+ summaryMaxTokens?: number;
309
+ conciseMaxTokens?: number;
310
+ maxConcurrentCompressions?: number;
311
+ entitySimilarityThreshold?: number;
312
+ defaultSearchLimit?: number;
313
+ /** 每次召回相当于多少毫秒的时间权重加成(默认 3_600_000 即 1 小时)*/
314
+ recallBoostMs?: number;
315
+ /** 切块策略,目前仅 "markdown-heading"(默认)*/
316
+ chunkStrategy?: "markdown-heading";
317
+ /** 单块 token 上限;标题块过长时按此二次切分(默认 800)*/
318
+ chunkMaxTokens?: number;
319
+ /** 块间重叠 token;标题切块默认不重叠(默认 0)*/
320
+ chunkOverlap?: number;
321
+ /** searchKnowledge 默认片段返回数(默认 8)*/
322
+ knowledgeTopK?: number;
323
+ /** 文档级粗召回候选文档数;设为 0 关闭粗召回直接全片段搜索(默认 5)*/
324
+ docCoarseTopK?: number;
325
+ /** addDocument 未传 buildGraph 时的默认值(默认 "auto")*/
326
+ buildGraphDefault?: BuildGraphMode;
327
+ /**
328
+ * chunks 是否冗余存 userId/chatId/sessionId 三个 id:
329
+ * - true(默认):chunks 行内冗余三 id,按域过滤一步到位
330
+ * - false:chunks 不冗余(存空串),过滤时先按域查 documents 取 docId 再过滤 chunks
331
+ */
332
+ chunkRedundantIds?: boolean;
333
+ /**
334
+ * auto 模式下,片段命中达到该相似度才触发知识图谱多跳扩展(默认 0.78)。
335
+ * 取值范围 0~1,cosine 相似度。
336
+ */
337
+ knowledgeGraphTriggerScore?: number;
338
+ /** 知识图谱实体向量检索返回的实体数(多跳扩展的候选锚点池,默认 10)*/
339
+ knowledgeGraphEntityTopK?: number;
340
+ /** 从候选实体中取前 K 个作为多跳扩展锚点(默认 3)*/
341
+ knowledgeGraphAnchorTopK?: number;
342
+ /** 每个锚点实体一跳扩展的最大关系数(默认 10)*/
343
+ knowledgeGraphHopLimit?: number;
344
+ /** 文档图谱构建时并发抽取片段数(默认 2)*/
345
+ graphExtractConcurrency?: number;
346
+ /** waitGraph=true 时等待图谱构建的整体超时(毫秒,默认 120000)*/
347
+ graphBuildTimeoutMs?: number;
348
+ }
349
+ interface ResolvedConfig extends Required<MemoryConfig> {
350
+ }
351
+
352
+ declare class MemoryManager {
353
+ private readonly config;
354
+ private readonly lance;
355
+ private readonly grafeo;
356
+ private readonly embed;
357
+ private readonly llm;
358
+ private readonly sessionCache;
359
+ private readonly factCache;
360
+ private readonly compressManager;
361
+ private readonly knowledgeManager;
362
+ private readonly sessionMap;
363
+ constructor(config: MemoryConfig);
364
+ init(): Promise<void>;
365
+ private restoreFromStorage;
366
+ updateChat(messages: RawMessage[], opts?: UpdateChatOptions): Promise<void>;
367
+ flushChat(sessionId?: string, opts?: {
368
+ wait?: boolean;
369
+ waitGraph?: boolean;
370
+ }): Promise<void>;
371
+ updateFacts(content: string, level: FactLevel, userId: string, chatId: string, sessionId?: string): Promise<void>;
372
+ updateEntity(entities: Entity[], relations: Relation[], context?: UpdateEntityOptions): Promise<void>;
373
+ search(opts: SearchOptions): Promise<SearchResult[]>;
374
+ ask(opts: SearchOptions & {
375
+ maxChars?: number;
376
+ includeKnowledge?: boolean;
377
+ }): Promise<string>;
378
+ getFacts(level: FactLevel, id: string): Promise<string>;
379
+ /**
380
+ * 按层级语义取「上下文相关」的 facts 拼接字符串。
381
+ *
382
+ * scope 是层级包含的:user ⊃ chat ⊃ session。因此在某个 chat/session 上下文中,
383
+ * 既要看到该 chat 级的 facts,也要看到所属 user 级的 facts。
384
+ * 返回 user 级(userId) ∪ chat 级(chatId),按时间正序拼接。
385
+ */
386
+ getFactsForContext(userId: string, chatId: string): Promise<string>;
387
+ getHistoryWindow(sessionId: string): string;
388
+ private buildLanceFilter;
389
+ private deserializeSession;
390
+ private serializeSession;
391
+ getRecentMessages(sessionId: string, limit: number): Promise<StoredMessage[]>;
392
+ getSession(sessionId: string): SessionView | null;
393
+ getSessionsByUserId(userId: string, opts?: {
394
+ limit?: number;
395
+ }): SessionView[];
396
+ getSessionsByChatId(chatId: string, opts?: {
397
+ limit?: number;
398
+ }): SessionView[];
399
+ searchSessions(opts: SessionSearchOptions): SessionView[];
400
+ updateSession(sessionId: string, opts: UpdateSessionOptions): Promise<SessionView | null>;
401
+ deleteSession(sessionId: string): Promise<boolean>;
402
+ /** 概览统计:各类记忆数据的总量 */
403
+ stats(): Promise<{
404
+ sessions: number;
405
+ messages: number;
406
+ topics: number;
407
+ facts: number;
408
+ entities: number;
409
+ relations: number;
410
+ documents: number;
411
+ chunks: number;
412
+ }>;
413
+ /** 按天聚合最近 days 天的活跃趋势(概览图表用,含零值天)。days 默认 30,范围 1~365。 */
414
+ trend(days?: number): Promise<{
415
+ date: string;
416
+ sessions: number;
417
+ messages: number;
418
+ facts: number;
419
+ }[]>;
420
+ /** 列出会话,可选按 userId / chatId 过滤,按更新时间倒序 */
421
+ listSessions(filter?: {
422
+ userId?: string;
423
+ chatId?: string;
424
+ }): SessionView[];
425
+ /** 列出会话内的消息(按时间正序)*/
426
+ listMessages(sessionId: string, limit?: number): Promise<StoredMessage[]>;
427
+ /** 列出主题/摘要,可选按 sessionId / userId / chatId 过滤 */
428
+ listTopics(filter?: {
429
+ sessionId?: string;
430
+ userId?: string;
431
+ chatId?: string;
432
+ }): Promise<Topic[]>;
433
+ /**
434
+ * 列出事实,按创建时间倒序。过滤遵循 scope 层级包含语义:
435
+ * - 按 chatId 过滤时,除该 chat 级 facts 外,还包含该 chat 所属 user 的 user 级 facts
436
+ * (user 级对其下所有 chat/session 生效)。
437
+ * - 按 userId 过滤时,返回该 user 名下全部 facts(两级都带 userId)。
438
+ * - level 过滤在层级过滤之后再叠加。
439
+ */
440
+ listFacts(filter?: {
441
+ level?: FactLevel;
442
+ userId?: string;
443
+ chatId?: string;
444
+ }): Fact[];
445
+ /** 由 chatId 反查所属 userId:优先用会话表映射,兜底用 chat 级 fact 自身。 */
446
+ private resolveChatOwner;
447
+ /** 手动新增一条事实 */
448
+ addFact(content: string, level: FactLevel, userId: string, chatId: string, sessionId?: string): Promise<void>;
449
+ /** 删除单条事实,返回是否命中 */
450
+ deleteFact(factId: string): Promise<boolean>;
451
+ /** 列出全部实体(知识图谱节点)*/
452
+ listEntities(): Promise<Entity[]>;
453
+ /** 列出全部关系(知识图谱边)*/
454
+ listRelations(): Promise<Relation[]>;
455
+ /** 摄入一个文档(markdown)。document 落库即返回,切块/embedding/图谱后台执行(wait=true 可等待)。*/
456
+ addDocument(opts: AddDocumentOptions): Promise<{
457
+ docId: string;
458
+ }>;
459
+ /** 检索知识库片段,返回命中片段、涉及文档与图谱命中。*/
460
+ searchKnowledge(opts: KnowledgeSearchOptions): Promise<KnowledgeSearchResult>;
461
+ /** 获取文档(含原文)。*/
462
+ getDocument(docId: string): Promise<Document | null>;
463
+ /** 删除文档(级联删除其片段与知识图谱痕迹),返回是否命中。*/
464
+ deleteDocument(docId: string): Promise<boolean>;
465
+ /** 列出文档,可选按 userId / chatId / sessionId 过滤,按更新时间倒序。*/
466
+ listDocuments(filter?: {
467
+ userId?: string;
468
+ chatId?: string;
469
+ sessionId?: string;
470
+ }): Promise<Document[]>;
471
+ destroy(): void;
472
+ }
473
+
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
+ 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
+ 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
+ type NodeType = (typeof DEFAULT_NODE_TYPES)[number];
589
+ type RelationType = (typeof DEFAULT_RELATION_TYPES)[number];
590
+ /** 图谱节点/边的来源标记:会话记忆 vs 知识库,用于隔离两类图谱 */
591
+ declare const KIND_CONVERSATION = "conversation";
592
+ declare const KIND_KNOWLEDGE = "knowledge";
593
+
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 };