Files
nexus/wiki/concepts/上下文压缩.md

46 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "上下文压缩"
type: concept
tags: [ai, context-window, code-analysis, tool]
---
## 定义
将大型代码库或长文本压缩为结构化摘要,以适配 AI 上下文窗口限制,同时最大化有效信息密度的技术。
## 解决的问题
- AI 上下文窗口有限4K-200K tokens大型代码库超出限制
- 原始代码包含大量 boilerplate空行、注释、重复代码块
- 上下文窗口消耗 → 每次交互成本上升 → 速度下降
## 主要方法
### CodeWeaver 方案
将整个代码库编织为树形 Markdown
- 目录结构 → 树形标题
- 文件内容 → 代码块
- 保留语言标注
### 语义摘要方案
- LLM 提取关键函数/类/依赖关系
- 生成模块关系图
- 用自然语言描述系统行为
### 增量上下文方案
- 只将当前任务相关文件送入上下文
- 通过检索RAG从全代码库中召回相关片段
- 每次交互动态构建上下文
## 在 Vibe Coding 中的作用
[[vibe-coding经验收集]] 提及CodeWeaver 将"屎山代码"编织为树形 Markdown简化 AI 上下文注入,是 vibe coding 工程化的支撑工具之一。
## 与 RAG 的关系
- RAG从向量数据库检索相关文本片段
- 上下文压缩:将检索结果进一步提炼为高密度信息
- 两者结合RAG → 压缩 → AI 处理
## Aliases
- Context Window Management
- Code Summarization
- AI Context Optimization
- 代码压缩