Html
节点解析器。
HTML节点解析器 #
基类:EventNodeParser
HTML节点解析器。
使用自定义HTML分割逻辑将文档分割为节点。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
include_metadata
|
bool
|
是否在节点中包含元数据 |
required |
include_prev_next_rel
|
bool
|
是否包含上一页/下一页关系 |
required |
tags
|
List[str]
|
用于提取文本的HTML标签。 |
['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'li', 'b', 'i', 'u', 'section']
|
workflows/handler.py 中的源代码llama_index/core/node_parser/file/html.py
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 | |
class_name
classmethod
#
class_name() -> str
获取类名。
workflows/handler.py 中的源代码llama_index/core/node_parser/file/html.py
51 52 53 54 | |
get_nodes_from_node #
从文档中获取节点。
workflows/handler.py 中的源代码llama_index/core/node_parser/file/html.py
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 | |
JSON节点解析器 #
基类:EventNodeParser
JSON节点解析器。
使用自定义 JSON 拆分逻辑将文档拆分为节点。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
include_metadata
|
bool
|
是否在节点中包含元数据 |
required |
include_prev_next_rel
|
bool
|
是否包含上一页/下一页关系 |
required |
workflows/handler.py 中的源代码llama_index/core/node_parser/file/json.py
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 105 106 107 | |
class_name
classmethod
#
class_name() -> str
获取类名。
workflows/handler.py 中的源代码llama_index/core/node_parser/file/json.py
40 41 42 43 | |
get_nodes_from_node #
从文档中获取节点。
workflows/handler.py 中的源代码llama_index/core/node_parser/file/json.py
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 | |
Markdown节点解析器 #
基类:EventNodeParser
Markdown 节点解析器。
使用基于Markdown标题的分割逻辑将文档分割为节点。 每个节点包含其文本内容以及指向它的标题路径。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
include_metadata
|
bool
|
是否在节点中包含元数据 |
required |
include_prev_next_rel
|
bool
|
是否包含上一页/下一页关系 |
required |
header_path_separator
|
str
|
用于章节标题路径元数据的分隔符字符 |
'/'
|
workflows/handler.py 中的源代码llama_index/core/node_parser/file/markdown.py
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 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 | |
get_nodes_from_node #
通过按标题分割从文档中获取节点。
workflows/handler.py 中的源代码llama_index/core/node_parser/file/markdown.py
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 | |
简单文件节点解析器 #
基类:EventNodeParser
简单文件节点解析器。
根据文件类型自动将加载的文档拆分为节点 基于文件类型自动检测要使用的节点解析器
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
include_metadata
|
bool
|
是否在节点中包含元数据 |
required |
include_prev_next_rel
|
bool
|
是否包含上一页/下一页关系 |
required |
workflows/handler.py 中的源代码llama_index/core/node_parser/file/simple_file.py
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 | |
class_name
classmethod
#
class_name() -> str
获取类名。
workflows/handler.py 中的源代码llama_index/core/node_parser/file/simple_file.py
50 51 52 53 | |
MetadataAwareTextSplitter #
基类:EventTextSplitter
workflows/handler.py 中的源代码llama_index/core/node_parser/interface.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
NodeParser #
Bases: TransformComponent, ABC
节点解析器的基础接口。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
include_metadata
|
bool
|
分割时是否考虑元数据。 |
True
|
include_prev_next_rel
|
bool
|
包含上一个/下一个节点关系。 |
True
|
callback_manager
|
CallbackManager
|
|
<llama_index.core.callbacks.base.CallbackManager object at 0x7f82e1235730>
|
id_func
|
Annotated[Callable, FieldInfo, BeforeValidator, WithJsonSchema, WithJsonSchema, PlainSerializer] | None
|
生成节点ID的函数。 |
None
|
workflows/handler.py 中的源代码llama_index/core/node_parser/interface.py
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 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 | |
get_nodes_from_documents #
get_nodes_from_documents(documents: Sequence[文档], show_progress: bool = False, **kwargs: Any) -> List[BaseNode]
将文档解析为节点。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
documents
|
Sequence[文档]
|
待解析的文档 |
required |
show_progress
|
bool
|
是否显示进度条 |
False
|
workflows/handler.py 中的源代码llama_index/core/node_parser/interface.py
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 | |
TextSplitter #
基类:EventNodeParser
workflows/handler.py 中的源代码llama_index/core/node_parser/interface.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
分层节点解析器 #
基类:EventNodeParser
分层节点解析器。
使用节点解析器将文档分割成递归层次结构的节点。
注意:这将返回一个扁平列表中的节点层次结构,其中父节点(例如使用较大的分块大小)与每个父节点下的子节点(例如使用较小的分块大小)之间会存在重叠。
例如,这可能返回一个节点列表,如:
- 顶级节点列表,块大小为2048
- 二级节点列表,其中每个节点都是顶级节点的子节点, 块大小 512
- 三级节点列表,其中每个节点都是二级节点的子节点, 分块大小 128
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
chunk_sizes
|
List[int] | None
|
分割文档时使用的块大小,按层级顺序排列。 |
None
|
node_parser_ids
|
List[str]
|
用于在拆分文档时使用的节点解析器ID列表,按层级顺序排列(第一个ID用于第一级,依此类推)。 |
<dynamic>
|
node_parser_map
|
Dict[str, NodeParser]
|
节点解析器标识到节点解析器的映射。 |
required |
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/hierarchical.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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
get_nodes_from_documents #
get_nodes_from_documents(documents: Sequence[文档], show_progress: bool = False, **kwargs: Any) -> List[BaseNode]
将文档解析为节点。
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/hierarchical.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
Markdown元素节点解析器 #
基类:EventBaseElementNodeParser
Markdown 元素节点解析器。
将Markdown文档分割为文本节点和索引节点,分别对应嵌入对象(例如表格)。
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/markdown_element.py
11 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 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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 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 | |
get_nodes_from_node #
从节点获取节点。
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/markdown_element.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
aget_nodes_from_node
async
#
从节点获取节点。
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/markdown_element.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
extract_html_tables #
extract_html_tables(elements: List[Element]) -> List[Element]
从文本中提取HTML表格。
返回:
| 类型 | 描述 |
|---|---|
List[Element]
|
列表[元素]:按表格文本元素分割的文本元素 |
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/markdown_element.py
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 | |
extract_elements #
extract_elements(text: str, node_id: Optional[str] = None, table_filters: Optional[List[Callable]] = None, **kwargs: Any) -> List[Element]
从文本中提取元素。
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/markdown_element.py
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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
filter_table #
filter_table(table_element: Any) -> bool
筛选表格。
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/markdown_element.py
288 289 290 291 292 293 | |
非结构化元素节点解析器 #
基类:EventBaseElementNodeParser
非结构化元素节点解析器。
将文档分割为文本节点和对应于嵌入对象(例如表格)的索引节点。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
partitioning_parameters
|
Dict[str, Any] | None
|
表示分区过程参数的额外字典。 |
{}
|
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/unstructured_element.py
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 | |
get_nodes_from_node #
从节点获取节点。
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/unstructured_element.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
aget_nodes_from_node
async
#
从节点获取节点。
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/unstructured_element.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
extract_elements #
extract_elements(text: str, table_filters: Optional[List[Callable]] = None, **kwargs: Any) -> List[Element]
从文本中提取元素。
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/unstructured_element.py
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 | |
filter_table #
filter_table(table_element: Any) -> bool
筛选表格。
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/unstructured_element.py
136 137 138 139 140 141 | |
Llama解析JSON节点解析器 #
基类:EventBaseElementNodeParser
Llama Parse Json 格式元素节点解析器。
将来自LlamaParse的JSON格式文档拆分为文本节点和索引节点,对应嵌入对象(例如表格)。
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/llama_parse_json_element.py
11 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 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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 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 | |
get_nodes_from_node #
从节点获取节点。
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/llama_parse_json_element.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
aget_nodes_from_node
async
#
从节点获取节点。
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/llama_parse_json_element.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
extract_elements #
extract_elements(text: str, mode: Optional[str] = 'json', node_id: Optional[str] = None, node_metadata: Optional[Dict[str, Any]] = None, table_filters: Optional[List[Callable]] = None, **kwargs: Any) -> List[Element]
基于JSON节点提取元素。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
text
|
str
|
节点的文本内容 |
required |
mode
|
Optional[str]
|
基于所选模式返回不同类型元素的不同模式 |
'json'
|
node_id
|
Optional[str]
|
节点的唯一标识符 |
None
|
node_metadata
|
Optional[Dict[str, Any]]
|
节点的元数据。节点的 JSON 输出包含许多元素字段 |
None
|
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/llama_parse_json_element.py
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 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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 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 | |
filter_table #
filter_table(table_element: Any) -> bool
筛选表格。
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/llama_parse_json_element.py
298 299 300 301 302 303 304 | |
代码分割器 #
基类:EventTextSplitter
使用AST解析器拆分代码。
感谢 Kevin Lu / SweepAI 提出这个优雅的代码拆分解决方案。 https://docs.sweep.dev/blogs/chunking-2m-files
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
language
|
str
|
正在拆分的代码所使用的编程语言。 |
required |
chunk_lines
|
int
|
每个块中包含的行数。 |
40
|
chunk_lines_overlap
|
int
|
每个代码块重叠的代码行数。 |
15
|
max_chars
|
int
|
每个分块的最大字符数。 |
1500
|
workflows/handler.py 中的源代码llama_index/core/node_parser/text/code.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 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 | |
from_defaults
classmethod
#
from_defaults(language: str, chunk_lines: int = DEFAULT_CHUNK_LINES, chunk_lines_overlap: int = DEFAULT_LINES_OVERLAP, max_chars: int = DEFAULT_MAX_CHARS, callback_manager: Optional[CallbackManager] = None, parser: Any = None) -> CodeSplitter
使用默认值创建一个代码分割器。
workflows/handler.py 中的源代码llama_index/core/node_parser/text/code.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
split_text #
split_text(text: str) -> List[str]
使用抽象语法树解析器将传入的代码分割成块。
此方法将输入代码解析为抽象语法树,然后在保留语法结构的同时对其进行分块处理。它能够处理错误情况,并确保代码可以被正确解析。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
text
|
str
|
要分割的源代码文本。 |
required |
返回:
| 类型 | 描述 |
|---|---|
List[str]
|
List[str]: 代码块列表。 |
引发:
| 类型 | 描述 |
|---|---|
ValueError
|
如果无法解析指定语言的代码。 |
workflows/handler.py 中的源代码llama_index/core/node_parser/text/code.py
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 | |
Langchain节点解析器 #
基类:EventTextSplitter
基于langchain文本分割器的基本封装。
待办:弄清楚如何让这个元数据感知。
workflows/handler.py 中的源代码llama_index/core/node_parser/text/langchain.py
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 | |
split_text #
split_text(text: str) -> List[str]
将文本分割成句子。
workflows/handler.py 中的源代码llama_index/core/node_parser/text/langchain.py
43 44 45 | |
语义分割节点解析器 #
基类:EventNodeParser
语义节点解析器。
将文档分割为节点,每个节点是一组语义相关的句子。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
buffer_size
|
int
|
评估语义相似度时组合在一起的句子数量 |
1
|
embed_model
|
BaseEmbedding
|
(BaseEmbedding): 要使用的嵌入模型 |
required |
sentence_splitter
|
Optional[Callable]
|
将文本分割成句子 |
<function split_by_sentence_tokenizer.<locals>.<lambda> at 0x7f82dcb320c0>
|
breakpoint_percentile_threshold
|
int
|
用于创建语义断点的相异度阈值,较低的值将生成更多节点 |
95
|
include_metadata
|
bool
|
是否在节点中包含元数据 |
required |
include_prev_next_rel
|
bool
|
是否包含上一页/下一页关系 |
required |
workflows/handler.py 中的源代码llama_index/core/node_parser/text/semantic_splitter.py
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 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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 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 | |
build_semantic_nodes_from_documents #
build_semantic_nodes_from_documents(documents: Sequence[文档], show_progress: bool = False) -> List[BaseNode]
从文档构建窗口节点。
workflows/handler.py 中的源代码llama_index/core/node_parser/text/semantic_splitter.py
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 | |
abuild_semantic_nodes_from_documents
async
#
abuild_semantic_nodes_from_documents(documents: Sequence[文档], show_progress: bool = False) -> List[BaseNode]
从文档异步构建窗口节点。
workflows/handler.py 中的源代码llama_index/core/node_parser/text/semantic_splitter.py
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 229 230 | |
语义双重合并分割器节点解析器 #
基类:EventNodeParser
语义双重合并文本分割器。
将文档分割为节点,每个节点是一组语义相关的句子。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
language_config
|
LanguageConfig
|
选择要使用的语言和spacy语言模型 |
<llama_index.core.node_parser.text.semantic_double_merging_splitter.LanguageConfig object at 0x7f82f02a3110>
|
initial_threshold
|
float
|
设置初始化新分块的阈值 |
0.6
|
appending_threshold
|
float
|
设置将新句子附加到分块的阈值 |
0.8
|
merging_threshold
|
float
|
设置合并整个区块的阈值 |
0.8
|
max_chunk_size
|
int
|
分块的最大尺寸(以字符为单位) |
1000
|
merging_range
|
int
|
如果相似,在最近邻之外要合并多少个'前方'块(可用1或2个) |
1
|
merging_separator
|
str
|
合并数据块时使用的分隔符。默认为单个空格。 |
' '
|
sentence_splitter
|
Optional[Callable]
|
将文本分割成句子 |
<function split_by_sentence_tokenizer.<locals>.<lambda> at 0x7f82dcb30c20>
|
workflows/handler.py 中的源代码llama_index/core/node_parser/text/semantic_double_merging_splitter.py
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 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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 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 364 365 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 397 398 | |
build_semantic_nodes_from_documents #
从文档构建窗口节点。
workflows/handler.py 中的源代码llama_index/core/node_parser/text/semantic_double_merging_splitter.py
198 199 200 201 202 203 | |
build_semantic_nodes_from_nodes #
从节点构建窗口节点。
workflows/handler.py 中的源代码llama_index/core/node_parser/text/semantic_double_merging_splitter.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
句子分割器 #
基类:EventMetadataAwareTextSplitter
解析文本时优先考虑完整句子。
总的来说,这个类会尽量保持句子和段落的完整性。因此,与原始的TokenTextSplitter相比,在节点块末尾出现悬挂句子或句子片段的可能性更小。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
chunk_size
|
int
|
每个分块的令牌大小。 |
1024
|
chunk_overlap
|
int
|
每个分块拆分时的令牌重叠量。 |
200
|
separator
|
str
|
默认用于分割成单词的分隔符 |
' '
|
paragraph_separator
|
str
|
段落之间的分隔符。 |
'\n\n\n'
|
secondary_chunking_regex
|
str | None
|
用于分割句子的备用正则表达式。 |
'[^,.;。?!]+[,.;。?!]?|[,.;。?!]'
|
workflows/handler.py 中的源代码llama_index/core/node_parser/text/sentence.py
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 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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 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 | |
from_defaults
classmethod
#
from_defaults(separator: str = ' ', chunk_size: int = DEFAULT_CHUNK_SIZE, chunk_overlap: int = SENTENCE_CHUNK_OVERLAP, tokenizer: Optional[Callable] = None, paragraph_separator: str = DEFAULT_PARAGRAPH_SEP, chunking_tokenizer_fn: Optional[Callable[[str], List[str]]] = None, secondary_chunking_regex: str = CHUNKING_REGEX, callback_manager: Optional[CallbackManager] = None, include_metadata: bool = True, include_prev_next_rel: bool = True) -> SentenceSplitter
使用参数进行初始化。
workflows/handler.py 中的源代码llama_index/core/node_parser/text/sentence.py
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 | |
句子窗口节点解析器 #
基类:EventNodeParser
句子窗口节点解析器。
将文档分割为节点,每个节点代表一个句子。 每个节点在元数据中包含来自周围句子的窗口。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
sentence_splitter
|
Optional[Callable]
|
将文本分割成句子 |
<function split_by_sentence_tokenizer.<locals>.<lambda> at 0x7f82dcb30c20>
|
include_metadata
|
bool
|
是否在节点中包含元数据 |
required |
include_prev_next_rel
|
bool
|
是否包含上一页/下一页关系 |
required |
window_size
|
int
|
要捕获的句子两侧的句子数量。 |
3
|
window_metadata_key
|
str
|
用于存储句子窗口的元数据键。 |
'window'
|
original_text_metadata_key
|
str
|
用于存储原始句子的元数据键。 |
'original_text'
|
workflows/handler.py 中的源代码llama_index/core/node_parser/text/sentence_window.py
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 | |
build_window_nodes_from_documents #
从文档构建窗口节点。
workflows/handler.py 中的源代码llama_index/core/node_parser/text/sentence_window.py
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 | |
令牌文本分割器 #
基类:EventMetadataAwareTextSplitter
实现基于词语标记的文本分割方法。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
chunk_size
|
int
|
每个分块的令牌大小。 |
1024
|
chunk_overlap
|
int
|
每个分块拆分时的令牌重叠量。 |
20
|
separator
|
str
|
默认用于分割成单词的分隔符 |
' '
|
backup_separators
|
List
|
用于分割的额外分隔符。 |
<dynamic>
|
keep_whitespaces
|
bool
|
是否在文本块中保留前导/尾随空格。 |
False
|
workflows/handler.py 中的源代码llama_index/core/node_parser/text/token.py
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 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 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
from_defaults
classmethod
#
from_defaults(chunk_size: int = DEFAULT_CHUNK_SIZE, chunk_overlap: int = DEFAULT_CHUNK_OVERLAP, separator: str = ' ', backup_separators: Optional[List[str]] = ['\n'], callback_manager: Optional[CallbackManager] = None, keep_whitespaces: bool = False, include_metadata: bool = True, include_prev_next_rel: bool = True, id_func: Optional[Callable[[int, 文档], str]] = None) -> TokenTextSplitter
使用默认参数进行初始化。
workflows/handler.py 中的源代码llama_index/core/node_parser/text/token.py
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 | |
split_text_metadata_aware #
split_text_metadata_aware(text: str, metadata_str: str) -> List[str]
将文本分割成块,保留元数据字符串所需的空间。
workflows/handler.py 中的源代码llama_index/core/node_parser/text/token.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
split_text #
split_text(text: str) -> List[str]
将文本分割成块。
workflows/handler.py 中的源代码llama_index/core/node_parser/text/token.py
138 139 140 | |
get_leaf_nodes #
获取叶子节点。
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/hierarchical.py
25 26 27 28 29 30 31 | |
get_root_nodes #
获取根节点。
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/hierarchical.py
34 35 36 37 38 39 40 | |
get_child_nodes #
从给定的所有节点中获取节点的子节点。
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/hierarchical.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
get_deeper_nodes #
获取给定节点中根节点的子节点,这些子节点具有指定深度。
workflows/handler.py 中的源代码llama_index/core/node_parser/relational/hierarchical.py
61 62 63 64 65 66 67 68 69 70 71 72 73 | |
选项: 成员:- HTMLNodeParser