@ppagent/memory 0.1.2 → 0.3.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/dist/index.d.ts CHANGED
@@ -305,7 +305,18 @@ interface KnowledgeSearchResult {
305
305
  }
306
306
 
307
307
  interface MemoryConfig {
308
+ /**
309
+ * 向量存储后端:
310
+ * - "auto"(默认):运行时探测 @lancedb/lancedb 原生绑定,可用则 lancedb,否则回退 sqlite
311
+ * (覆盖 Intel Mac / musl 等无预编译二进制的平台)。首次选定后写入数据目录 marker 固化,
312
+ * 避免环境变化导致静默换库(表现为「记忆丢失」)。
313
+ * - "lancedb" / "sqlite":显式指定。
314
+ * 注意:两个后端的数据文件互不相通,切换需自行迁移。
315
+ */
316
+ provider?: "auto" | "lancedb" | "sqlite";
308
317
  lancedbPath: string;
318
+ /** sqlite 后端的数据库文件路径(默认 lancedbPath 同级目录下的 memory.sqlite3) */
319
+ sqlitePath?: string;
309
320
  grafeoPath: string;
310
321
  embeddingBaseUrl: string;
311
322
  embeddingApiKey: string;
@@ -371,7 +382,17 @@ interface MemoryConfig {
371
382
  * 不阻塞启动;嵌入式单进程使用时建议保持开启,否则 LanceDB 版本目录会无限膨胀、启动越来越慢。
372
383
  */
373
384
  autoOptimizeOnInit?: boolean;
374
- /** 压实时保留多久内的历史版本(毫秒,默认 0 即仅保留当前版本)。*/
385
+ /**
386
+ * 运行期定期压实的间隔(毫秒,默认 6 小时;设为 0 或负数关闭定时任务)。
387
+ * 长驻服务不重启时版本仍会随写入累积,靠该定时任务周期性回收。
388
+ * 定时器已 unref,不会阻止进程退出;destroy() 会清除。
389
+ */
390
+ autoOptimizeIntervalMs?: number;
391
+ /**
392
+ * 压实时保留多久内的历史版本(毫秒,默认 0 即仅保留当前版本)。
393
+ * 注意:运行期定期压实会对该值强制施加 60 秒下限,避免误删仍被在途查询引用的版本;
394
+ * 启动时的那次压实无在途查询,按原值执行。
395
+ */
375
396
  optimizeVersionRetentionMs?: number;
376
397
  /** 启动时恢复各会话历史窗口的并发数(默认 8,旧行为为逐会话串行)。*/
377
398
  restoreConcurrency?: number;
@@ -379,7 +400,122 @@ interface MemoryConfig {
379
400
  interface ResolvedConfig extends Required<MemoryConfig> {
380
401
  }
381
402
 
382
- /** 单表压实结果(compaction + 历史版本清理)*/
403
+ /**
404
+ * 向量存储后端抽象层的类型定义。
405
+ *
406
+ * 设计原则:接口只表达「语义」(结果意味着什么),不表达「机制」(怎么算出来的)。
407
+ * - 混合检索(RRF 融合)、回退策略、业务重排等组合逻辑在共享域层 memory.store.ts 实现,
408
+ * provider 只需提供 vectorSearch / ftsSearch 两个检索原语,保证跨后端行为一致。
409
+ * - ANN、索引维护、存储压实等机制细节由各 provider 自行决定,接口仅以声明式
410
+ * IndexSpec 提示与 capabilities 能力声明的方式暴露。
411
+ * - 过滤条件为结构化对象(而非 SQL 字符串),各 provider 翻译为自己的方言,
412
+ * 从根上消除转义/注入问题。
413
+ */
414
+ type FilterCondition =
415
+ /** 等值匹配 */
416
+ {
417
+ op: "eq";
418
+ field: string;
419
+ value: string | number;
420
+ }
421
+ /** 数值大于 */
422
+ | {
423
+ op: "gt";
424
+ field: string;
425
+ value: number;
426
+ }
427
+ /** 数值大于等于 */
428
+ | {
429
+ op: "gte";
430
+ field: string;
431
+ value: number;
432
+ }
433
+ /** 字段值属于集合。values 为空数组表示「不匹配任何行」 */
434
+ | {
435
+ op: "in";
436
+ field: string;
437
+ values: string[];
438
+ }
439
+ /**
440
+ * 匹配序列化为 JSON 字符串的 metadata 列中的键值对。
441
+ * 语义等同旧 LanceService.buildMetadataFilter 的 LIKE '%"key":value%' 模式:
442
+ * 仅适合标量值精确匹配,嵌套对象/含特殊字符的值不保证可靠。
443
+ */
444
+ | {
445
+ op: "jsonContains";
446
+ field: string;
447
+ key: string;
448
+ value: string | number | boolean;
449
+ };
450
+ /** 多个条件为 AND 关系。空数组等同于不过滤。 */
451
+ type Filter = FilterCondition[];
452
+ type ColumnType =
453
+ /** UTF-8 文本 */
454
+ "text"
455
+ /** 32 位整数 */
456
+ | "int"
457
+ /** 64 位整数(毫秒时间戳等)。JS 侧统一以 number 读写 */
458
+ | "long"
459
+ /** 定长 float32 向量,维度由 TableDef.vectorDimension 决定 */
460
+ | "vector";
461
+ interface ColumnDef {
462
+ name: string;
463
+ type: ColumnType;
464
+ /** 默认 false。nullable 列用于 schema 演进的兼容(旧数据无此列) */
465
+ nullable?: boolean;
466
+ }
467
+ interface IndexSpec {
468
+ column: string;
469
+ /**
470
+ * - scalar:标量索引(btree 等价物),加速等值/范围过滤
471
+ * - fts:全文检索索引(BM25)
472
+ * - vector:向量检索加速提示。当前所有 provider 均为精确暴力扫描(ANN 暂不启用,
473
+ * 见 plans/vector-db-replacement-research.md 决议),该值仅作为将来启用 ANN 的声明位。
474
+ */
475
+ kind: "scalar" | "fts" | "vector";
476
+ }
477
+ interface TableDef {
478
+ name: string;
479
+ columns: ColumnDef[];
480
+ /** 有 vector 列时必填 */
481
+ vectorDimension?: number;
482
+ indexes: IndexSpec[];
483
+ }
484
+ interface OrderBySpec {
485
+ column: string;
486
+ ascending: boolean;
487
+ }
488
+ interface QueryOptions {
489
+ filter?: Filter;
490
+ orderBy?: OrderBySpec[];
491
+ limit?: number;
492
+ /** 只取指定列(性能优化,如 trendDaily 只读 created_at)。省略取全部列 */
493
+ select?: string[];
494
+ }
495
+ interface VectorSearchOptions {
496
+ filter?: Filter;
497
+ limit: number;
498
+ }
499
+ interface FtsSearchOptions {
500
+ /** 参与全文匹配的列(须已建 fts 索引) */
501
+ columns: string[];
502
+ filter?: Filter;
503
+ limit: number;
504
+ }
505
+ /** 通用行类型:列名 → 值。vector 列为 number[],long 列为 number */
506
+ type Row = Record<string, unknown>;
507
+ /**
508
+ * 向量检索结果附带 _distance(L2 平方距离,越小越相近)。
509
+ * 各 provider 必须保持相同度量(L2),依赖距离阈值的上层逻辑才能跨后端一致。
510
+ */
511
+ type ScoredRow = Row & {
512
+ _distance: number;
513
+ };
514
+ /** FTS 检索结果附带 _score(BM25 相关度,越大越相关;仅用于排序,绝对值跨后端无可比性) */
515
+ type FtsRow = Row & {
516
+ _score: number;
517
+ };
518
+ /** 单表压实结果。不同后端的语义映射:LanceDB=碎片合并+版本清理;SQLite=incremental vacuum 等 */
383
519
  interface StorageOptimizeResult {
384
520
  table: string;
385
521
  fragmentsRemoved: number;
@@ -388,133 +524,46 @@ interface StorageOptimizeResult {
388
524
  oldVersionsRemoved: number;
389
525
  bytesRemoved: number;
390
526
  }
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;
527
+ interface ProviderCapabilities {
528
+ /** 是否支持原生 FTS(BM25)。false 时域层混合检索自动降级为纯向量 */
529
+ fts: boolean;
530
+ /** 向量检索是否为 ANN 近似(false = 精确暴力)。当前所有 provider 均为 false */
531
+ ann: boolean;
532
+ /** optimize() 是否有实际效果(LanceDB 版本回收必需;SQLite 可选) */
533
+ optimize: boolean;
534
+ }
535
+ /**
536
+ * 向量存储后端需要实现的最小原语集合。
537
+ *
538
+ * 实现约定:
539
+ * - init 必须幂等:表已存在则打开并按 TableDef 补齐缺失的列(schema 演进)与索引;
540
+ * 不存在则创建。
541
+ * - 所有 filter 参数为结构化 Filter,provider 内部翻译为自己的方言并负责转义/参数化。
542
+ * - vectorSearch 使用 L2 距离,返回按 _distance 升序的前 limit 行。
543
+ * - ftsSearch 返回按 _score(BM25)降序的前 limit 行;查询词的分词由 provider 负责
544
+ * (中文场景 sqlite provider 使用 jieba;lancedb provider 使用 tantivy 内置分词)。
545
+ * - add/update/delete 需保证同一表内的派生结构(如 sqlite 的 FTS 影子表)事务一致。
546
+ */
547
+ interface VectorStoreProvider {
548
+ /** provider 标识,用于日志与数据目录 marker */
549
+ readonly kind: string;
550
+ init(tables: TableDef[]): Promise<void>;
551
+ add(table: string, rows: Row[]): Promise<void>;
552
+ update(table: string, values: Row, filter: Filter): Promise<void>;
553
+ deleteWhere(table: string, filter: Filter): Promise<void>;
554
+ query(table: string, opts?: QueryOptions): Promise<Row[]>;
555
+ vectorSearch(table: string, vector: number[], opts: VectorSearchOptions): Promise<ScoredRow[]>;
556
+ ftsSearch(table: string, query: string, opts: FtsSearchOptions): Promise<FtsRow[]>;
557
+ count(table: string, filter?: Filter): Promise<number>;
558
+ /** 存储压实与历史版本回收。retentionMs:保留多久内的历史版本(不支持版本概念的后端可忽略) */
559
+ optimize(retentionMs: number): Promise<StorageOptimizeResult[]>;
560
+ capabilities(): ProviderCapabilities;
561
+ close(): Promise<void>;
513
562
  }
514
563
 
515
564
  declare class MemoryManager {
516
565
  private readonly config;
517
- private readonly lance;
566
+ private readonly store;
518
567
  private readonly grafeo;
519
568
  private readonly embed;
520
569
  private readonly llm;
@@ -523,8 +572,12 @@ declare class MemoryManager {
523
572
  private readonly compressManager;
524
573
  private readonly knowledgeManager;
525
574
  private readonly sessionMap;
575
+ private optimizeTimer?;
576
+ private optimizeRunning;
526
577
  constructor(config: MemoryConfig);
527
578
  init(): Promise<void>;
579
+ /** 后台压实的统一入口:防重入(上一轮未结束则跳过),失败仅告警不影响服务。*/
580
+ private runBackgroundOptimize;
528
581
  /**
529
582
  * 手动触发存储压实与历史版本清理(init 后台会自动执行一次;上层维护任务也可调用)。
530
583
  * @param retentionMs 保留多久内的历史版本,默认取配置 optimizeVersionRetentionMs
@@ -553,7 +606,7 @@ declare class MemoryManager {
553
606
  */
554
607
  getFactsForContext(userId: string, chatId: string): Promise<string>;
555
608
  getHistoryWindow(sessionId: string): string;
556
- private buildLanceFilter;
609
+ private buildScopeFilter;
557
610
  private deserializeSession;
558
611
  private serializeSession;
559
612
  getRecentMessages(sessionId: string, limit: number): Promise<StoredMessage[]>;
@@ -692,6 +745,117 @@ declare class MemoryManager {
692
745
  destroy(): void;
693
746
  }
694
747
 
748
+ /**
749
+ * 记忆系统的存储域层:保持原 LanceService 的公开方法面,内部组合
750
+ * VectorStoreProvider 的通用原语实现。业务逻辑(混合检索融合、话题回退、
751
+ * recall 加权重排)全部在此层,各后端 provider 不感知。
752
+ */
753
+ declare class MemoryStore {
754
+ private readonly config;
755
+ private provider;
756
+ private readonly providerOverride?;
757
+ /** provider 省略时在 init() 阶段经 provider.resolver 自动探测创建(测试可显式注入) */
758
+ constructor(config: ResolvedConfig, provider?: VectorStoreProvider);
759
+ /** 当前后端 provider 标识(日志/诊断用) */
760
+ get providerKind(): string;
761
+ init(): Promise<void>;
762
+ close(): Promise<void>;
763
+ /**
764
+ * 存储压实(碎片合并 + 历史版本清理)。
765
+ * LanceDB 后端长期运行必须定期执行;SQLite 后端为可选的空间回收。
766
+ */
767
+ optimizeStorage(retentionMs?: number): Promise<StorageOptimizeResult[]>;
768
+ addMessages(messages: StoredMessage[]): Promise<void>;
769
+ getMessagesSince(sessionId: string, since: number, limit?: number): Promise<StoredMessage[]>;
770
+ getLatestMessages(sessionId: string, limit: number): Promise<StoredMessage[]>;
771
+ /** 取某会话的全部消息(按 createdAt 升序),供管理面板分页切片使用 */
772
+ getAllMessagesBySession(sessionId: string): Promise<StoredMessage[]>;
773
+ searchMessages(vector: number[], filter?: Filter, limit?: number): Promise<Array<StoredMessage & {
774
+ _distance: number;
775
+ }>>;
776
+ hybridSearchMessages(query: string, vector: number[], filter?: Filter, limit?: number): Promise<StoredMessage[]>;
777
+ hybridSearchTopics(query: string, vector: number[], filter?: Filter, limit?: number): Promise<Topic[]>;
778
+ /**
779
+ * 通用混合检索:FTS(BM25)与向量两路各取 limit*HYBRID_OVERFETCH 候选,RRF 融合。
780
+ * FTS 不可用(后端不支持或查询失败)时降级为纯向量。返回融合后的完整候选序列(未截断)。
781
+ */
782
+ private hybridSearch;
783
+ private keyColumnOf;
784
+ addTopic(topic: Topic): Promise<void>;
785
+ updateTopicRecallCount(summaryId: string, count: number): Promise<void>;
786
+ getRecentTopics(chatId: string, userId: string, n1: number, n2: number, n3: number): Promise<{
787
+ detail: Topic[];
788
+ summary: Topic[];
789
+ concise: Topic[];
790
+ }>;
791
+ /** 全量读取 topics(管理面板列表用,不做 recall 加权排序,按 endTime 倒序)*/
792
+ getAllTopics(): Promise<Topic[]>;
793
+ deleteTopicsBySession(sessionId: string): Promise<void>;
794
+ saveFact(fact: Fact): Promise<void>;
795
+ getAllFacts(): Promise<Fact[]>;
796
+ /** 删除单条 fact */
797
+ deleteFact(factId: string): Promise<void>;
798
+ getAllSessionIds(): Promise<string[]>;
799
+ insertSession(session: Session): Promise<void>;
800
+ upsertSession(session: Session): Promise<void>;
801
+ getAllSessions(): Promise<Session[]>;
802
+ deleteSession(sessionId: string): Promise<void>;
803
+ /** 删除某会话下的全部消息(级联删除会话时使用)*/
804
+ deleteMessagesBySession(sessionId: string): Promise<void>;
805
+ /** 各表行数统计(概览卡片用)*/
806
+ countAll(): Promise<{
807
+ sessions: number;
808
+ messages: number;
809
+ topics: number;
810
+ facts: number;
811
+ }>;
812
+ /**
813
+ * 按天聚合最近 days 天的活跃趋势(概览图表用)。
814
+ * 返回连续日期序列(含无数据的零值天),按本地日期分桶。
815
+ */
816
+ trendDaily(days: number): Promise<{
817
+ date: string;
818
+ sessions: number;
819
+ messages: number;
820
+ facts: number;
821
+ }[]>;
822
+ addDocument(doc: Document): Promise<void>;
823
+ addChunks(chunks: Chunk[]): Promise<void>;
824
+ updateDocumentGraphFlag(docId: string, hasGraph: boolean): Promise<void>;
825
+ getDocument(docId: string): Promise<Document | null>;
826
+ /** 查找同域同 hash 的文档(去重用)*/
827
+ findDocumentByHash(contentHash: string, filter?: Filter): Promise<Document | null>;
828
+ /** 按域过滤返回 docId 列表(chunkRedundantIds=false 时用于 chunk 过滤)*/
829
+ getDocIdsByDomain(filter?: Filter): Promise<string[]>;
830
+ /** 文档级粗召回:对摘要向量做向量搜索,定位候选文档 */
831
+ searchDocuments(vector: number[], filter?: Filter, limit?: number): Promise<Array<Document & {
832
+ _distance: number;
833
+ }>>;
834
+ /** 知识片段混合检索(BM25 + 向量),失败回退纯向量 */
835
+ searchChunks(query: string, vector: number[], filter?: Filter, limit?: number): Promise<Chunk[]>;
836
+ deleteDocument(docId: string): Promise<void>;
837
+ deleteChunksByDoc(docId: string): Promise<void>;
838
+ /** 全量读取文档(管理面板用),按更新时间倒序 */
839
+ getAllDocuments(): Promise<Document[]>;
840
+ /** 知识库行数统计 */
841
+ countKnowledge(): Promise<{
842
+ documents: number;
843
+ chunks: number;
844
+ }>;
845
+ /**
846
+ * 根据 metadata 字段内容构建结构化过滤条件。
847
+ *
848
+ * metadata 以 JSON 字符串存储,此方法将键值对转换为 jsonContains 条件,
849
+ * 可直接传给 searchMessages / hybridSearchTopics 的 filter 参数。
850
+ *
851
+ * 注意:仅适合简单标量值(字符串、数字、布尔)的精确匹配。
852
+ * 复杂嵌套对象或含空格的 JSON 值可能无法可靠匹配。
853
+ */
854
+ static buildMetadataFilter(conditions: Record<string, string | number | boolean>): Filter;
855
+ }
856
+
857
+ type ProviderKind = "lancedb" | "sqlite";
858
+
695
859
  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"];
696
860
  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"];
697
861
  type NodeType = (typeof DEFAULT_NODE_TYPES)[number];
@@ -700,4 +864,4 @@ type RelationType = (typeof DEFAULT_RELATION_TYPES)[number];
700
864
  declare const KIND_CONVERSATION = "conversation";
701
865
  declare const KIND_KNOWLEDGE = "knowledge";
702
866
 
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 };
867
+ 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, type Filter, type FilterCondition, KIND_CONVERSATION, KIND_KNOWLEDGE, type KnowledgeSearchOptions, type KnowledgeSearchResult, type MemoryConfig, MemoryManager, MemoryStore, type MessageType, type NodeType, type PageParams, type Paginated, type ProviderCapabilities, type ProviderKind, 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, type VectorStoreProvider };