text-chipper 0.2.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.
Files changed (104) hide show
  1. text_chipper-0.2.0/.github/dependabot.yml +13 -0
  2. text_chipper-0.2.0/.github/workflows/benchmark.yaml +92 -0
  3. text_chipper-0.2.0/.github/workflows/build_wheels.yaml +131 -0
  4. text_chipper-0.2.0/.gitignore +30 -0
  5. text_chipper-0.2.0/Cargo.lock +1725 -0
  6. text_chipper-0.2.0/Cargo.toml +64 -0
  7. text_chipper-0.2.0/LICENSE +201 -0
  8. text_chipper-0.2.0/PKG-INFO +386 -0
  9. text_chipper-0.2.0/README.md +359 -0
  10. text_chipper-0.2.0/benches/chipper_benchmark.rs +40 -0
  11. text_chipper-0.2.0/benchmarks/README.md +272 -0
  12. text_chipper-0.2.0/benchmarks/charts/memory_single_core.png +0 -0
  13. text_chipper-0.2.0/benchmarks/charts/memory_single_core.svg +2373 -0
  14. text_chipper-0.2.0/benchmarks/charts/quality_scorecard.png +0 -0
  15. text_chipper-0.2.0/benchmarks/charts/quality_scorecard.svg +3281 -0
  16. text_chipper-0.2.0/benchmarks/charts/speed_overall.png +0 -0
  17. text_chipper-0.2.0/benchmarks/charts/speed_overall.svg +2169 -0
  18. text_chipper-0.2.0/benchmarks/charts/speed_per_workload.png +0 -0
  19. text_chipper-0.2.0/benchmarks/charts/speed_per_workload.svg +4508 -0
  20. text_chipper-0.2.0/benchmarks/chunkbench/__init__.py +3 -0
  21. text_chipper-0.2.0/benchmarks/chunkbench/__main__.py +3 -0
  22. text_chipper-0.2.0/benchmarks/chunkbench/adapters.py +296 -0
  23. text_chipper-0.2.0/benchmarks/chunkbench/corpora.py +367 -0
  24. text_chipper-0.2.0/benchmarks/chunkbench/metrics.py +370 -0
  25. text_chipper-0.2.0/benchmarks/chunkbench/plot.py +94 -0
  26. text_chipper-0.2.0/benchmarks/chunkbench/report.py +159 -0
  27. text_chipper-0.2.0/benchmarks/chunkbench/runner.py +341 -0
  28. text_chipper-0.2.0/benchmarks/chunkbench/tokenizer.py +44 -0
  29. text_chipper-0.2.0/benchmarks/chunkbench/worker.py +188 -0
  30. text_chipper-0.2.0/benchmarks/corpora.lock.json +32 -0
  31. text_chipper-0.2.0/benchmarks/diag_lost.py +132 -0
  32. text_chipper-0.2.0/benchmarks/diag_real.py +232 -0
  33. text_chipper-0.2.0/benchmarks/make_charts.py +483 -0
  34. text_chipper-0.2.0/benchmarks/requirements.txt +12 -0
  35. text_chipper-0.2.0/benchmarks/results/20261112_220628/report.md +76 -0
  36. text_chipper-0.2.0/benchmarks/results/20261112_220628/results.json +992 -0
  37. text_chipper-0.2.0/benchmarks/results/20261112_220628/summary.csv +15 -0
  38. text_chipper-0.2.0/benchmarks/results/20261112_233503/commit.txt +1 -0
  39. text_chipper-0.2.0/benchmarks/results/20261112_233503/pip_freeze.txt +59 -0
  40. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/answer_alignment__all_ov0.png +0 -0
  41. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/answer_alignment__all_ov0.svg +2263 -0
  42. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/answer_alignment__single_ov0.png +0 -0
  43. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/answer_alignment__single_ov0.svg +2264 -0
  44. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/clean_ends__all_ov0.png +0 -0
  45. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/clean_ends__all_ov0.svg +2444 -0
  46. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/clean_ends__single_ov0.png +0 -0
  47. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/clean_ends__single_ov0.svg +2445 -0
  48. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/code_fences_intact__all_ov0.png +0 -0
  49. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/code_fences_intact__all_ov0.svg +1536 -0
  50. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/code_fences_intact__single_ov0.png +0 -0
  51. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/code_fences_intact__single_ov0.svg +1539 -0
  52. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/cpu_time__all_ov0.png +0 -0
  53. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/cpu_time__all_ov0.svg +2539 -0
  54. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/cpu_time__single_ov0.png +0 -0
  55. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/cpu_time__single_ov0.svg +2533 -0
  56. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/memory__all_ov0.png +0 -0
  57. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/memory__all_ov0.svg +2380 -0
  58. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/memory__single_ov0.png +0 -0
  59. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/memory__single_ov0.svg +2383 -0
  60. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/mid_word_cuts__all_ov0.png +0 -0
  61. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/mid_word_cuts__all_ov0.svg +2416 -0
  62. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/mid_word_cuts__single_ov0.png +0 -0
  63. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/mid_word_cuts__single_ov0.svg +2419 -0
  64. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/over_limit__all_ov0.png +0 -0
  65. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/over_limit__all_ov0.svg +2483 -0
  66. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/over_limit__single_ov0.png +0 -0
  67. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/over_limit__single_ov0.svg +2486 -0
  68. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/throughput__all_ov0.png +0 -0
  69. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/throughput__all_ov0.svg +2404 -0
  70. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/throughput__single_ov0.png +0 -0
  71. text_chipper-0.2.0/benchmarks/results/20261112_233503/plots/throughput__single_ov0.svg +2407 -0
  72. text_chipper-0.2.0/benchmarks/results/20261112_233503/report.md +358 -0
  73. text_chipper-0.2.0/benchmarks/results/20261112_233503/results.json +13013 -0
  74. text_chipper-0.2.0/benchmarks/results/20261112_233503/summary.csv +193 -0
  75. text_chipper-0.2.0/benchmarks/tests/conftest.py +9 -0
  76. text_chipper-0.2.0/benchmarks/tests/stubs.py +43 -0
  77. text_chipper-0.2.0/benchmarks/tests/test_chunkbench.py +233 -0
  78. text_chipper-0.2.0/integrations/langchain.py +48 -0
  79. text_chipper-0.2.0/integrations/llama_index.py +59 -0
  80. text_chipper-0.2.0/pyproject.toml +33 -0
  81. text_chipper-0.2.0/scripts/fetch_commonmark.py +63 -0
  82. text_chipper-0.2.0/scripts/profile_tokenizer.py +119 -0
  83. text_chipper-0.2.0/scripts/run_release_suite.sh +63 -0
  84. text_chipper-0.2.0/scripts/run_validation.sh +36 -0
  85. text_chipper-0.2.0/src/backend.rs +412 -0
  86. text_chipper-0.2.0/src/block.rs +213 -0
  87. text_chipper-0.2.0/src/chunk_types.rs +197 -0
  88. text_chipper-0.2.0/src/chunker.rs +1574 -0
  89. text_chipper-0.2.0/src/errors.rs +46 -0
  90. text_chipper-0.2.0/src/file.rs +306 -0
  91. text_chipper-0.2.0/src/lib.rs +101 -0
  92. text_chipper-0.2.0/src/markdown.rs +1542 -0
  93. text_chipper-0.2.0/src/normalization.rs +265 -0
  94. text_chipper-0.2.0/src/python.rs +502 -0
  95. text_chipper-0.2.0/src/split_engine.rs +1389 -0
  96. text_chipper-0.2.0/src/tests/merge_margin.rs +269 -0
  97. text_chipper-0.2.0/src/tests/oracle_block.rs +293 -0
  98. text_chipper-0.2.0/src/tests/oracle_list.rs +159 -0
  99. text_chipper-0.2.0/src/tests/parallel.rs +428 -0
  100. text_chipper-0.2.0/src/tests/release_suite.rs +3367 -0
  101. text_chipper-0.2.0/src/tests/robustness.rs +670 -0
  102. text_chipper-0.2.0/src/tests/unit.rs +595 -0
  103. text_chipper-0.2.0/tests/fixtures/commonmark_spec.json +5218 -0
  104. text_chipper-0.2.0/tests/test_bindings.py +275 -0
@@ -0,0 +1,13 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: github-actions
4
+ directory: /
5
+ schedule:
6
+ interval: weekly
7
+ - package-ecosystem: cargo
8
+ directory: /
9
+ schedule:
10
+ interval: weekly
11
+ ignore:
12
+ - dependency-name: "tiktoken-rs"
13
+ - dependency-name: "tiktoken"
@@ -0,0 +1,92 @@
1
+ name: benchmark
2
+
3
+ # Runs the cross-library benchmark (benchmarks/) on a GitHub-hosted runner and publishes the tables
4
+ # in the job summary; raw results, charts and `pip freeze` are uploaded as an artifact.
5
+ # Hosted runners are shared machines: use these numbers for relative comparison, not absolute speed.
6
+ on:
7
+ workflow_dispatch:
8
+ inputs:
9
+ size_mib:
10
+ description: "Size of each synthetic corpus in MiB"
11
+ default: "1.0"
12
+ rounds:
13
+ description: "Independent processes per cell"
14
+ default: "5"
15
+ include_real:
16
+ description: "Also run on the downloaded real-world corpora"
17
+ type: boolean
18
+ default: true
19
+
20
+ permissions:
21
+ contents: read
22
+
23
+ concurrency:
24
+ group: benchmark-${{ github.ref }}
25
+ cancel-in-progress: true
26
+
27
+ jobs:
28
+ benchmark:
29
+ runs-on: ubuntu-latest
30
+ timeout-minutes: 120
31
+ env:
32
+ SIZE_MIB: ${{ inputs.size_mib }}
33
+ ROUNDS: ${{ inputs.rounds }}
34
+ INCLUDE_REAL: ${{ inputs.include_real }}
35
+ steps:
36
+ - uses: actions/checkout@v5
37
+ - uses: dtolnay/rust-toolchain@stable
38
+ - uses: Swatinem/rust-cache@v2
39
+ - uses: actions/setup-python@v6
40
+ with:
41
+ python-version: "3.12"
42
+
43
+ - name: Create virtualenv
44
+ run: |
45
+ python -m venv .venv
46
+ echo "VIRTUAL_ENV=$PWD/.venv" >> "$GITHUB_ENV"
47
+ echo "$PWD/.venv/bin" >> "$GITHUB_PATH"
48
+
49
+ - name: Install benchmark dependencies and build text_chipper
50
+ run: |
51
+ python -m pip install --upgrade pip maturin
52
+ python -m pip install -r benchmarks/requirements.txt
53
+ maturin develop --release
54
+
55
+ - name: Harness self-tests
56
+ run: python -m pytest benchmarks/tests -q
57
+
58
+ - name: Smoke-test every adapter
59
+ working-directory: benchmarks
60
+ run: python -m chunkbench check
61
+
62
+ - name: Fetch real-world corpora (pinned by SHA-256)
63
+ if: ${{ inputs.include_real }}
64
+ working-directory: benchmarks
65
+ run: python -m chunkbench fetch
66
+
67
+ - name: Run benchmark
68
+ working-directory: benchmarks
69
+ run: |
70
+ args=(run --size-mib "$SIZE_MIB" --rounds "$ROUNDS" --out ci_results)
71
+ if [ "$INCLUDE_REAL" != "true" ]; then args+=(--no-real); fi
72
+ python -m chunkbench "${args[@]}"
73
+
74
+ - name: Charts, environment record, job summary
75
+ working-directory: benchmarks
76
+ run: |
77
+ run_dir="$(ls -d ci_results/*/ | sort | tail -n1)"
78
+ python -m chunkbench plot "$run_dir"
79
+ python -m pip freeze > "${run_dir}pip_freeze.txt"
80
+ echo "$GITHUB_SHA" > "${run_dir}commit.txt"
81
+ {
82
+ echo "### Benchmark run ($GITHUB_SHA)"
83
+ echo "Hosted runner (shared hardware): compare libraries with each other, not with other machines."
84
+ echo
85
+ cat "${run_dir}report.md"
86
+ } >> "$GITHUB_STEP_SUMMARY"
87
+
88
+ - uses: actions/upload-artifact@v4
89
+ with:
90
+ name: benchmark-results
91
+ path: benchmarks/ci_results/
92
+ if-no-files-found: error
@@ -0,0 +1,131 @@
1
+ name: build_wheels
2
+
3
+ # Builds the sdist and the wheels for PyPI (`pip install text-chipper`).
4
+ # - pull requests / manual runs: build and test only
5
+ # - tag `vX.Y.Z` (must equal the version in Cargo.toml): build, test, then publish to PyPI
6
+ on:
7
+ push:
8
+ branches: [main]
9
+ tags: ["v*"]
10
+ pull_request:
11
+ workflow_dispatch:
12
+
13
+ permissions:
14
+ contents: read
15
+
16
+ concurrency:
17
+ group: build-wheels-${{ github.ref }}
18
+ cancel-in-progress: true
19
+
20
+ env:
21
+ CARGO_TERM_COLOR: always
22
+
23
+ jobs:
24
+ rust-tests:
25
+ name: cargo test
26
+ runs-on: ubuntu-latest
27
+ steps:
28
+ - uses: actions/checkout@v5
29
+ - uses: dtolnay/rust-toolchain@stable
30
+ - uses: Swatinem/rust-cache@v2
31
+ - run: cargo test --release
32
+
33
+ sdist:
34
+ name: sdist
35
+ runs-on: ubuntu-latest
36
+ steps:
37
+ - uses: actions/checkout@v5
38
+ - name: Tag must match the crate version
39
+ if: startsWith(github.ref, 'refs/tags/v')
40
+ run: |
41
+ version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)"
42
+ test "v${version}" = "${GITHUB_REF_NAME}" || { echo "tag ${GITHUB_REF_NAME} != Cargo.toml version ${version}"; exit 1; }
43
+ - uses: PyO3/maturin-action@v1
44
+ with:
45
+ command: sdist
46
+ args: --out dist
47
+ - uses: actions/upload-artifact@v4
48
+ with:
49
+ name: dist-sdist
50
+ path: dist/*.tar.gz
51
+
52
+ wheels:
53
+ name: wheel ${{ matrix.name }}
54
+ runs-on: ${{ matrix.os }}
55
+ strategy:
56
+ fail-fast: false
57
+ matrix:
58
+ include:
59
+ - { name: linux-x86_64, os: ubuntu-latest, target: x86_64-unknown-linux-gnu, manylinux: auto }
60
+ - { name: linux-aarch64, os: ubuntu-24.04-arm, target: aarch64-unknown-linux-gnu, manylinux: auto }
61
+ - { name: musllinux-x86_64, os: ubuntu-latest, target: x86_64-unknown-linux-musl, manylinux: musllinux_1_2 }
62
+ - { name: musllinux-aarch64, os: ubuntu-24.04-arm, target: aarch64-unknown-linux-musl, manylinux: musllinux_1_2 }
63
+ - { name: macos-arm64, os: macos-latest, target: aarch64-apple-darwin, manylinux: "off" }
64
+ - { name: macos-x86_64, os: macos-15-intel, target: x86_64-apple-darwin, manylinux: "off" }
65
+ - { name: windows-x64, os: windows-latest, target: x86_64-pc-windows-msvc, manylinux: "off" }
66
+ steps:
67
+ - uses: actions/checkout@v5
68
+ - uses: actions/setup-python@v6
69
+ with:
70
+ python-version: "3.12"
71
+ # The extension uses the stable ABI (abi3-py39): one wheel per platform covers Python >= 3.9.
72
+ - uses: PyO3/maturin-action@v1
73
+ with:
74
+ target: ${{ matrix.target }}
75
+ manylinux: ${{ matrix.manylinux }}
76
+ args: --release --out dist
77
+ sccache: "true"
78
+ - uses: actions/upload-artifact@v4
79
+ with:
80
+ name: dist-${{ matrix.name }}
81
+ path: dist/*.whl
82
+
83
+ test-wheels:
84
+ name: test wheel on ${{ matrix.os }} / py${{ matrix.python }}
85
+ needs: wheels
86
+ runs-on: ${{ matrix.os }}
87
+ strategy:
88
+ fail-fast: false
89
+ matrix:
90
+ include:
91
+ - { os: ubuntu-24.04, python: "3.9", wheel: linux-x86_64 }
92
+ - { os: ubuntu-24.04, python: "3.13", wheel: linux-x86_64 }
93
+ - { os: macos-latest, python: "3.12", wheel: macos-arm64 }
94
+ - { os: windows-latest, python: "3.12", wheel: windows-x64 }
95
+ steps:
96
+ - uses: actions/checkout@v5
97
+ - uses: actions/setup-python@v6
98
+ with:
99
+ python-version: ${{ matrix.python }}
100
+ - uses: actions/download-artifact@v4
101
+ with:
102
+ name: dist-${{ matrix.wheel }}
103
+ path: dist
104
+ - name: Install the built wheel (not the source tree) and run the binding tests
105
+ shell: bash
106
+ run: |
107
+ python -m pip install --upgrade pip pytest
108
+ python -m pip install --no-index --find-links dist text-chipper
109
+ python -c "import text_chipper; print(text_chipper.__file__)"
110
+ # Run from a temp copy of the tests so `import text_chipper` cannot pick up anything from the repo root.
111
+ mkdir -p "$RUNNER_TEMP/t" && cp -r tests "$RUNNER_TEMP/t/"
112
+ cd "$RUNNER_TEMP/t" && python -m pytest tests -q
113
+
114
+ publish:
115
+ name: publish to PyPI
116
+ if: startsWith(github.ref, 'refs/tags/v')
117
+ needs: [rust-tests, sdist, wheels, test-wheels]
118
+ runs-on: ubuntu-latest
119
+ environment:
120
+ name: pypi
121
+ url: https://pypi.org/p/text-chipper
122
+ permissions:
123
+ id-token: write # PyPI trusted publishing (no API token stored in GitHub)
124
+ steps:
125
+ - uses: actions/download-artifact@v4
126
+ with:
127
+ pattern: dist-*
128
+ merge-multiple: true
129
+ path: dist
130
+ - run: ls -l dist
131
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,30 @@
1
+ # Rust
2
+ /target/
3
+
4
+ # Python
5
+ __pycache__/
6
+ *.py[cod]
7
+ *.so
8
+ *.pyd
9
+ .venv/
10
+ venv/
11
+ dist/
12
+ build/
13
+ *.egg-info/
14
+ .pytest_cache/
15
+
16
+ # OS / editor
17
+ .DS_Store
18
+ .idea/
19
+ .vscode/
20
+
21
+ # Local leftovers
22
+ *.orig
23
+ *.rej
24
+ *.patch
25
+ /reports/
26
+
27
+ # Benchmark: downloaded corpora (re-created by `python -m chunkbench fetch`, pinned in corpora.lock.json)
28
+ /benchmarks/corpora/
29
+ # Benchmark: CI output (uploaded as a workflow artifact instead)
30
+ /benchmarks/ci_results/