| name | longer-memory |
| description | Persistent vector memory for Claude — save and semantically recall anything across sessions. Use this skill whenever the user says "nhớ", "lưu", "remember", "save", "ghi lại", or asks "trước tôi có nói gì về X?", "tìm lại thông tin về Y", "recall", "what did I say about". Also auto-trigger at the end of any conversation that contains important facts about the user, decisions made, or knowledge shared. Covers four memory types: user profile info, conversation highlights, knowledge/documents, and anything the user explicitly asks to save. ALWAYS use this skill when memory or recall is involved — even if the user just says "nhớ cái này".
|
Longer Memory Skill
Skill này dùng LanceDB để lưu trữ và tìm kiếm thông tin theo kiểu vector (semantic search).
Mọi memory đều tồn tại vĩnh viễn trong workspace folder, kể cả sau khi session kết thúc.
Cấu hình (Config)
Settings được lưu tại ~/.config/longer-memory/config.json — đặt một lần, dùng mãi.
Xem config hiện tại
python scripts/config.py --show
Thiết lập settings
python scripts/config.py --set embedding-model ollama
python scripts/config.py --set embedding-model sentence-transformers
python scripts/config.py --set embedding-model openai
python scripts/config.py --set ollama-url http://localhost:11434
python scripts/config.py --set ollama-model nomic-embed-text
python scripts/config.py --set openai-model text-embedding-3-small
export OPENAI_API_KEY=sk-...
python scripts/config.py --set db-path /your/custom/path/memory_db
python scripts/config.py --reset
Thứ tự ưu tiên (cao → thấp)
- CLI argument (
--ollama-url, --embedding-model, ...)
- Environment variable (
MEMORY_OLLAMA_URL, MEMORY_EMBEDDING_MODEL, ...)
~/.config/longer-memory/config.json
- Default built-in
Khi user nói "đổi sang Ollama" hoặc "set URL":
Chạy config.py --set với giá trị họ cung cấp, rồi config.py --show để xác nhận.
Nơi lưu DB
Mặc định: ~/.longer_memory_db/ (trong home directory của user)
Nếu user chỉ định đường dẫn khác: python scripts/config.py --set db-path /path/to/db
Embedding Models được hỗ trợ
Hỏi user khi chưa rõ, hoặc dùng sentence-transformers làm default:
| Model | Cách dùng | Ưu điểm |
|---|
sentence-transformers | Local, không cần gì thêm | Miễn phí, offline, nhanh |
ollama | Local server tự chạy | Tự chọn model, không tốn API |
openai | API cloud | Chất lượng cao nhất |
Ollama (local server)
Ollama cho phép chạy embedding model hoàn toàn trên máy, hỗ trợ nhiều model khác nhau.
Cài Ollama: https://ollama.com
Pull model: ollama pull nomic-embed-text
Chạy server: ollama serve (mặc định port 11434)
Các model Ollama phổ biến cho embedding:
nomic-embed-text — cân bằng tốt giữa tốc độ và chất lượng (khuyến nghị)
mxbai-embed-large — chất lượng cao hơn, nặng hơn
all-minilm — nhỏ gọn, nhanh nhất
Nếu user đang dùng Ollama với một URL khác (ví dụ server remote), hỏi họ URL cụ thể.
Các thao tác chính
1. Lưu memory mới
python scripts/save.py \
--text "Nội dung cần nhớ" \
--category "user_info|conversation|knowledge|document" \
--tags "tag1,tag2" \
--source "tên nguồn (tuỳ chọn)"
python scripts/save.py \
--text "Nội dung cần nhớ" \
--embedding-model ollama \
--ollama-url "http://localhost:11434" \
--ollama-model "nomic-embed-text"
python scripts/save.py \
--text "Nội dung cần nhớ" \
--embedding-model openai
2. Tìm kiếm semantic
python scripts/search.py --query "câu hỏi hoặc từ khoá" --top-k 5
python scripts/search.py \
--query "câu hỏi" \
--embedding-model ollama \
--ollama-url "http://localhost:11434" \
--ollama-model "nomic-embed-text"
3. Liệt kê tất cả memory
python scripts/list.py \
--category "user_info" \
--limit 20 \
--db-path "/path/to/db"
4. Xoá memory
python scripts/delete.py \
--id "memory-id" \
--db-path "/path/to/db"
5. Xem thống kê DB
python scripts/stats.py --db-path "/path/to/db"
Quy trình xử lý theo tình huống
Khi user nói "nhớ/lưu cái này":
- Xác định nội dung cần lưu (trích từ câu nói hoặc hỏi lại nếu mơ hồ)
- Phân loại category phù hợp
- Nếu chưa biết embedding model, hỏi user (hoặc dùng sentence-transformers làm default)
- Chạy
save.py
- Xác nhận đã lưu thành công với user
Khi user hỏi "tìm lại / recall":
- Xác định query từ câu hỏi của user
- Chạy
search.py với top-k = 5
- Trình bày kết quả tìm được rõ ràng, kèm category và ngày lưu
- Nếu không tìm thấy gì phù hợp, thông báo thẳng thắn
Tự động lưu cuối session:
Nếu trong conversation có các thông tin quan trọng như:
- Thông tin cá nhân user (tên, công ty, sở thích, thói quen)
- Quyết định hoặc kết luận đã được đưa ra
- Kiến thức kỹ thuật hoặc domain-specific được chia sẻ
→ Chủ động hỏi: "Cuộc trò chuyện này có vài điểm quan trọng — bạn muốn mình lưu lại không?"
→ Nếu user đồng ý, tóm tắt các điểm chính và lưu.
Cài đặt dependencies
pip install lancedb sentence-transformers --break-system-packages
pip install lancedb openai --break-system-packages
Categories
| Category | Dùng khi |
|---|
user_info | Thông tin cá nhân, sở thích, thói quen của user |
conversation | Tóm tắt hoặc highlight của một cuộc trò chuyện |
knowledge | Kiến thức, khái niệm, tài liệu được chia sẻ |
document | Nội dung từ file hoặc URL được lưu lại |
Lưu ý quan trọng
- Luôn in ra ID của memory vừa lưu để user có thể tham chiếu sau
- Khi tìm kiếm, hiển thị cả score (độ tương đồng) để user biết mức độ liên quan
- Nếu DB chưa tồn tại, scripts sẽ tự tạo
- Nếu gặp lỗi import, chạy lệnh cài đặt phía trên trước