parsing
PdfParsingConfig
¶
Bases: BaseParsingConfig
enable_configs(values)
classmethod
¶
Ensure correct config is set based on library selection.
Source code in langroid/parsing/parser.py
ParsingConfig
¶
Bases: BaseSettings
convert_chunk_size_to_int(v)
classmethod
¶
Convert chunk_size to int, maintaining backward compatibility with Pydantic V1.
Source code in langroid/parsing/parser.py
Parser(config)
¶
Source code in langroid/parsing/parser.py
add_window_ids(chunks)
¶
Chunks may belong to multiple docs, but for each doc, they appear consecutively. Add window_ids in metadata.
Chunks this has already windowed are left as they are, so calling
it twice does not replace their neighbors with a singleton. See
the module-level add_window_ids for the details.
Source code in langroid/parsing/parser.py
chunk_tokens(text)
¶
Split a text into chunks of ~CHUNK_SIZE tokens, based on punctuation and newline boundaries. Adapted from https://github.com/openai/chatgpt-retrieval-plugin/blob/main/services/chunks.py
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to split into chunks. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
A list of text chunks, each of which is a string of tokens |
List[str]
|
roughly self.config.chunk_size tokens long. |
List[str]
|
A chunk may exceed that size to finish a UTF-8 character. |
Source code in langroid/parsing/parser.py
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 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |