Chunkers¶
Bases: Protocol
Splits a Document into a list of Chunks.
Contract — chunk.content is the exact text that will be embedded.
Implementations that prepend contextual information (e.g. heading hierarchy
in a MarkdownChunker, code-block fences in a CodeChunker) MUST include that
context in chunk.content, not only in chunk.metadata. The embedding
cache keys off (model_id, sha256(chunk.content)); two chunks with the
same body but different context would collide and return the wrong vector.
The companion chunk.content_hash is sha256(chunk.content) and is set
by the implementation. Callers must not mutate chunk.content after the
chunker returns.
Source code in src/cenote/chunkers/base.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
chunk(document: Document) -> list[Chunk]
¶
Return the document split into ordered Chunks.
Source code in src/cenote/chunkers/base.py
27 28 29 | |
Recursively splits a Document using separators in priority order.
Algorithm:
1. Try to split the text on the highest-priority separator.
2. For each resulting piece, if it fits under chunk_size, keep it.
3. Otherwise, recurse on it with the next separator.
4. After all pieces fit, glue adjacent pieces back together up to
chunk_size, producing the final chunk list with chunk_overlap
characters of overlap between consecutive chunks.
Source code in src/cenote/chunkers/recursive.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 | |
chunk(document: Document) -> list[Chunk]
¶
Return the document split into ordered Chunks.
Source code in src/cenote/chunkers/recursive.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |