Theme / v3.9.0

MemPalace

本地優先的 AI 記憶宮殿

指令詳解

mempalace search

在 Palace 中搜索記憶,使用語義與圖譜加權找到相關 Drawers。

import CodeBlock from ‘../../../components/CodeBlock.astro’; import CopyButton from ‘../../../components/CopyButton.tsx’;

mempalace search

在 Palace 中搜索記憶,使用語意與圖譜加權找到相關 Drawers。

指令

<CodeBlock code={‘mempalace search [query] [options]’} language=“bash”> <CopyButton code={‘mempalace search’} />

選項

選項 描述 預設值
-q, –query 搜索查詢
-n, –limit 顯示結果數量 10
-w, –wing 限定 Wing 所有 Wings
-r, –room 限定 Room 所有 Rooms
-t, –tags 按標籤過濾(逗號分隔)
–type 按類型過濾(reference/observation/view)
–format 輸出格式(table/json/yaml/markdown) table
–no-graph 禁用圖譜加權 false
–freshness 啟用新近性加權 true

範例

基本搜索

# 搜索「API 設計」相關記憶
mempalace search --query "API 設計"

Wing: d:/Repo/myproject
  Room: api-design (3 Drawers)
    [observation] API 認證機制設計
    [reference] RESTful API 最佳實踐
    [observation] API 版本管理策略

  Room: architecture (1 Drawer)
    [observation] API 網關架構設計

Results: 4 (Precision: 0.92, Recall: 0.88)
Latency: 215ms

限定 Wing 與 Room

# 在特定 Wing 與 Room 中搜索
mempalace search --query "PostgreSQL" \
  --wing "d:/Repo/myproject" \
  --room "database-schema"

Results: 2
  [observation] 使用 PostgreSQL 處理關聯數據
  [reference] PostgreSQL JSONB 最佳實踐

按標籤或類型過濾

# 查詢標籤為「models」的記憶
mempalace search --query "模型能力" --tags "models"

# 只查詢 Reference Drawers
mempalace search --query "PostgreSQL" --type reference

# 多標籤過濾(所有標籤都須符合)
mempalace search --query "性能" --tags "models,benchmark"

輸出格式

# 以 JSON 格式輸出
mempalace search --query "API" --limit 20 --format json

# 以 YAML 格式輸出
mempalace search --query "API" --format yaml

# 以 Markdown 格式輸出
mempalace search --query "API" --format markdown

搜索結果解釋

基本輸出格式:

Wing: wing-name
  Room: room-name (X Drawers)
    [type] Drawer Title
      Sources: file:lines (若為 Observation)
      Tags: tag1,tag2
      Score: 0.942 (綜合分數)

Wing: total wings
Rooms: total rooms
Drawers: total drawers
Precision: 0.XX (相關性比例)
Recall: 0.XX (覆蓋比例)
Latency: Xms

綜合分數計算

綜合分數由三個權重組成:

Score = (Match Score * 0.5) + (Graph Score * 0.3) + (Freshness Score * 0.2)
分數組成 權重 說明
Match Score 0.5 語義匹配度(Embeddings 相似度)
Graph Score 0.3 圖譜關聯權重(相關 Drawers 分數增加)
Freshness Score 0.2 新近性權重(近期的 Drawers 略高)

禁用圖譜或新近性加權

# 禁用圖譜加權(純語義匹配)
mempalace search --query "API" --no-graph

# 禁用新近性加權(不偏向近期的 Drawers)
mempalace search --query "API" --freshness=false

多語言搜索

# 除非特別指定,搜索查詢預設使用 Palace 的 default_language
# 範例:若 Palace 預設為 zh-TW,則以下查詢會匹配中文記憶
mempalace search --query "API 設計"

# 在多語言 Palace 中指定語言
mempalace search --query "API design" --language "en-US"

搜索效能

目標指標

  • Precision(相關性):≥ 0.90
  • Recall(覆蓋率):≥ 0.85
  • Latency(響應時間):≤ 250ms

您可以在 Palace 根目錄檢視搜索統計:

mempalace search --stats

Search Statistics (Last 30 Days):
  Total Queries: 125
  Avg Precision: 0.91 (Goal: ≥0.90) ✅
  Avg Recall: 0.87 (Goal: ≥0.85) ✅
  Avg Latency: 215ms (Goal: ≤250ms) ✅

Top Queries (by Frequency):
1. "API 設計" - 12 queries
2. "PostgreSQL" - 8 queries
3. "模型能力" - 6 queries

別名與捷徑

# 捷徑:-q 代用 --query
mempalace search -q "API"

# 捷徑:數字代用 --limit
mempalace search -q "API" 50  # limit 50

捷徑:-w 代用 --wing
mempalace search -q "API" -w "d:/Repo/myproject"

相關指令

  • mempalace view - 檢視 Drawer 內容
  • mempalace list - 列出 Palace 結構
  • mempalace graph - 檢視知識圖譜

v3.9.0:Search 會優先重用健康的 live Hub

從 v3.9.0 起,如果同一個 Palace 已有健康的 Hub,CLI mempalace search 會優先把查詢 forward 給 Hub,避免每個 CLI process 再載入一份大型 vector index。

這個轉送保留原本的 filters、ranking、authentication 與 configuration negotiation;Hub 不健康或不適用時仍有安全 fallback。因此一般使用者不需要新增旗標,主要差異是資源拓撲變了。

Raw similarity 與有效排序分數

v3.9.0 也把兩個概念分得更清楚:公開 similarity 是 raw vector score;closet boost 等因素影響的是 effective ranking。看到 similarity 較高,不代表它一定排第一,因為最後 ranking 還可能綜合其他訊號。

多代理同時搜尋

Hub read 現在可以並行;mutation 仍維持 exclusive。多個 agent 同時查同一個 Palace 時,不再因單一 HTTP dispatch lock 被全部串成序列。