上下文引擎
上下文引擎透過三種機制增強你的 AI 互動:對話壓縮、跨 profile 上下文共享,以及本地 RAG(檢索增強生成)。
當對話超過 token 閾值時,Claudex 使用 LLM 對較舊的訊息進行摘要,保留最近的訊息完整。
[context.compression]enabled = truethreshold_tokens = 50000 # 總 token 數超過此值時壓縮keep_recent = 10 # 始終保留最後 N 條訊息profile = "openrouter" # 重用某個 profile 的 base_url + api_keymodel = "qwen/qwen-2.5-7b-instruct" # 覆寫模型(選用)- 轉發請求前,Claudex 估算總 token 數
- 若 token 數超過
threshold_tokens,超出keep_recent的較舊訊息會被替換為摘要 - 摘要由設定的本地 LLM 生成
- 壓縮後的對話再轉發至提供商
跨 Profile 共享
Section titled “跨 Profile 共享”在同一工作階段中跨不同提供商 profile 共享上下文。
[context.sharing]enabled = truemax_context_size = 2000 # 從其他 profile 注入的最大 token 數這在任務中途切換提供商時很有用,來自先前互動的相關上下文會自動包含進來。
本地 RAG
Section titled “本地 RAG”索引本地程式碼和文件以進行檢索增強生成。相關程式碼片段會自動注入請求中。
[context.rag]enabled = trueindex_paths = ["./src", "./docs"] # 要索引的目錄profile = "openrouter" # 重用某個 profile 的 base_url + api_keymodel = "openai/text-embedding-3-small" # 嵌入模型chunk_size = 512 # 文字區塊大小top_k = 5 # 要注入的結果數量- 啟動時,Claudex 使用嵌入模型為
index_paths中的檔案建立索引 - 對於每個請求,使用者訊息會被嵌入並與索引比對
- 最相關的前 k 個區塊作為額外上下文注入請求
- 提供商收到關於你程式碼庫更豐富的上下文