面试题库
共 328 题,当前筛选 1 题。
课程全部30 天从前端工程师到 Agent 工程师5 天提示词工程零基础Claude 高效使用:从对话到 Claude CodeCodex 与 OpenAI Agents SDK 高效使用7 天 MCP:把工具接进任何 Agent7 天 Agent Skills:把经验做成可复用能力5 天上下文工程14 天 RAG:从检索到可信回答14 天用 Agent 搭一条 AI 短剧生产线
标签
全部#retrieval1#reliability9#streaming7#agent-loop4#cost4#framework-design4#tool-calling4#context-engineering3#llm-basics3#model-routing3#sse3#api-design2
还有 35 个标签收起标签
#architecture2#deployment2#error-handling2#observability2#prompt-engineering2#agent-basics1#communication1#compression1#context1#debugging1#docker1#engineering-tradeoffs1#event-driven1#forking1#idempotency1#interview-prep1#latency1#memory1#mobile1#nodejs1#persistence1#prompt1#prompt-injection1#protocol1#rag1#react1#sampling1#security1#service-architecture1#session-management1#system-prompt1#tool-design1#tool-permissions1#tools1#ux1
30 天从前端工程师到 Agent 工程师
D6 消息、上下文工程与压缩、会话存储/恢复/分叉(dg M06/M08/M09/M10)
上下文工程和 RAG 检索是什么关系?只做 RAG 不做上下文管理会出什么问题?How do context engineering and RAG relate, and what breaks if you do RAG without context management?
国内高频海外高频深入#context-engineering#rag#retrieval分析过程 · 先想清楚再作答
- 题眼在「关系」。把两者说成并列的两种技术是最常见的失分答法——正确的框架是包含关系:上下文工程是「决定这次请求里放什么」,RAG 是它的一种供给手段,负责「从外部捞该放进去的东西」。
- 拆开看职责就清楚了:RAG 解决的是「信息不在模型参数里、也不在当前对话里」,靠检索把它取回来;上下文工程解决的是「取回来的东西、加上历史、加上工具定义,一共放不放得下、该按什么优先级放」。前者管来源,后者管预算。
- 所以只做 RAG 不做上下文管理会出三类问题,最好按这个顺序说。第一是挤占:检索回来的文档动辄几千 token,直接拼进去把对话历史挤没了,模型记得住资料却忘了用户三句话前说过什么。第二是干扰:召回条数调大看着安全,实际上不相关的片段会稀释模型注意力,准确率不升反降。第三是成本:检索结果每一轮都重发,一段两千 token 的资料聊十轮就付了十次。
- 给出正确的组合姿势:先给历史和检索结果各划一条预算线,检索结果只保留 top-k 且不跨轮重复注入,历史超线就压缩,两条线加起来必须留出输出空间。这套「分账」的说法比笼统的「要平衡」有说服力得多。
- 可以预期的追问:检索结果该放在系统提示词里还是当成一条 user 消息?答放在靠近当前问题的位置通常效果更好,而且要标注来源便于模型区分「资料」和「用户说的话」;顺带说清它是一次性上下文,不该被写进长期会话历史里反复重发。
How to reason about it · think before answering
- The hinge word is 'relate'. Treating them as two parallel techniques is the standard weak answer — the right frame is containment: context engineering decides what goes into this request, and RAG is one supply mechanism that fetches what should go in.
- Separate the responsibilities and it becomes obvious: RAG solves 'the information is neither in the weights nor in this conversation' by retrieving it; context engineering solves 'the retrieved chunks plus the history plus the tool definitions all have to fit, in some priority order'. One owns sourcing, the other owns budget.
- So RAG without context management breaks in three ways, best delivered in this order. Crowding: retrieved documents run to thousands of tokens and squeeze out the conversation, so the model knows the manual but forgot what the user said three turns ago. Interference: raising top-k feels safe but irrelevant chunks dilute attention and accuracy drops instead of rising. Cost: retrieved text is resent every turn, so a 2k-token passage costs ten times over ten turns.
- Give the correct combination: budget history and retrieval separately, keep retrieval to top-k without re-injecting the same chunks every turn, compress history when it crosses its line, and make sure both lines together still leave room for output. This 'separate budgets' framing lands much better than a vague 'you need to balance them'.
- Expect the follow-up on placement: putting retrieved context near the current question usually works better, and it should be labeled with its source so the model can tell reference material from what the user actually said. Note too that it is single-turn context and should not be written into the persisted history and resent forever.
答题要点
- 不是并列关系而是包含关系:上下文工程决定这次请求放什么,RAG 是给它供货的一种手段,负责把不在模型和对话里的信息检索回来
- 只做 RAG 会挤占历史:几千 token 的检索结果把对话挤没,模型记得住资料却忘了用户刚说的话
- 召回条数越大越准是错觉:不相关片段会稀释注意力,准确率反而下降,应控制 top-k
- 检索结果每轮重发会持续计费,属于一次性上下文,不该写进持久化历史反复重发
- 正确姿势是给历史和检索各划一条预算线,历史超线就压缩,两条线之外还要留出输出空间
Key points
- They are not parallel: context engineering decides what enters the request, and RAG is one supply mechanism for information that is neither in the weights nor in the conversation
- RAG alone crowds out history — multi-thousand-token retrievals evict the conversation, so the model knows the docs but forgot the user's last request
- A bigger top-k is not safer: irrelevant chunks dilute attention and accuracy drops, so cap retrieval
- Retrieved text is single-turn context; persisting it into the history means paying for it on every subsequent turn
- Budget history and retrieval on separate lines, compress history when it crosses its line, and leave room for the output on top of both