parser
BaseParsingConfig
¶
Bases: BaseSettings
Base class for document parsing configurations.
LLMPdfParserConfig
¶
Bases: BaseSettings
Configuration for LLM-based parsing.
MarkerConfig
¶
Bases: BaseSettings
Configuration for Markitdown-based 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 | |
add_window_ids(chunks, n_neighbor_ids)
¶
Give each chunk a distinct id and the ids of its neighbors.
Chunks may belong to multiple docs, but for each doc they appear
consecutively, and all chunks of one doc share a metadata.id -- which
is how they are grouped here, so a window never crosses a document.
Already-windowed chunks are left alone. Grouping by a shared
metadata.id is what makes this non-idempotent: after one call every
chunk has its own id, so a second call would see each chunk as a
single-chunk document and collapse every window to a singleton,
silently discarding the neighbors from the first call. A chunk is taken
to be already windowed when it is alone under its id and that id is in
its own window -- the exact state this function leaves behind, and one
a group of siblings sharing an inherited id cannot be in.
The decision is per group, not per call, so mixing windowed chunks with fresh ones windows only the fresh ones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunks
|
List[Document]
|
chunks to window, modified in place. |
required |
n_neighbor_ids
|
int
|
how many neighbors to keep on each side. |
required |