omnichunk 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- omnichunk-0.1.0/.gitignore +208 -0
- omnichunk-0.1.0/LICENSE +21 -0
- omnichunk-0.1.0/PKG-INFO +313 -0
- omnichunk-0.1.0/README.md +259 -0
- omnichunk-0.1.0/benchmarks/README.md +38 -0
- omnichunk-0.1.0/pyproject.toml +102 -0
- omnichunk-0.1.0/src/omnichunk/__init__.py +34 -0
- omnichunk-0.1.0/src/omnichunk/chunker.py +87 -0
- omnichunk-0.1.0/src/omnichunk/context/__init__.py +17 -0
- omnichunk-0.1.0/src/omnichunk/context/entities.py +817 -0
- omnichunk-0.1.0/src/omnichunk/context/format.py +54 -0
- omnichunk-0.1.0/src/omnichunk/context/imports.py +72 -0
- omnichunk-0.1.0/src/omnichunk/context/scope.py +105 -0
- omnichunk-0.1.0/src/omnichunk/context/siblings.py +112 -0
- omnichunk-0.1.0/src/omnichunk/engine/__init__.py +14 -0
- omnichunk-0.1.0/src/omnichunk/engine/code_engine.py +409 -0
- omnichunk-0.1.0/src/omnichunk/engine/hybrid_engine.py +165 -0
- omnichunk-0.1.0/src/omnichunk/engine/markup_engine.py +352 -0
- omnichunk-0.1.0/src/omnichunk/engine/prose_engine.py +822 -0
- omnichunk-0.1.0/src/omnichunk/engine/router.py +70 -0
- omnichunk-0.1.0/src/omnichunk/parser/__init__.py +11 -0
- omnichunk-0.1.0/src/omnichunk/parser/html_parser.py +77 -0
- omnichunk-0.1.0/src/omnichunk/parser/languages.py +130 -0
- omnichunk-0.1.0/src/omnichunk/parser/markdown_parser.py +211 -0
- omnichunk-0.1.0/src/omnichunk/parser/query_patterns.py +102 -0
- omnichunk-0.1.0/src/omnichunk/parser/tree_sitter.py +35 -0
- omnichunk-0.1.0/src/omnichunk/py.typed +0 -0
- omnichunk-0.1.0/src/omnichunk/sizing/__init__.py +11 -0
- omnichunk-0.1.0/src/omnichunk/sizing/counter.py +59 -0
- omnichunk-0.1.0/src/omnichunk/sizing/nws.py +30 -0
- omnichunk-0.1.0/src/omnichunk/sizing/tokenizers.py +79 -0
- omnichunk-0.1.0/src/omnichunk/types.py +182 -0
- omnichunk-0.1.0/src/omnichunk/util/__init__.py +4 -0
- omnichunk-0.1.0/src/omnichunk/util/detect.py +178 -0
- omnichunk-0.1.0/src/omnichunk/util/text_index.py +46 -0
- omnichunk-0.1.0/src/omnichunk/windowing/__init__.py +16 -0
- omnichunk-0.1.0/src/omnichunk/windowing/greedy.py +114 -0
- omnichunk-0.1.0/src/omnichunk/windowing/merge.py +58 -0
- omnichunk-0.1.0/src/omnichunk/windowing/models.py +12 -0
- omnichunk-0.1.0/src/omnichunk/windowing/overlap.py +109 -0
- omnichunk-0.1.0/src/omnichunk/windowing/split.py +107 -0
- omnichunk-0.1.0/tests/conftest.py +10 -0
- omnichunk-0.1.0/tests/fixtures/html_page.html +18 -0
- omnichunk-0.1.0/tests/fixtures/markdown_doc.md +73 -0
- omnichunk-0.1.0/tests/fixtures/mixed_notebook.py +27 -0
- omnichunk-0.1.0/tests/fixtures/python_complex.py +119 -0
- omnichunk-0.1.0/tests/fixtures/rust_complex.rs +19 -0
- omnichunk-0.1.0/tests/fixtures/sample.json +15 -0
- omnichunk-0.1.0/tests/fixtures/sample.toml +12 -0
- omnichunk-0.1.0/tests/fixtures/sample.yaml +11 -0
- omnichunk-0.1.0/tests/fixtures/typescript_complex.ts +33 -0
- omnichunk-0.1.0/tests/test_api.py +67 -0
- omnichunk-0.1.0/tests/test_code_chunking.py +118 -0
- omnichunk-0.1.0/tests/test_context.py +97 -0
- omnichunk-0.1.0/tests/test_edge_cases.py +40 -0
- omnichunk-0.1.0/tests/test_hybrid_chunking.py +29 -0
- omnichunk-0.1.0/tests/test_markup_chunking.py +53 -0
- omnichunk-0.1.0/tests/test_overlap.py +23 -0
- omnichunk-0.1.0/tests/test_prose_chunking.py +71 -0
- omnichunk-0.1.0/tests/test_query_patterns.py +21 -0
- omnichunk-0.1.0/tests/test_sizing.py +55 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
#.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
# .vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
|
208
|
+
.DS_Store
|
omnichunk-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Oğuzhan KIR
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
omnichunk-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: omnichunk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Structure-aware deterministic chunking for code, prose, and markup.
|
|
5
|
+
Project-URL: Homepage, https://github.com/oguzhankir/omnichunk
|
|
6
|
+
Project-URL: Documentation, https://github.com/oguzhankir/omnichunk#readme
|
|
7
|
+
Project-URL: Issues, https://github.com/oguzhankir/omnichunk/issues
|
|
8
|
+
Project-URL: Source, https://github.com/oguzhankir/omnichunk
|
|
9
|
+
Project-URL: Changelog, https://github.com/oguzhankir/omnichunk/blob/main/CHANGELOG.md
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: chunking,code-analysis,embedding,llm,rag,semantic-search,tree-sitter
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Requires-Dist: numpy>=1.24.0
|
|
27
|
+
Requires-Dist: tree-sitter-go>=0.23.0
|
|
28
|
+
Requires-Dist: tree-sitter-java>=0.23.0
|
|
29
|
+
Requires-Dist: tree-sitter-javascript>=0.23.0
|
|
30
|
+
Requires-Dist: tree-sitter-python>=0.23.0
|
|
31
|
+
Requires-Dist: tree-sitter-rust>=0.23.0
|
|
32
|
+
Requires-Dist: tree-sitter-typescript>=0.23.0
|
|
33
|
+
Requires-Dist: tree-sitter>=0.23.0
|
|
34
|
+
Provides-Extra: all-languages
|
|
35
|
+
Requires-Dist: tree-sitter-c-sharp>=0.23.0; extra == 'all-languages'
|
|
36
|
+
Requires-Dist: tree-sitter-c>=0.23.0; extra == 'all-languages'
|
|
37
|
+
Requires-Dist: tree-sitter-cpp>=0.23.0; extra == 'all-languages'
|
|
38
|
+
Requires-Dist: tree-sitter-kotlin>=0.23.0; extra == 'all-languages'
|
|
39
|
+
Requires-Dist: tree-sitter-php>=0.23.0; extra == 'all-languages'
|
|
40
|
+
Requires-Dist: tree-sitter-ruby>=0.23.0; extra == 'all-languages'
|
|
41
|
+
Requires-Dist: tree-sitter-swift>=0.23.0; extra == 'all-languages'
|
|
42
|
+
Provides-Extra: dev
|
|
43
|
+
Requires-Dist: mypy>=1.0.0; extra == 'dev'
|
|
44
|
+
Requires-Dist: pre-commit>=3.7.0; extra == 'dev'
|
|
45
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
46
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
47
|
+
Requires-Dist: ruff>=0.4.0; extra == 'dev'
|
|
48
|
+
Requires-Dist: tiktoken>=0.5.0; extra == 'dev'
|
|
49
|
+
Provides-Extra: tiktoken
|
|
50
|
+
Requires-Dist: tiktoken>=0.5.0; extra == 'tiktoken'
|
|
51
|
+
Provides-Extra: transformers
|
|
52
|
+
Requires-Dist: transformers>=4.30.0; extra == 'transformers'
|
|
53
|
+
Description-Content-Type: text/markdown
|
|
54
|
+
|
|
55
|
+
<div align="center">
|
|
56
|
+
<picture>
|
|
57
|
+
<source media="(prefers-color-scheme: dark)" srcset="assets/logo/omnichunk-logo-dark.svg">
|
|
58
|
+
<source media="(prefers-color-scheme: light)" srcset="assets/logo/omnichunk-logo.svg">
|
|
59
|
+
<img src="assets/logo/omnichunk-logo.svg" alt="omnichunk" width="360">
|
|
60
|
+
</picture>
|
|
61
|
+
<br><br>
|
|
62
|
+
<p>Structure-aware chunking for code, prose, and markup.</p>
|
|
63
|
+
|
|
64
|
+
[](https://pypi.org/project/omnichunk/)
|
|
65
|
+
[](https://github.com/oguzhankir/omnichunk/actions/workflows/ci.yml)
|
|
66
|
+
[](https://pypi.org/project/omnichunk/)
|
|
67
|
+
[](https://github.com/oguzhankir/omnichunk/blob/main/LICENSE)
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
# omnichunk
|
|
71
|
+
|
|
72
|
+
Chunk code, prose, and markup files with structure awareness.
|
|
73
|
+
|
|
74
|
+
`omnichunk` is a Python library that splits files into smaller pieces while keeping useful context:
|
|
75
|
+
|
|
76
|
+
- **Code**: respects function/class boundaries, includes scope and import information
|
|
77
|
+
- **Markdown**: respects headings and sections
|
|
78
|
+
- **JSON/YAML/TOML**: splits by top-level keys/sections
|
|
79
|
+
- **HTML/XML**: splits by elements
|
|
80
|
+
- **Mixed files**: handles notebooks and Python files with long docstrings
|
|
81
|
+
|
|
82
|
+
Each chunk includes:
|
|
83
|
+
- The original text slice
|
|
84
|
+
- Byte and line ranges for lossless reconstruction
|
|
85
|
+
- Context (scope, entities, headings, imports, siblings)
|
|
86
|
+
- Optional `contextualized_text` for embeddings
|
|
87
|
+
|
|
88
|
+
The library is deterministic and works without external APIs.
|
|
89
|
+
|
|
90
|
+
## Installation
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pip install omnichunk
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Optional extras:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
pip install omnichunk[tiktoken] # tiktoken tokenizer support
|
|
100
|
+
pip install omnichunk[transformers] # HuggingFace tokenizer support
|
|
101
|
+
pip install omnichunk[all-languages] # Extended language grammars
|
|
102
|
+
pip install omnichunk[dev] # Development tools
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Quick start
|
|
106
|
+
|
|
107
|
+
### One-shot API
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from omnichunk import chunk
|
|
111
|
+
|
|
112
|
+
code = """
|
|
113
|
+
import os
|
|
114
|
+
|
|
115
|
+
def hello(name: str) -> str:
|
|
116
|
+
return f"hello {name}"
|
|
117
|
+
"""
|
|
118
|
+
|
|
119
|
+
chunks = chunk("example.py", code, max_chunk_size=128, size_unit="chars")
|
|
120
|
+
|
|
121
|
+
for c in chunks:
|
|
122
|
+
print(c.index, c.byte_range, c.context.breadcrumb)
|
|
123
|
+
print(c.contextualized_text)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Reusable `Chunker`
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
from omnichunk import Chunker
|
|
130
|
+
|
|
131
|
+
chunker = Chunker(
|
|
132
|
+
max_chunk_size=1024,
|
|
133
|
+
min_chunk_size=80,
|
|
134
|
+
tokenizer="cl100k_base",
|
|
135
|
+
context_mode="full",
|
|
136
|
+
overlap=0.1,
|
|
137
|
+
overlap_lines=1,
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
chunks = chunker.chunk("api.py", source_code)
|
|
141
|
+
|
|
142
|
+
for c in chunker.stream("large.py", large_source):
|
|
143
|
+
consume(c)
|
|
144
|
+
|
|
145
|
+
batch_results = chunker.batch(
|
|
146
|
+
[
|
|
147
|
+
{"filepath": "a.py", "code": code_a},
|
|
148
|
+
{"filepath": "b.ts", "code": code_b},
|
|
149
|
+
{"filepath": "README.md", "code": readme_md},
|
|
150
|
+
],
|
|
151
|
+
concurrency=8,
|
|
152
|
+
)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### File API
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
from omnichunk import chunk_file
|
|
159
|
+
|
|
160
|
+
chunks = chunk_file("path/to/file.py")
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Chunk model
|
|
164
|
+
|
|
165
|
+
Every `Chunk` includes raw content, exact offsets, and rich context:
|
|
166
|
+
|
|
167
|
+
- `text`: exact source slice (lossless reconstruction)
|
|
168
|
+
- `contextualized_text`: embedding-ready representation
|
|
169
|
+
- `byte_range`, `line_range`
|
|
170
|
+
- `context`: scope, entities, siblings, imports, headings, section metadata
|
|
171
|
+
- `token_count`, `char_count`, `nws_count`
|
|
172
|
+
|
|
173
|
+
## Supported content
|
|
174
|
+
|
|
175
|
+
### Code
|
|
176
|
+
|
|
177
|
+
- Python
|
|
178
|
+
- JavaScript / TypeScript
|
|
179
|
+
- Rust
|
|
180
|
+
- Go
|
|
181
|
+
- Java
|
|
182
|
+
- C / C++ / C#
|
|
183
|
+
- Ruby / PHP / Kotlin / Swift (grammar-dependent)
|
|
184
|
+
|
|
185
|
+
### Prose
|
|
186
|
+
|
|
187
|
+
- Markdown
|
|
188
|
+
- Plaintext
|
|
189
|
+
|
|
190
|
+
Markdown fenced blocks are delegated by language:
|
|
191
|
+
|
|
192
|
+
- fenced code (`python`, `ts`, etc.) routes to `CodeEngine`
|
|
193
|
+
- fenced markup (`json`, `yaml`, `toml`, `html`, `xml`) routes to `MarkupEngine`
|
|
194
|
+
|
|
195
|
+
### Markup
|
|
196
|
+
|
|
197
|
+
- JSON
|
|
198
|
+
- YAML
|
|
199
|
+
- TOML
|
|
200
|
+
- HTML / XML
|
|
201
|
+
|
|
202
|
+
### Hybrid
|
|
203
|
+
|
|
204
|
+
- Python with heavy docstrings
|
|
205
|
+
- Notebook-style `# %%` cell files
|
|
206
|
+
|
|
207
|
+
## Architecture
|
|
208
|
+
|
|
209
|
+
```
|
|
210
|
+
src/omnichunk/
|
|
211
|
+
├── chunker.py
|
|
212
|
+
├── types.py
|
|
213
|
+
├── engine/
|
|
214
|
+
│ ├── router.py
|
|
215
|
+
│ ├── code_engine.py
|
|
216
|
+
│ ├── prose_engine.py
|
|
217
|
+
│ ├── markup_engine.py
|
|
218
|
+
│ └── hybrid_engine.py
|
|
219
|
+
├── parser/
|
|
220
|
+
│ ├── tree_sitter.py
|
|
221
|
+
│ ├── markdown_parser.py
|
|
222
|
+
│ ├── html_parser.py
|
|
223
|
+
│ └── languages.py
|
|
224
|
+
├── context/
|
|
225
|
+
│ ├── entities.py
|
|
226
|
+
│ ├── scope.py
|
|
227
|
+
│ ├── siblings.py
|
|
228
|
+
│ ├── imports.py
|
|
229
|
+
│ └── format.py
|
|
230
|
+
├── sizing/
|
|
231
|
+
│ ├── nws.py
|
|
232
|
+
│ ├── tokenizers.py
|
|
233
|
+
│ └── counter.py
|
|
234
|
+
└── windowing/
|
|
235
|
+
├── greedy.py
|
|
236
|
+
├── merge.py
|
|
237
|
+
├── split.py
|
|
238
|
+
└── overlap.py
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Determinism & integrity guarantees
|
|
242
|
+
|
|
243
|
+
`omnichunk` is built to preserve source fidelity:
|
|
244
|
+
|
|
245
|
+
- Chunk boundaries are deterministic
|
|
246
|
+
- Empty/whitespace-only chunks are dropped
|
|
247
|
+
- Chunks are contiguous and non-overlapping in source order
|
|
248
|
+
- Byte range integrity is validated in tests:
|
|
249
|
+
|
|
250
|
+
```python
|
|
251
|
+
original_bytes = source.encode("utf-8")
|
|
252
|
+
for chunk in chunks:
|
|
253
|
+
assert original_bytes[chunk.byte_range.start:chunk.byte_range.end].decode("utf-8") == chunk.text
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Testing
|
|
257
|
+
|
|
258
|
+
Run the test suite:
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
pytest -q
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Run benchmark scenarios:
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
python benchmarks/run_benchmarks.py
|
|
268
|
+
python benchmarks/run_comparisons.py
|
|
269
|
+
python benchmarks/run_quality_report.py
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Run repository checks:
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
python scripts/check_ai_rules_sync.py
|
|
276
|
+
python scripts/check_benchmarks.py
|
|
277
|
+
python scripts/check_benchmarks.py --run-quality
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Current suite covers:
|
|
281
|
+
|
|
282
|
+
- API usage (`chunk`, `chunk_file`, `Chunker`)
|
|
283
|
+
- Code/prose/markup/hybrid behavior
|
|
284
|
+
- Context metadata (imports, siblings, scope, headings)
|
|
285
|
+
- Sizing/tokenization/NWS logic
|
|
286
|
+
- Overlap behavior
|
|
287
|
+
- Edge cases (empty input, unicode, malformed syntax, range contiguity)
|
|
288
|
+
|
|
289
|
+
## Contributing
|
|
290
|
+
|
|
291
|
+
Contribution and project process files:
|
|
292
|
+
|
|
293
|
+
- `CONTRIBUTING.md`
|
|
294
|
+
- `CODE_OF_CONDUCT.md`
|
|
295
|
+
- `SECURITY.md`
|
|
296
|
+
- `GOVERNANCE.md`
|
|
297
|
+
- `MAINTAINERS.md`
|
|
298
|
+
- `ROADMAP.md`
|
|
299
|
+
- `ARCHITECTURE.md`
|
|
300
|
+
|
|
301
|
+
Install dev tooling and run pre-commit hooks:
|
|
302
|
+
|
|
303
|
+
```bash
|
|
304
|
+
pip install -e .[dev]
|
|
305
|
+
pre-commit install
|
|
306
|
+
pre-commit run --all-files
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## Notes
|
|
310
|
+
|
|
311
|
+
- Tree-sitter grammars are resolved dynamically and cached per language.
|
|
312
|
+
- If a parser is unavailable, the system degrades gracefully with fallback heuristics.
|
|
313
|
+
- `contextualized_text` is optimized for embedding quality while preserving raw `text` separately.
|