怎样为查询引擎指定响应模式?
先说出你的答案
定义边界、关键机制、一个反例;P8题再补容量、失败与验证。
查看完整题解
参考回答
直接回答
常见入口是 index.as_query_engine(response_mode="compact"),或者先用 get_response_synthesizer 建合成器,再传给 RetrieverQueryEngine。它改变的是候选节点之后的处理。
讲清原理
compact 会尽量把证据拼在较少的提示里。refine 顺着片段更新已有答案。长材料的整体概括可实测 tree_summarize,看看合并层次是否能保住关键事实。
例子与易错点
示例明确设成 no_text,用同一个查询引擎取得来源节点,暂时跳过生成文字。排查“到底召回了什么”时,这种模式会直接一些。
from llama_index.core import Settings, VectorStoreIndex
from llama_index.core.embeddings import MockEmbedding
from llama_index.core.llms import MockLLM
from llama_index.core.schema import TextNode
Settings.tokenizer = str.split
index = VectorStoreIndex([TextNode(id_="manual", text="Use hand tools.")],
embed_model=MockEmbedding(embed_dim=4))
Settings.llm = MockLLM()
engine = index.as_query_engine(response_mode="no_text", llm=Settings.llm)
result = engine.query("Which tools?")
assert result.response == ""
assert [hit.node.node_id for hit in result.source_nodes] == ["manual"]
print("manual source returned without generated text")
和评分标准对照,你能独立回答到哪一步?
自评会安排下一次复习,不保存你的口述内容。
这道题,你掌握得怎么样?
掌握程度由你主动标记,阅读和收藏不会自动改变状态。