line_indexer
zocrates.rag.line_indexer ¶
Precomputed character-offset indexing utilities for line mapping.
Provides fast, deterministic, 1-indexed line number resolution for converted Markdown documents, shared across ToC generation and chunking pipelines.
LineIndex ¶
Precomputed character-offset index for fast, deterministic character-to-line mapping.
Construct a line index from source text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Raw input text. |
required |
Source code in zocrates/rag/line_indexer.py
char_to_line ¶
Map a 0-indexed character position to a 1-indexed line number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
char_pos
|
int
|
Character position in source text. |
required |
Returns:
| Type | Description |
|---|---|
int
|
1-indexed line number clamped to |
Source code in zocrates/rag/line_indexer.py
span_to_lines ¶
Map a half-open character range [start_char, end_char) to 1-indexed line bounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_char
|
int
|
0-indexed inclusive start character position. |
required |
end_char
|
int
|
0-indexed exclusive end character position. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
Tuple of |
Source code in zocrates/rag/line_indexer.py
char_offset_to_line ¶
Binary search character offset to 1-indexed line number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
offsets
|
list[int]
|
List of character start offsets for each line (0-indexed). |
required |
char_pos
|
int
|
Character index in document. |
required |
total_lines
|
int | None
|
Optional total number of lines to clamp the maximum line number. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
1-indexed line number. |