Skip to content

feat(memory): tantivy-jieba TantivyStore (CC-Adv alternative)#161

Open
Bahtya wants to merge 10 commits intomainfrom
feat/tantivy-memory-adv
Open

feat(memory): tantivy-jieba TantivyStore (CC-Adv alternative)#161
Bahtya wants to merge 10 commits intomainfrom
feat/tantivy-memory-adv

Conversation

@Bahtya
Copy link
Copy Markdown
Owner

@Bahtya Bahtya commented Apr 23, 2026

Summary

Alternative implementation of the LanceDB → tantivy-jieba migration, preserving HotStore + TieredStore.

Key differences from PR #160 (CC-Main):

See issue #159 for full independent analysis and issue #158 for RFC discussion.

[CC-Adv]

Test plan

  • Store/recall/delete/clear operations
  • Chinese full-text search (jieba tokenization)
  • Mixed Chinese-English search
  • Category and confidence filtering pushed down to tantivy
  • Capacity limits
  • Persistence across restart
  • Security scanning (prompt injection rejection)
  • TieredMemoryStore integration (L1+L2 dedup, promotion)
  • CI passes

Bahtya

Replace vector-search-based WarmStore with full-text BM25 search using
tantivy + tantivy-jieba. This eliminates the LanceDB dependency,
embedding generation overhead, and the CPU spike issue (#139).

Key changes:
- New TantivyStore: BM25 scoring, jieba CJK tokenization, persistent index
- Remove WarmStore (LanceDB), embedding.rs (HashEmbedding), arrow deps
- Replace MemoryError::LanceDb with MemoryError::SearchEngine
- Update MemoryConfig: tantivy_index_path replaces warm_store_path
- Simplify memory tools: remove EmbeddingGenerator parameter
- Update gateway.rs: remove embedding from learning pipeline

[CC-Adv]

Bahtya
Bahtya added 4 commits April 24, 2026 04:56
- Upgrade tantivy 0.24 → 0.26, tantivy-jieba 0.14 → 0.19
- Use i64 timestamp fields (micros) instead of tantivy DateTime
- Use RangeQuery::new() with Bound terms instead of new_f64_bounds
- Fix writer mutability (use `mut` for MutexGuard)
- Remove embedding field from MemoryEntry and MemoryQuery
- Add reader to TantivyStore for consistent reads
- Add concurrent writes test

Bahtya
Bahtya added 5 commits April 24, 2026 05:10
- Chain LowerCaser filter to JiebaTokenizer for case-insensitive BM25
- Fix upsert capacity check: skip limit when overwriting existing entry
- Fix test_combined_text_and_category_search: expect 2 results not 1

Bahtya
@Bahtya
Copy link
Copy Markdown
Owner Author

Bahtya commented Apr 24, 2026

[CC-Adv] PR #161 价值总结 — 双层架构备选方案

PR #160 已合并,PR #162 是当前待合并的 clean 版本。本 PR(#161)作为备选参考保留,提供 PR #162 中缺失的以下功能:

PR #161 额外价值

1. Critical Category Pinning

PR #162 删除了 HotStore,导致 MemoryCategory::Critical 的 pinning 语义丢失。在 PR #161 的 HotStore L1 中,Critical 条目被 exempt from LRU eviction:

// hot_store.rs — Critical entries never evicted
if entry.category == MemoryCategory::Critical {
    continue; // skip LRU eviction
}

2. LRU 淘汰策略

HotStore 使用 lru crate 提供基于 access_count 的淘汰。当达到容量上限时,最久未访问的非 Critical 条目被淘汰。PR #162 仅使用 tantivy num_docs() 硬上限,无智能淘汰。

3. 零延迟热数据缓存

HotStore 维护内存中的 HashMap<String, MemoryEntry>,recall 操作无需 tantivy index 查询。对于高频访问的热点记忆,延迟从 ~1ms(tantivy mmap)降至 ~0.01ms(HashMap lookup)。

4. TieredStore 透明分层

TieredMemoryStore 提供 L1 (HotStore) + L2 (TantivyStore) 的透明组合:

  • store() → 同时写 L1 和 L2
  • recall() → 先查 L1,miss 则查 L2 并回填 L1
  • search() → 合并 L1 和 L2 结果,去重并排序

5. 现有数据兼容

PR #161 保留了 hot_store.rs,可以读取现有 hot.jsonl 数据文件。PR #162 删除了 HotStore,现有用户升级后 hot.jsonl 数据无法迁移。

何时需要 PR #161

  • 生产环境 benchmark 显示 tantivy 冷启动延迟不可接受
  • 需要保护关键记忆不被淘汰(Critical pinning)
  • 需要高频记忆访问的零延迟命中
  • 现有用户数据迁移需求

分支状态

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant