Embedding recency
Node PostProcessor module.
LLMRerank #
Bases: BaseNodePostprocessor
LLM-based reranker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
top_n
|
int
|
Top N nodes to return. |
required |
choice_select_prompt
|
BasePromptTemplate
|
Choice select prompt. |
required |
choice_batch_size
|
int
|
Batch size for choice select. |
required |
llm
|
LLM
|
The LLM to rerank with. |
required |
Source code in 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 | |
StructuredLLMRerank #
Bases: BaseNodePostprocessor
Structured LLM-based reranker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
top_n
|
int
|
Top N nodes to return. |
required |
choice_select_prompt
|
BasePromptTemplate
|
Choice select prompt. |
required |
choice_batch_size
|
int
|
Batch size for choice select. |
required |
llm
|
LLM
|
The LLM to rerank with. |
required |
Source code in 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 | |
DocumentWithRelevance #
Bases: BaseModel
Document rankings as selected by model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document_number
|
int
|
The number of the document within the provided list |
required |
relevance
|
int
|
Relevance score from 1-10 of the document to the given query - based on the document content |
required |
Source code in llama_index/core/postprocessor/structured_llm_rerank.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
MetadataReplacementPostProcessor #
Bases: BaseNodePostprocessor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_metadata_key
|
str
|
Target metadata key to replace node content with. |
required |
Source code in 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 | |
AutoPrevNextNodePostprocessor #
Bases: BaseNodePostprocessor
Previous/Next Node post-processor.
Allows users to fetch additional nodes from the document store, based on the prev/next relationships of the nodes.
NOTE: difference with PrevNextPostprocessor is that this infers forward/backwards direction.
NOTE: this is a beta feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docstore
|
BaseDocumentStore
|
The document store. |
required |
num_nodes
|
int
|
The number of nodes to return (default: 1) |
1
|
infer_prev_next_tmpl
|
str
|
The template to use for inference. Required fields are {context_str} and {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[LLM, 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'>
|
Source code in 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 | |
KeywordNodePostprocessor #
Bases: BaseNodePostprocessor
Keyword-based Node processor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
required_keywords
|
List[str]
|
Built-in mutable sequence. If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified. |
<dynamic>
|
exclude_keywords
|
List[str]
|
Built-in mutable sequence. If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified. |
<dynamic>
|
lang
|
str
|
|
'en'
|
Source code in 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 | |
LongContextReorder #
Bases: BaseNodePostprocessor
Models struggle to access significant details found in the center of extended contexts. A study (https://arxiv.org/abs/2307.03172) observed that the best performance typically arises when crucial data is positioned at the start or conclusion of the input context. Additionally, as the input context lengthens, performance drops notably, even in models designed for long contexts.".
Source code in 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 | |
PrevNextNodePostprocessor #
Bases: BaseNodePostprocessor
Previous/Next Node post-processor.
Allows users to fetch additional nodes from the document store, based on the relationships of the nodes.
NOTE: this is a beta feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docstore
|
BaseDocumentStore
|
The document store. |
required |
num_nodes
|
int
|
The number of nodes to return (default: 1) |
1
|
mode
|
str
|
The mode of the post-processor. Can be "previous", "next", or "both. |
'next'
|
Source code in 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 | |
SimilarityPostprocessor #
Bases: BaseNodePostprocessor
Similarity-based Node processor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
similarity_cutoff
|
float
|
|
0.0
|
Source code in 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 | |
EmbeddingRecencyPostprocessor #
Bases: BaseNodePostprocessor
Embedding Recency post-processor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
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'
|
Source code in 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 | |
FixedRecencyPostprocessor #
Bases: BaseNodePostprocessor
Fixed Recency post-processor.
This post-processor does the following steps orders nodes by date.
Assumes the date_key corresponds to a date field in the metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
top_k
|
int
|
|
1
|
date_key
|
str
|
|
'date'
|
Source code in 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 | |
TimeWeightedPostprocessor #
Bases: BaseNodePostprocessor
Time-weighted post-processor.
Reranks a set of nodes based on their recency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_decay
|
float
|
|
0.99
|
last_accessed_key
|
str
|
|
'__last_accessed__'
|
time_access_refresh
|
bool
|
|
True
|
now
|
float | None
|
|
None
|
top_k
|
int
|
|
1
|
Source code in 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 | |
SentenceEmbeddingOptimizer #
Bases: BaseNodePostprocessor
Optimization of a text chunk given the query by shortening the input text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
percentile_cutoff
|
float | None
|
Percentile cutoff for the top k sentences to use. |
required |
threshold_cutoff
|
float | None
|
Threshold cutoff for similarity for each sentence to use. |
required |
context_before
|
int | None
|
Number of sentences before retrieved sentence for further context |
required |
context_after
|
int | None
|
Number of sentences after retrieved sentence for further context |
required |
Source code in 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 | |
NERPIINodePostprocessor #
Bases: BaseNodePostprocessor
NER PII Node processor.
Uses a HF transformers model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pii_node_info_key
|
str
|
|
'__pii_node_info__'
|
Source code in 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]
Mask PII in text.
Source code in llama_index/core/postprocessor/pii.py
112 113 114 115 116 117 118 119 120 121 | |
PIINodePostprocessor #
Bases: BaseNodePostprocessor
PII Node processor.
NOTE: this is a beta feature, the API might change.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm
|
LLM
|
The local LLM to use for prediction. |
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__'
|
Source code in 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]
Mask PII in text.
Source code in llama_index/core/postprocessor/pii.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
SentenceTransformerRerank #
Bases: BaseNodePostprocessor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Sentence transformer model name. |
required |
top_n
|
int
|
Number of nodes to return sorted by score. |
required |
device
|
str
|
Device to use for sentence transformer. |
'cpu'
|
keep_retrieval_score
|
bool
|
Whether to keep the retrieval score in metadata. |
False
|
trust_remote_code
|
bool
|
Whether to trust remote code. |
False
|
Source code in 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 | |
options: members: - EmbeddingRecencyPostprocessor