preembed 0.1.1__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.
preembed-0.1.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Aditya Munot
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.
@@ -0,0 +1,164 @@
1
+ Metadata-Version: 2.4
2
+ Name: preembed
3
+ Version: 0.1.1
4
+ Classifier: Development Status :: 2 - Pre-Alpha
5
+ Classifier: Environment :: Console
6
+ Classifier: License :: OSI Approved :: MIT License
7
+ Classifier: Operating System :: OS Independent
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
13
+ Classifier: Topic :: Text Processing
14
+ Requires-Dist: hypothesis>=6 ; extra == 'dev'
15
+ Requires-Dist: maturin>=1.5,<2 ; extra == 'dev'
16
+ Requires-Dist: pytest>=8 ; extra == 'dev'
17
+ Requires-Dist: pytest-cov>=5 ; extra == 'dev'
18
+ Requires-Dist: ruff>=0.4 ; extra == 'lint'
19
+ Requires-Dist: mypy>=1.9 ; extra == 'lint'
20
+ Provides-Extra: dev
21
+ Provides-Extra: lint
22
+ License-File: LICENSE
23
+ Summary: High-performance document preparation toolkit for LLM and RAG pipelines.
24
+ Keywords: llm,rag,chunking,document-processing,embeddings
25
+ Home-Page: https://github.com/AdityaMunot/preembed
26
+ Author: Aditya Munot
27
+ Requires-Python: >=3.10
28
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
29
+ Project-URL: Changelog, https://github.com/AdityaMunot/preembed/blob/main/CHANGELOG.md
30
+ Project-URL: Documentation, https://github.com/AdityaMunot/preembed/tree/main/docs
31
+ Project-URL: Homepage, https://github.com/AdityaMunot/preembed
32
+ Project-URL: Issues, https://github.com/AdityaMunot/preembed/issues
33
+ Project-URL: Repository, https://github.com/AdityaMunot/preembed
34
+
35
+ # preembed
36
+
37
+ <p align="center">
38
+ <picture>
39
+ <img src="https://raw.githubusercontent.com/AdityaMunot/preembed/main/assets/logo.png" alt="preembed" width="400">
40
+ </picture>
41
+ </p>
42
+
43
+ > Clean, chunk, deduplicate, and score documents before embedding.
44
+
45
+ **preembed** is a high-performance toolkit that sits between your raw documents and your vector database. It turns messy HTML, markdown, logs, and exports into high-quality, LLM-ready chunks — so your RAG pipeline retrieves better context and hallucinates less.
46
+
47
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
48
+ [![Python 3.10+](https://img.shields.io/badge/Python-3.10%2B-blue.svg)](https://www.python.org)
49
+ [![Rust](https://img.shields.io/badge/Rust-Powered-orange.svg)](https://www.rust-lang.org)
50
+
51
+ ## Why
52
+
53
+ Most RAG pipelines embed documents directly — noise, duplicates, and all. The result: wasted tokens, bloated vector stores, and retrieval that returns boilerplate instead of answers.
54
+
55
+ preembed fixes the data before it enters the pipeline:
56
+
57
+ ```
58
+ raw documents → clean → chunk → dedupe → score → embed
59
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60
+ preembed handles this
61
+ ```
62
+
63
+ ## Install
64
+
65
+ ```bash
66
+ pip install preembed
67
+ ```
68
+
69
+ For development (requires Rust toolchain):
70
+
71
+ ```bash
72
+ pip install -e ".[dev]"
73
+ maturin develop --release
74
+ ```
75
+
76
+ ## Quickstart
77
+
78
+ ### Pipeline (recommended)
79
+
80
+ ```python
81
+ from preembed import Pipeline
82
+
83
+ result = Pipeline(chunk_size=512, overlap=64).run("path/to/documents/")
84
+ result.save_report("report.json")
85
+
86
+ print(f"{result.stats.total_chunks} chunks, {result.stats.duplicate_ratio:.0%} duplicates removed")
87
+ ```
88
+
89
+ ### Individual primitives
90
+
91
+ ```python
92
+ from preembed import clean_text, chunk_text, dedupe_chunks, score_chunks
93
+
94
+ text = clean_text("<html><script>tracking()</script><p>Actual content here.</p></html>")
95
+ # → "Actual content here."
96
+
97
+ chunks = chunk_text(text, chunk_size=512, overlap=64)
98
+ chunks = dedupe_chunks(chunks)
99
+ scored = score_chunks(chunks)
100
+ # Each chunk gets a 0-1 quality score + warning labels
101
+ ```
102
+
103
+ ### Streaming (memory-efficient)
104
+
105
+ ```python
106
+ for batch in Pipeline().stream("huge_corpus/", batch_size=50):
107
+ upload_to_vector_db(batch.scored_chunks)
108
+ ```
109
+
110
+ Cross-batch deduplication included. Processes one batch at a time — constant memory regardless of corpus size.
111
+
112
+ ### Custom scoring
113
+
114
+ ```python
115
+ from preembed import register_scorer
116
+
117
+ @register_scorer("domain_relevance", weight=0.15)
118
+ def domain_scorer(chunk: str) -> float:
119
+ return 1.0 if "patient" in chunk.lower() else 0.3
120
+ ```
121
+
122
+ Blends with the built-in scoring engine. Errors default to neutral (0.5) — won't crash your pipeline.
123
+
124
+ ## How it works
125
+
126
+ | Stage | What it does |
127
+ |---|---|
128
+ | **Clean** | Strip HTML, scripts, styles. Normalize whitespace and unicode. |
129
+ | **Chunk** | Structure-aware splitting. Preserves headings, code blocks, paragraphs. Configurable size + overlap. |
130
+ | **Dedupe** | Exact, normalized, and near-duplicate removal via fingerprint similarity. |
131
+ | **Score** | Quality score (0–1) based on length, density, structure, duplicates. Warning labels for boilerplate, too-short/long, low-density. |
132
+ | **Report** | JSON, Markdown, or HTML diagnostics with per-chunk scores and recommendations. |
133
+
134
+ ## API
135
+
136
+ ```python
137
+ # Core primitives
138
+ clean_text(text: str) -> str
139
+ chunk_text(text: str, chunk_size=512, overlap=64, mode="word", tokenizer=None) -> list[str]
140
+ dedupe_chunks(chunks, return_stats=False, near_duplicate_threshold=0.9) -> list[str] | DedupeResult
141
+ score_chunks(chunks) -> list[Chunk]
142
+
143
+ # Pipeline
144
+ Pipeline(chunk_size=512, overlap=64, dedupe=True, score=True)
145
+ Pipeline.run(source, progress=None) -> PipelineResult
146
+ Pipeline.stream(source, batch_size=50, progress=None) -> Iterator[PipelineResult]
147
+
148
+ # Extensibility
149
+ register_scorer(name, weight=0.1)(fn)
150
+ clear_scorers()
151
+ ```
152
+
153
+ ## Development
154
+
155
+ ```bash
156
+ python -m venv .venv && source .venv/bin/activate
157
+ pip install -e ".[dev]"
158
+ pytest
159
+ ```
160
+
161
+ ## License
162
+
163
+ [MIT](LICENSE)
164
+
@@ -0,0 +1,129 @@
1
+ # preembed
2
+
3
+ <p align="center">
4
+ <picture>
5
+ <img src="https://raw.githubusercontent.com/AdityaMunot/preembed/main/assets/logo.png" alt="preembed" width="400">
6
+ </picture>
7
+ </p>
8
+
9
+ > Clean, chunk, deduplicate, and score documents before embedding.
10
+
11
+ **preembed** is a high-performance toolkit that sits between your raw documents and your vector database. It turns messy HTML, markdown, logs, and exports into high-quality, LLM-ready chunks — so your RAG pipeline retrieves better context and hallucinates less.
12
+
13
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
14
+ [![Python 3.10+](https://img.shields.io/badge/Python-3.10%2B-blue.svg)](https://www.python.org)
15
+ [![Rust](https://img.shields.io/badge/Rust-Powered-orange.svg)](https://www.rust-lang.org)
16
+
17
+ ## Why
18
+
19
+ Most RAG pipelines embed documents directly — noise, duplicates, and all. The result: wasted tokens, bloated vector stores, and retrieval that returns boilerplate instead of answers.
20
+
21
+ preembed fixes the data before it enters the pipeline:
22
+
23
+ ```
24
+ raw documents → clean → chunk → dedupe → score → embed
25
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26
+ preembed handles this
27
+ ```
28
+
29
+ ## Install
30
+
31
+ ```bash
32
+ pip install preembed
33
+ ```
34
+
35
+ For development (requires Rust toolchain):
36
+
37
+ ```bash
38
+ pip install -e ".[dev]"
39
+ maturin develop --release
40
+ ```
41
+
42
+ ## Quickstart
43
+
44
+ ### Pipeline (recommended)
45
+
46
+ ```python
47
+ from preembed import Pipeline
48
+
49
+ result = Pipeline(chunk_size=512, overlap=64).run("path/to/documents/")
50
+ result.save_report("report.json")
51
+
52
+ print(f"{result.stats.total_chunks} chunks, {result.stats.duplicate_ratio:.0%} duplicates removed")
53
+ ```
54
+
55
+ ### Individual primitives
56
+
57
+ ```python
58
+ from preembed import clean_text, chunk_text, dedupe_chunks, score_chunks
59
+
60
+ text = clean_text("<html><script>tracking()</script><p>Actual content here.</p></html>")
61
+ # → "Actual content here."
62
+
63
+ chunks = chunk_text(text, chunk_size=512, overlap=64)
64
+ chunks = dedupe_chunks(chunks)
65
+ scored = score_chunks(chunks)
66
+ # Each chunk gets a 0-1 quality score + warning labels
67
+ ```
68
+
69
+ ### Streaming (memory-efficient)
70
+
71
+ ```python
72
+ for batch in Pipeline().stream("huge_corpus/", batch_size=50):
73
+ upload_to_vector_db(batch.scored_chunks)
74
+ ```
75
+
76
+ Cross-batch deduplication included. Processes one batch at a time — constant memory regardless of corpus size.
77
+
78
+ ### Custom scoring
79
+
80
+ ```python
81
+ from preembed import register_scorer
82
+
83
+ @register_scorer("domain_relevance", weight=0.15)
84
+ def domain_scorer(chunk: str) -> float:
85
+ return 1.0 if "patient" in chunk.lower() else 0.3
86
+ ```
87
+
88
+ Blends with the built-in scoring engine. Errors default to neutral (0.5) — won't crash your pipeline.
89
+
90
+ ## How it works
91
+
92
+ | Stage | What it does |
93
+ |---|---|
94
+ | **Clean** | Strip HTML, scripts, styles. Normalize whitespace and unicode. |
95
+ | **Chunk** | Structure-aware splitting. Preserves headings, code blocks, paragraphs. Configurable size + overlap. |
96
+ | **Dedupe** | Exact, normalized, and near-duplicate removal via fingerprint similarity. |
97
+ | **Score** | Quality score (0–1) based on length, density, structure, duplicates. Warning labels for boilerplate, too-short/long, low-density. |
98
+ | **Report** | JSON, Markdown, or HTML diagnostics with per-chunk scores and recommendations. |
99
+
100
+ ## API
101
+
102
+ ```python
103
+ # Core primitives
104
+ clean_text(text: str) -> str
105
+ chunk_text(text: str, chunk_size=512, overlap=64, mode="word", tokenizer=None) -> list[str]
106
+ dedupe_chunks(chunks, return_stats=False, near_duplicate_threshold=0.9) -> list[str] | DedupeResult
107
+ score_chunks(chunks) -> list[Chunk]
108
+
109
+ # Pipeline
110
+ Pipeline(chunk_size=512, overlap=64, dedupe=True, score=True)
111
+ Pipeline.run(source, progress=None) -> PipelineResult
112
+ Pipeline.stream(source, batch_size=50, progress=None) -> Iterator[PipelineResult]
113
+
114
+ # Extensibility
115
+ register_scorer(name, weight=0.1)(fn)
116
+ clear_scorers()
117
+ ```
118
+
119
+ ## Development
120
+
121
+ ```bash
122
+ python -m venv .venv && source .venv/bin/activate
123
+ pip install -e ".[dev]"
124
+ pytest
125
+ ```
126
+
127
+ ## License
128
+
129
+ [MIT](LICENSE)
@@ -0,0 +1,60 @@
1
+ [build-system]
2
+ requires = ["maturin>=1.5,<2"]
3
+ build-backend = "maturin"
4
+
5
+ [project]
6
+ name = "preembed"
7
+ version = "0.1.1"
8
+ description = "High-performance document preparation toolkit for LLM and RAG pipelines."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = { file = "LICENSE" }
12
+ authors = [
13
+ { name = "Aditya Munot" },
14
+ ]
15
+ keywords = ["llm", "rag", "chunking", "document-processing", "embeddings"]
16
+ classifiers = [
17
+ "Development Status :: 2 - Pre-Alpha",
18
+ "Environment :: Console",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Operating System :: OS Independent",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
26
+ "Topic :: Text Processing",
27
+ ]
28
+
29
+ [project.urls]
30
+ Homepage = "https://github.com/AdityaMunot/preembed"
31
+ Repository = "https://github.com/AdityaMunot/preembed"
32
+ Documentation = "https://github.com/AdityaMunot/preembed/tree/main/docs"
33
+ Issues = "https://github.com/AdityaMunot/preembed/issues"
34
+ Changelog = "https://github.com/AdityaMunot/preembed/blob/main/CHANGELOG.md"
35
+
36
+ [project.optional-dependencies]
37
+ dev = [
38
+ "hypothesis>=6",
39
+ "maturin>=1.5,<2",
40
+ "pytest>=8",
41
+ "pytest-cov>=5",
42
+ ]
43
+ lint = [
44
+ "ruff>=0.4",
45
+ "mypy>=1.9",
46
+ ]
47
+
48
+ [tool.setuptools.package-data]
49
+ preembed = ["py.typed"]
50
+
51
+ [tool.maturin]
52
+ manifest-path = "rust/Cargo.toml"
53
+ python-source = "python"
54
+ module-name = "preembed.preembed_core"
55
+ features = ["pyo3/extension-module"]
56
+
57
+ [tool.pytest.ini_options]
58
+ testpaths = ["tests"]
59
+ pythonpath = ["python"]
60
+ markers = ["slow: large-input smoke tests (opt in with -m slow)"]
@@ -0,0 +1,46 @@
1
+ """Python API for preembed."""
2
+
3
+ __all__ = [
4
+ "Chunk",
5
+ "ChunkMetadata",
6
+ "DedupeResult",
7
+ "Pipeline",
8
+ "PipelineResult",
9
+ "PipelineStats",
10
+ "PreembedError",
11
+ "Scorer",
12
+ "Tokenizer",
13
+ "clean_text",
14
+ "chunk_text",
15
+ "clear_scorers",
16
+ "dedupe_chunks",
17
+ "register_scorer",
18
+ "score_chunks",
19
+ ]
20
+
21
+ from .pipeline import Pipeline
22
+ from .text import (
23
+ PreembedError,
24
+ chunk_text,
25
+ clean_text,
26
+ clear_scorers,
27
+ dedupe_chunks,
28
+ register_scorer,
29
+ score_chunks,
30
+ )
31
+ from .types import (
32
+ Chunk,
33
+ ChunkMetadata,
34
+ DedupeResult,
35
+ PipelineResult,
36
+ PipelineStats,
37
+ Scorer,
38
+ Tokenizer,
39
+ )
40
+
41
+ try:
42
+ from importlib.metadata import version as _get_version
43
+
44
+ __version__ = _get_version("preembed")
45
+ except Exception:
46
+ __version__ = "0.0.0"