固定时效性
节点后处理模块。
LLM重排序 #
基类:EventBaseNodePostprocessor
基于大语言模型的重新排序器。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
top_n
|
int
|
返回前 N 个节点。 |
required |
choice_select_prompt
|
BasePromptTemplate
|
选项选择提示。 |
required |
choice_batch_size
|
int
|
选项选择的分批大小。 |
required |
llm
|
大语言模型
|
用于重新排序的大语言模型。 |
required |
workflows/handler.py 中的源代码llama_index/core/postprocessor/llm_rerank.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
结构化LLM重排序 #
基类:EventBaseNodePostprocessor
基于结构化LLM的重排序器。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
top_n
|
int
|
返回前 N 个节点。 |
required |
choice_select_prompt
|
BasePromptTemplate
|
选项选择提示。 |
required |
choice_batch_size
|
int
|
选项选择的分批大小。 |
required |
llm
|
大语言模型
|
用于重新排序的大语言模型。 |
required |
workflows/handler.py 中的源代码llama_index/core/postprocessor/structured_llm_rerank.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
相关文档 #
基类:EventBaseModel
模型选择的文档排名。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
document_number
|
int
|
在提供的列表中的文档编号 |
required |
relevance
|
int
|
文档与给定查询的相关性评分(1-10分)- 基于文档内容 |
required |
workflows/handler.py 中的源代码llama_index/core/postprocessor/structured_llm_rerank.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
元数据替换后处理器 #
基类:EventBaseNodePostprocessor
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
target_metadata_key
|
str
|
用于替换节点内容的目标元数据键。 |
required |
workflows/handler.py 中的源代码llama_index/core/postprocessor/metadata_replacement.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
自动前后节点后处理器 #
基类:EventBaseNodePostprocessor
上一个/下一个节点后处理器。
允许用户根据节点的前后关系,从文档存储中获取更多节点。
注意:与 PrevNextPostprocessor 的区别在于 它会推断前进/后退方向。
注意:这是一个测试版功能。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
docstore
|
BaseDocumentStore
|
文档存储。 |
required |
num_nodes
|
int
|
要返回的节点数量(默认值:1) |
1
|
infer_prev_next_tmpl
|
str
|
用于推理的模板。 必需字段为 {context_str} 和 {query_str}。 |
"The current context information is provided. \nA question is also provided. \nYou are a retrieval agent deciding whether to search the document store for additional prior context or future context. \nGiven the context and question, return PREVIOUS or NEXT or NONE. \nExamples: \n\nContext: Describes the author's experience at Y Combinator.Question: What did the author do after his time at Y Combinator? \nAnswer: NEXT \n\nContext: Describes the author's experience at Y Combinator.Question: What did the author do before his time at Y Combinator? \nAnswer: PREVIOUS \n\nContext: Describe the author's experience at Y Combinator.Question: What did the author do at Y Combinator? \nAnswer: NONE \n\nContext: {context_str}\nQuestion: {query_str}\nAnswer: "
|
llm
|
Annotated[大语言模型, SerializeAsAny] | None
|
|
None
|
refine_prev_next_tmpl
|
str
|
|
'The current context information is provided. \nA question is also provided. \nAn existing answer is also provided.\nYou are a retrieval agent deciding whether to search the document store for additional prior context or future context. \nGiven the context, question, and previous answer, return PREVIOUS or NEXT or NONE.\nExamples: \n\nContext: {context_msg}\nQuestion: {query_str}\nExisting Answer: {existing_answer}\nAnswer: '
|
verbose
|
bool
|
|
False
|
response_mode
|
ResponseMode
|
|
<ResponseMode.COMPACT: 'compact'>
|
workflows/handler.py 中的源代码llama_index/core/postprocessor/node.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
关键词节点后处理器 #
基类:EventBaseNodePostprocessor
基于关键词的节点处理器。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
required_keywords
|
List[str]
|
内置可变序列。 如果未提供参数,构造函数将创建一个新的空列表。 如果指定了参数,则它必须是一个可迭代对象。 |
<dynamic>
|
exclude_keywords
|
List[str]
|
内置可变序列。 如果未提供参数,构造函数将创建一个新的空列表。 如果指定了参数,则它必须是一个可迭代对象。 |
<dynamic>
|
lang
|
str
|
|
'en'
|
workflows/handler.py 中的源代码llama_index/core/postprocessor/node.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
长上下文重排序 #
基类:EventBaseNodePostprocessor
模型难以获取扩展上下文中心的重要细节。一项研究 (https://arxiv.org/abs/2307.03172) 发现,最佳 性能通常出现在关键数据位于 输入上下文开头或结尾时。此外, 随着输入上下文长度增加,性能显著下降,即使 在专为长上下文设计的模型中也是如此。
workflows/handler.py 中的源代码llama_index/core/postprocessor/node.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | |
上一个下一个节点后处理器 #
基类:EventBaseNodePostprocessor
上一个/下一个节点后处理器。
允许用户根据节点之间的关系,从文档存储中获取额外的节点。
注意:这是一个测试版功能。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
docstore
|
BaseDocumentStore
|
文档存储。 |
required |
num_nodes
|
int
|
要返回的节点数量(默认值:1) |
1
|
mode
|
str
|
后处理器的模式。 可以是 "previous"、"next" 或 "both"。 |
'next'
|
workflows/handler.py 中的源代码llama_index/core/postprocessor/node.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
相似性后处理器 #
基类:EventBaseNodePostprocessor
基于相似度的节点处理器。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
similarity_cutoff
|
float
|
|
0.0
|
workflows/handler.py 中的源代码llama_index/core/postprocessor/node.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
嵌入时效性后处理器 #
基类:EventBaseNodePostprocessor
嵌入时效性后处理器。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
embed_model
|
BaseEmbedding
|
|
<dynamic>
|
date_key
|
str
|
|
'date'
|
similarity_cutoff
|
float
|
|
0.7
|
query_embedding_tmpl
|
str
|
|
'The current document is provided.\n----------------\n{context_str}\n----------------\nGiven the document, we wish to find documents that contain \nsimilar context. Note that these documents are older than the current document, meaning that certain details may be changed. \nHowever, the high-level context should be similar.\n'
|
workflows/handler.py 中的源代码llama_index/core/postprocessor/node_recency.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
固定时效性后处理器 #
基类:EventBaseNodePostprocessor
固定时效性后处理器。
该后处理器按日期顺序执行以下步骤对节点进行排序。
假设 date_key 对应于元数据中的日期字段。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
top_k
|
int
|
|
1
|
date_key
|
str
|
|
'date'
|
workflows/handler.py 中的源代码llama_index/core/postprocessor/node_recency.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
时间加权后处理器 #
基类:EventBaseNodePostprocessor
时间加权后处理器。
根据最近性对一组节点进行重新排序。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
time_decay
|
float
|
|
0.99
|
last_accessed_key
|
str
|
|
'__last_accessed__'
|
time_access_refresh
|
bool
|
|
True
|
now
|
float | None
|
|
None
|
top_k
|
int
|
|
1
|
workflows/handler.py 中的源代码llama_index/core/postprocessor/node_recency.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
句子嵌入优化器 #
基类:EventBaseNodePostprocessor
根据查询优化文本块,通过缩短输入文本。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
percentile_cutoff
|
float | None
|
用于前k个句子的百分位数截断值。 |
required |
threshold_cutoff
|
float | None
|
每个句子使用的相似度阈值截断值。 |
required |
context_before
|
int | None
|
在检索句子之前用于提供更多上下文的句子数量 |
required |
context_after
|
int | None
|
检索句子后用于进一步上下文的句子数量 |
required |
workflows/handler.py 中的源代码llama_index/core/postprocessor/optimizer.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
NERPII节点后处理器 #
基类:EventBaseNodePostprocessor
NER PII 节点处理器。
使用一个HF transformers模型。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
pii_node_info_key
|
str
|
|
'__pii_node_info__'
|
workflows/handler.py 中的源代码llama_index/core/postprocessor/pii.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
mask_pii #
mask_pii(ner: Callable, text: str) -> Tuple[str, Dict]
在文本中屏蔽个人身份信息。
workflows/handler.py 中的源代码llama_index/core/postprocessor/pii.py
112 113 114 115 116 117 118 119 120 121 | |
PII节点后处理器 #
基类:EventBaseNodePostprocessor
PII节点处理器。
注意:这是一个测试版功能,API可能会发生变化。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
llm
|
大语言模型
|
用于预测的本地LLM。 |
required |
pii_str_tmpl
|
str
|
|
'The current context information is provided. \nA task is also provided to mask the PII within the context. \nReturn the text, with all PII masked out, and a mapping of the original PII to the masked PII. \nReturn the output of the task in JSON. \nContext:\nHello Zhang Wei, I am John. Your AnyCompany Financial Services, LLC credit card account 1111-0000-1111-0008 has a minimum payment of $24.53 that is due by July 31st. Based on your autopay settings, we will withdraw your payment. Task: Mask out the PII, replace each PII with a tag, and return the text. Return the mapping in JSON. \nOutput: \nHello [NAME1], I am [NAME2]. Your AnyCompany Financial Services, LLC credit card account [CREDIT_CARD_NUMBER] has a minimum payment of $24.53 that is due by [DATE_TIME]. Based on your autopay settings, we will withdraw your payment. Output Mapping:\n{{"NAME1": "Zhang Wei", "NAME2": "John", "CREDIT_CARD_NUMBER": "1111-0000-1111-0008", "DATE_TIME": "July 31st"}}\nContext:\n{context_str}\nTask: {query_str}\nOutput: \n'
|
pii_node_info_key
|
str
|
|
'__pii_node_info__'
|
workflows/handler.py 中的源代码llama_index/core/postprocessor/pii.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
mask_pii #
mask_pii(text: str) -> Tuple[str, Dict]
在文本中屏蔽个人身份信息。
workflows/handler.py 中的源代码llama_index/core/postprocessor/pii.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
SentenceTransformer重排序器 #
基类:EventBaseNodePostprocessor
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
model
|
str
|
句子转换器模型名称。 |
required |
top_n
|
int
|
按分数排序返回的节点数量。 |
required |
device
|
str
|
用于句子转换器的设备。 |
'cpu'
|
keep_retrieval_score
|
bool
|
是否在元数据中保留检索分数。 |
False
|
trust_remote_code
|
bool
|
是否信任远程代码。 |
False
|
workflows/handler.py 中的源代码llama_index/core/postprocessor/sbert_rerank.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
选项: 成员:- FixedRecencyPostprocessor