swarmauri_embedding_workspace 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.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2025] [Jacob Stewart @ Swarmauri]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,4 @@
1
+ Swarmauri SDK
2
+
3
+ This package is part of the Swarmauri SDK and is distributed under the
4
+ Apache License, Version 2.0. See LICENSE for the license terms.
@@ -0,0 +1,340 @@
1
+ Metadata-Version: 2.4
2
+ Name: swarmauri_embedding_workspace
3
+ Version: 0.1.0
4
+ Summary: Concatenated hierarchy, ordinal, and content vectors.
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ License-File: NOTICE
8
+ Keywords: swarmauri,workspace,embedding,hierarchy,ordinal
9
+ Author: Jacob Stewart
10
+ Author-email: jacob@swarmauri.com
11
+ Requires-Python: >=3.10,<3.15
12
+ Classifier: Development Status :: 1 - Planning
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Requires-Dist: swarmauri_base (>=0.11.1,<0.12)
19
+ Requires-Dist: swarmauri_core (>=0.11.2,<0.12)
20
+ Project-URL: Repository, https://github.com/swarmauri/swarmauri-sdk
21
+ Description-Content-Type: text/markdown
22
+
23
+ # swarmauri_embedding_workspace
24
+
25
+ <!-- readme-standards:begin branding -->
26
+ <p align="center"><a href="https://github.com/swarmauri/swarmauri-sdk"><img src="https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri.brand.theme.svg" alt="Swarmauri SDK" width="300"></a></p>
27
+ <p align="center"><strong>swarmauri_embedding_workspace</strong></p>
28
+ <p align="center">Concatenated hierarchy, ordinal, and content vectors.</p>
29
+ <p align="center">
30
+ <a href="https://pypi.org/project/swarmauri_embedding_workspace/"><img alt="pypi: swarmauri_embedding_workspace unpublished" src="https://img.shields.io/static/v1?label=pypi&amp;message=swarmauri_embedding_workspace%20unpublished&amp;labelColor=292421&amp;color=805500"></a>
31
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/pyproject.toml"><img alt="Source version: 0.1.0" src="https://img.shields.io/static/v1?label=Source%20version&amp;message=0.1.0&amp;labelColor=292421&amp;color=994525"></a>
32
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/pyproject.toml"><img alt="Python: &gt;=3.10,&lt;3.15" src="https://img.shields.io/static/v1?label=Python&amp;message=%3E%3D3.10%2C%3C3.15&amp;labelColor=292421&amp;color=994525"></a>
33
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/pyproject.toml"><img alt="Layer: standards" src="https://img.shields.io/static/v1?label=Layer&amp;message=standards&amp;labelColor=292421&amp;color=994525"></a>
34
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/README.md#lifecycle-and-migration"><img alt="Lifecycle: active" src="https://img.shields.io/static/v1?label=Lifecycle&amp;message=active&amp;labelColor=292421&amp;color=24654A"></a>
35
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/LICENSE"><img alt="License: Apache-2.0" src="https://img.shields.io/static/v1?label=License&amp;message=Apache-2.0&amp;labelColor=292421&amp;color=994525"></a>
36
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/NOTICE"><img alt="Notice: attribution" src="https://img.shields.io/static/v1?label=Notice&amp;message=attribution&amp;labelColor=292421&amp;color=994525"></a>
37
+ </p>
38
+ <p align="center">
39
+ <a href="https://pypi.org/project/swarmauri_embedding_workspace/"><img alt="pypi downloads: swarmauri_embedding_workspace: unpublished" src="https://img.shields.io/static/v1?label=pypi%20downloads&amp;message=swarmauri_embedding_workspace%3A%20unpublished&amp;labelColor=292421&amp;color=805500"></a>
40
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/README.md"><img alt="README hits: swarmauri_embedding_workspace" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/pkgs/40-standards/swarmauri_embedding_workspace/README.md.svg?label=README%20hits&amp;labelColor=292421&amp;color=08704E"></a>
41
+ </p>
42
+ <p align="center">
43
+ <a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="README standards: CI gate" src="https://img.shields.io/static/v1?label=README%20standards&amp;message=CI%20gate&amp;labelColor=292421&amp;color=67437E"></a>
44
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/tests/unit/test_readme_sources.py"><img alt="Tests: example source" src="https://img.shields.io/static/v1?label=Tests&amp;message=example%20source&amp;labelColor=292421&amp;color=67437E"></a>
45
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/README.md#certification-status"><img alt="Certification: not certified" src="https://img.shields.io/static/v1?label=Certification&amp;message=not%20certified&amp;labelColor=292421&amp;color=805500"></a>
46
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md"><img alt="Governance: repository policy" src="https://img.shields.io/static/v1?label=Governance&amp;message=repository%20policy&amp;labelColor=292421&amp;color=67437E"></a>
47
+ <a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="Evidence: source and CI" src="https://img.shields.io/static/v1?label=Evidence&amp;message=source%20and%20CI&amp;labelColor=292421&amp;color=67437E"></a>
48
+ </p>
49
+ <p align="center"><a href="#overview">Overview</a> · <a href="#installation">Installation</a> · <a href="#quick-start">Quick Start</a> · <a href="#usage">Usage</a> · <a href="#public-api-and-import-surfaces">API</a> · <a href="#contributing">Contributing</a> · <a href="#governance">Governance</a> · <a href="#license">License</a></p>
50
+ <!-- readme-standards:end branding -->
51
+
52
+ ---
53
+
54
+ ## Overview
55
+
56
+ ### Summary
57
+
58
+ Concatenated hierarchy, ordinal, and content vectors.
59
+
60
+ ### Why This Package
61
+
62
+ `WorkspaceEmbedding` provides a separately installable implementation for Swarmauri callers.
63
+
64
+ ### When to Use
65
+
66
+ The example yields a vector with 148 values. Replace the illustrative content encoder with your fitted text embedding and give it a stable revision.
67
+
68
+ ### Features
69
+
70
+ - Concatenated hierarchy, ordinal, and content vectors.
71
+ - Use `WorkspaceEmbedding` directly from Python.
72
+
73
+ ### Non-Goals
74
+
75
+ The public surface is the component and its documented options.
76
+
77
+ ---
78
+
79
+ ## Getting Started
80
+
81
+ ### Prerequisites
82
+
83
+ Use Python 3.10 through 3.14. The source example runs in the SDK workspace.
84
+
85
+ ### Installation
86
+
87
+ #### Install with uv
88
+
89
+ <!-- readme-standards:begin installation.uv -->
90
+ `swarmauri_embedding_workspace` is not declared published. From the source checkout:
91
+
92
+ ```bash
93
+ uv pip install .
94
+ ```
95
+ <!-- readme-standards:end installation.uv -->
96
+
97
+ #### Install with pip
98
+
99
+ <!-- readme-standards:begin installation.pip -->
100
+ `swarmauri_embedding_workspace` is not declared published. From the source checkout:
101
+
102
+ ```bash
103
+ python -m pip install .
104
+ ```
105
+ <!-- readme-standards:end installation.pip -->
106
+
107
+ #### Install with Poetry
108
+
109
+ <!-- readme-standards:begin installation.poetry -->
110
+ `swarmauri_embedding_workspace` is not declared published. From a separate Poetry project, replace the path with your checkout:
111
+
112
+ ```bash
113
+ poetry add /path/to/swarmauri_embedding_workspace
114
+ ```
115
+ <!-- readme-standards:end installation.poetry -->
116
+
117
+ ### Quick Start
118
+
119
+ #### Example
120
+
121
+ <!-- readme-standards:begin example.quick-start -->
122
+ Source: [docs/readme/quick_start.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/docs/readme/quick_start.py).
123
+
124
+ ```python
125
+ from swarmauri_base.vectors.VectorBase import VectorBase
126
+ from swarmauri_embedding_workspace.WorkspaceEmbedding import (
127
+ WorkspaceChunk,
128
+ WorkspaceEmbedding,
129
+ )
130
+
131
+
132
+ def encode(text):
133
+ return VectorBase(value=[float(len(text)), 1.0])
134
+
135
+
136
+ embedding = WorkspaceEmbedding(
137
+ content_encoder=encode, content_dimensions=2, encoder_revision="demo-1"
138
+ )
139
+ chunk = WorkspaceChunk("src/retries.py", 0, 1, "retry", 1, 1)
140
+ print(len(embedding.infer_vector(chunk).value))
141
+ ```
142
+ <!-- readme-standards:end example.quick-start -->
143
+
144
+ #### Expected Result
145
+
146
+ The example demonstrates the documented `swarmauri_embedding_workspace` source boundary or workflow. Complete its required configuration first. README CI checks the maintained source’s syntax and declarations; it does not claim that external services or the application workflow were exercised.
147
+
148
+ ---
149
+
150
+ ## Usage
151
+
152
+ ### Common Workflows
153
+
154
+ <!-- readme-standards:begin example.usage -->
155
+ Source: [docs/readme/usage.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/docs/readme/usage.py).
156
+
157
+ ```python
158
+ from swarmauri_base.vectors.VectorBase import VectorBase
159
+ from swarmauri_embedding_workspace.WorkspaceEmbedding import (
160
+ WorkspaceChunk,
161
+ WorkspaceEmbedding,
162
+ )
163
+
164
+
165
+ def encode(text):
166
+ return VectorBase(value=[float(len(text)), 1.0])
167
+
168
+
169
+ embedding = WorkspaceEmbedding(
170
+ content_encoder=encode, content_dimensions=2, encoder_revision="demo-1"
171
+ )
172
+ chunk = WorkspaceChunk("src/retries.py", 0, 1, "retry", 1, 1)
173
+ print(len(embedding.infer_vector(chunk).value))
174
+ ```
175
+ <!-- readme-standards:end example.usage -->
176
+
177
+ Pass the store to `AgentRunner` to persist a conversation. Use `runner.load(run_id)`
178
+ to read the typed run state.
179
+
180
+ ### Configuration
181
+
182
+ Configure the component at construction. See [the source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/swarmauri_embedding_workspace/WorkspaceEmbedding.py) for supported inputs.
183
+
184
+ ### Error Handling
185
+
186
+ Invalid inputs raise an exception before a result is returned. See the API and package regression tests for concrete cases.
187
+
188
+ ### Best Practices
189
+
190
+ Use the provided example to exercise the component with your configuration before depending on it.
191
+
192
+ ---
193
+
194
+ ## Package Boundary
195
+
196
+ ### What It Owns
197
+
198
+ Concatenated hierarchy, ordinal, and content vectors.
199
+
200
+ ### Public API and Import Surfaces
201
+
202
+ Import `WorkspaceEmbedding` from `swarmauri_embedding_workspace`.
203
+
204
+ ### Entry Points
205
+
206
+ <!-- readme-standards:begin entry-points -->
207
+ - `swarmauri.embeddings` → `WorkspaceEmbedding` → `swarmauri_embedding_workspace:WorkspaceEmbedding`
208
+ <!-- readme-standards:end entry-points -->
209
+
210
+ ### Injected Dependencies
211
+
212
+ The package manifest declares the Swarmauri collaborators used by this component.
213
+
214
+ ### Protocol Consumers
215
+
216
+ Applications can construct the component directly using the import shown above.
217
+
218
+ ### Extensions
219
+
220
+ Use the corresponding SDK interface when adding another implementation.
221
+
222
+ ---
223
+
224
+ ## Operations and Readiness
225
+
226
+ ### Operational Requirements
227
+
228
+ Configure the component as shown in the example. Match the lifetime of stored records and injected collaborators to the application.
229
+
230
+ ### Health and Observability
231
+
232
+ Use package tests and inspect exceptions from component calls.
233
+
234
+ ### Security and Resource Limits
235
+
236
+ Supply application-appropriate input sizes and access controls for your use case.
237
+
238
+ ### Compatibility
239
+
240
+ Version 0.1.0 declares Python 3.10 through 3.14.
241
+
242
+ ---
243
+
244
+ ## Verification
245
+
246
+ ### Tests
247
+
248
+ Run `uv run --package swarmauri_embedding_workspace pytest` from the package directory.
249
+
250
+ ### Certification Status
251
+
252
+ Planning release.
253
+
254
+ ### Evidence
255
+
256
+ The source examples and package tests document the supported behavior.
257
+
258
+ ---
259
+
260
+ ## FAQ
261
+
262
+ ### Why
263
+
264
+ Concatenated hierarchy, ordinal, and content vectors.
265
+
266
+ ### How
267
+
268
+ Run the source example under Getting Started.
269
+
270
+ ### When
271
+
272
+ Re-run the package tests after changing the backend, distance model, or embedding configuration used by your application.
273
+
274
+ ---
275
+
276
+ ## Documentation and Related Packages
277
+
278
+ ### More Documentation
279
+
280
+ See the [component source](https://github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/40-standards/swarmauri_embedding_workspace).
281
+
282
+ ### Related Packages
283
+
284
+ See [swarmauri-core](https://github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/10-interfaces/swarmauri_core) for interfaces and shared types.
285
+
286
+ ### Project Links
287
+
288
+ <!-- readme-standards:begin project-links -->
289
+ - [Repository](https://github.com/swarmauri/swarmauri-sdk)
290
+ - [pypi: swarmauri_embedding_workspace](https://pypi.org/project/swarmauri_embedding_workspace/)
291
+ <!-- readme-standards:end project-links -->
292
+
293
+ ---
294
+
295
+ ## Contributing
296
+
297
+ ### How to Contribute
298
+
299
+ See the [contribution guide](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md).
300
+
301
+ ### Development Setup
302
+
303
+ Use the SDK workspace to run package tests and the README examples.
304
+
305
+ ### Notes for Maintainers
306
+
307
+ Update both maintained examples when changing the public API.
308
+
309
+ ---
310
+
311
+ ## Governance
312
+
313
+ ### Ownership and Decision Making
314
+
315
+ The SDK maintainer review process applies.
316
+
317
+ ### Standards and Policies
318
+
319
+ See the [README policy](https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md).
320
+
321
+ ### Lifecycle and Migration
322
+
323
+ Planning version 0.1.0. Install from a checkout while the package is unpublished.
324
+
325
+ ---
326
+
327
+ ## License and Attribution
328
+
329
+ ### License
330
+
331
+ <!-- readme-standards:begin license -->
332
+ Licensed under `Apache-2.0`. See [LICENSE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/LICENSE).
333
+ <!-- readme-standards:end license -->
334
+
335
+ ### Notices
336
+
337
+ <!-- readme-standards:begin notices -->
338
+ See [NOTICE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/NOTICE) for attribution.
339
+ <!-- readme-standards:end notices -->
340
+
@@ -0,0 +1,317 @@
1
+ # swarmauri_embedding_workspace
2
+
3
+ <!-- readme-standards:begin branding -->
4
+ <p align="center"><a href="https://github.com/swarmauri/swarmauri-sdk"><img src="https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri.brand.theme.svg" alt="Swarmauri SDK" width="300"></a></p>
5
+ <p align="center"><strong>swarmauri_embedding_workspace</strong></p>
6
+ <p align="center">Concatenated hierarchy, ordinal, and content vectors.</p>
7
+ <p align="center">
8
+ <a href="https://pypi.org/project/swarmauri_embedding_workspace/"><img alt="pypi: swarmauri_embedding_workspace unpublished" src="https://img.shields.io/static/v1?label=pypi&amp;message=swarmauri_embedding_workspace%20unpublished&amp;labelColor=292421&amp;color=805500"></a>
9
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/pyproject.toml"><img alt="Source version: 0.1.0" src="https://img.shields.io/static/v1?label=Source%20version&amp;message=0.1.0&amp;labelColor=292421&amp;color=994525"></a>
10
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/pyproject.toml"><img alt="Python: &gt;=3.10,&lt;3.15" src="https://img.shields.io/static/v1?label=Python&amp;message=%3E%3D3.10%2C%3C3.15&amp;labelColor=292421&amp;color=994525"></a>
11
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/pyproject.toml"><img alt="Layer: standards" src="https://img.shields.io/static/v1?label=Layer&amp;message=standards&amp;labelColor=292421&amp;color=994525"></a>
12
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/README.md#lifecycle-and-migration"><img alt="Lifecycle: active" src="https://img.shields.io/static/v1?label=Lifecycle&amp;message=active&amp;labelColor=292421&amp;color=24654A"></a>
13
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/LICENSE"><img alt="License: Apache-2.0" src="https://img.shields.io/static/v1?label=License&amp;message=Apache-2.0&amp;labelColor=292421&amp;color=994525"></a>
14
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/NOTICE"><img alt="Notice: attribution" src="https://img.shields.io/static/v1?label=Notice&amp;message=attribution&amp;labelColor=292421&amp;color=994525"></a>
15
+ </p>
16
+ <p align="center">
17
+ <a href="https://pypi.org/project/swarmauri_embedding_workspace/"><img alt="pypi downloads: swarmauri_embedding_workspace: unpublished" src="https://img.shields.io/static/v1?label=pypi%20downloads&amp;message=swarmauri_embedding_workspace%3A%20unpublished&amp;labelColor=292421&amp;color=805500"></a>
18
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/README.md"><img alt="README hits: swarmauri_embedding_workspace" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/pkgs/40-standards/swarmauri_embedding_workspace/README.md.svg?label=README%20hits&amp;labelColor=292421&amp;color=08704E"></a>
19
+ </p>
20
+ <p align="center">
21
+ <a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="README standards: CI gate" src="https://img.shields.io/static/v1?label=README%20standards&amp;message=CI%20gate&amp;labelColor=292421&amp;color=67437E"></a>
22
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/tests/unit/test_readme_sources.py"><img alt="Tests: example source" src="https://img.shields.io/static/v1?label=Tests&amp;message=example%20source&amp;labelColor=292421&amp;color=67437E"></a>
23
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/README.md#certification-status"><img alt="Certification: not certified" src="https://img.shields.io/static/v1?label=Certification&amp;message=not%20certified&amp;labelColor=292421&amp;color=805500"></a>
24
+ <a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md"><img alt="Governance: repository policy" src="https://img.shields.io/static/v1?label=Governance&amp;message=repository%20policy&amp;labelColor=292421&amp;color=67437E"></a>
25
+ <a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="Evidence: source and CI" src="https://img.shields.io/static/v1?label=Evidence&amp;message=source%20and%20CI&amp;labelColor=292421&amp;color=67437E"></a>
26
+ </p>
27
+ <p align="center"><a href="#overview">Overview</a> · <a href="#installation">Installation</a> · <a href="#quick-start">Quick Start</a> · <a href="#usage">Usage</a> · <a href="#public-api-and-import-surfaces">API</a> · <a href="#contributing">Contributing</a> · <a href="#governance">Governance</a> · <a href="#license">License</a></p>
28
+ <!-- readme-standards:end branding -->
29
+
30
+ ---
31
+
32
+ ## Overview
33
+
34
+ ### Summary
35
+
36
+ Concatenated hierarchy, ordinal, and content vectors.
37
+
38
+ ### Why This Package
39
+
40
+ `WorkspaceEmbedding` provides a separately installable implementation for Swarmauri callers.
41
+
42
+ ### When to Use
43
+
44
+ The example yields a vector with 148 values. Replace the illustrative content encoder with your fitted text embedding and give it a stable revision.
45
+
46
+ ### Features
47
+
48
+ - Concatenated hierarchy, ordinal, and content vectors.
49
+ - Use `WorkspaceEmbedding` directly from Python.
50
+
51
+ ### Non-Goals
52
+
53
+ The public surface is the component and its documented options.
54
+
55
+ ---
56
+
57
+ ## Getting Started
58
+
59
+ ### Prerequisites
60
+
61
+ Use Python 3.10 through 3.14. The source example runs in the SDK workspace.
62
+
63
+ ### Installation
64
+
65
+ #### Install with uv
66
+
67
+ <!-- readme-standards:begin installation.uv -->
68
+ `swarmauri_embedding_workspace` is not declared published. From the source checkout:
69
+
70
+ ```bash
71
+ uv pip install .
72
+ ```
73
+ <!-- readme-standards:end installation.uv -->
74
+
75
+ #### Install with pip
76
+
77
+ <!-- readme-standards:begin installation.pip -->
78
+ `swarmauri_embedding_workspace` is not declared published. From the source checkout:
79
+
80
+ ```bash
81
+ python -m pip install .
82
+ ```
83
+ <!-- readme-standards:end installation.pip -->
84
+
85
+ #### Install with Poetry
86
+
87
+ <!-- readme-standards:begin installation.poetry -->
88
+ `swarmauri_embedding_workspace` is not declared published. From a separate Poetry project, replace the path with your checkout:
89
+
90
+ ```bash
91
+ poetry add /path/to/swarmauri_embedding_workspace
92
+ ```
93
+ <!-- readme-standards:end installation.poetry -->
94
+
95
+ ### Quick Start
96
+
97
+ #### Example
98
+
99
+ <!-- readme-standards:begin example.quick-start -->
100
+ Source: [docs/readme/quick_start.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/docs/readme/quick_start.py).
101
+
102
+ ```python
103
+ from swarmauri_base.vectors.VectorBase import VectorBase
104
+ from swarmauri_embedding_workspace.WorkspaceEmbedding import (
105
+ WorkspaceChunk,
106
+ WorkspaceEmbedding,
107
+ )
108
+
109
+
110
+ def encode(text):
111
+ return VectorBase(value=[float(len(text)), 1.0])
112
+
113
+
114
+ embedding = WorkspaceEmbedding(
115
+ content_encoder=encode, content_dimensions=2, encoder_revision="demo-1"
116
+ )
117
+ chunk = WorkspaceChunk("src/retries.py", 0, 1, "retry", 1, 1)
118
+ print(len(embedding.infer_vector(chunk).value))
119
+ ```
120
+ <!-- readme-standards:end example.quick-start -->
121
+
122
+ #### Expected Result
123
+
124
+ The example demonstrates the documented `swarmauri_embedding_workspace` source boundary or workflow. Complete its required configuration first. README CI checks the maintained source’s syntax and declarations; it does not claim that external services or the application workflow were exercised.
125
+
126
+ ---
127
+
128
+ ## Usage
129
+
130
+ ### Common Workflows
131
+
132
+ <!-- readme-standards:begin example.usage -->
133
+ Source: [docs/readme/usage.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/docs/readme/usage.py).
134
+
135
+ ```python
136
+ from swarmauri_base.vectors.VectorBase import VectorBase
137
+ from swarmauri_embedding_workspace.WorkspaceEmbedding import (
138
+ WorkspaceChunk,
139
+ WorkspaceEmbedding,
140
+ )
141
+
142
+
143
+ def encode(text):
144
+ return VectorBase(value=[float(len(text)), 1.0])
145
+
146
+
147
+ embedding = WorkspaceEmbedding(
148
+ content_encoder=encode, content_dimensions=2, encoder_revision="demo-1"
149
+ )
150
+ chunk = WorkspaceChunk("src/retries.py", 0, 1, "retry", 1, 1)
151
+ print(len(embedding.infer_vector(chunk).value))
152
+ ```
153
+ <!-- readme-standards:end example.usage -->
154
+
155
+ Pass the store to `AgentRunner` to persist a conversation. Use `runner.load(run_id)`
156
+ to read the typed run state.
157
+
158
+ ### Configuration
159
+
160
+ Configure the component at construction. See [the source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/swarmauri_embedding_workspace/WorkspaceEmbedding.py) for supported inputs.
161
+
162
+ ### Error Handling
163
+
164
+ Invalid inputs raise an exception before a result is returned. See the API and package regression tests for concrete cases.
165
+
166
+ ### Best Practices
167
+
168
+ Use the provided example to exercise the component with your configuration before depending on it.
169
+
170
+ ---
171
+
172
+ ## Package Boundary
173
+
174
+ ### What It Owns
175
+
176
+ Concatenated hierarchy, ordinal, and content vectors.
177
+
178
+ ### Public API and Import Surfaces
179
+
180
+ Import `WorkspaceEmbedding` from `swarmauri_embedding_workspace`.
181
+
182
+ ### Entry Points
183
+
184
+ <!-- readme-standards:begin entry-points -->
185
+ - `swarmauri.embeddings` → `WorkspaceEmbedding` → `swarmauri_embedding_workspace:WorkspaceEmbedding`
186
+ <!-- readme-standards:end entry-points -->
187
+
188
+ ### Injected Dependencies
189
+
190
+ The package manifest declares the Swarmauri collaborators used by this component.
191
+
192
+ ### Protocol Consumers
193
+
194
+ Applications can construct the component directly using the import shown above.
195
+
196
+ ### Extensions
197
+
198
+ Use the corresponding SDK interface when adding another implementation.
199
+
200
+ ---
201
+
202
+ ## Operations and Readiness
203
+
204
+ ### Operational Requirements
205
+
206
+ Configure the component as shown in the example. Match the lifetime of stored records and injected collaborators to the application.
207
+
208
+ ### Health and Observability
209
+
210
+ Use package tests and inspect exceptions from component calls.
211
+
212
+ ### Security and Resource Limits
213
+
214
+ Supply application-appropriate input sizes and access controls for your use case.
215
+
216
+ ### Compatibility
217
+
218
+ Version 0.1.0 declares Python 3.10 through 3.14.
219
+
220
+ ---
221
+
222
+ ## Verification
223
+
224
+ ### Tests
225
+
226
+ Run `uv run --package swarmauri_embedding_workspace pytest` from the package directory.
227
+
228
+ ### Certification Status
229
+
230
+ Planning release.
231
+
232
+ ### Evidence
233
+
234
+ The source examples and package tests document the supported behavior.
235
+
236
+ ---
237
+
238
+ ## FAQ
239
+
240
+ ### Why
241
+
242
+ Concatenated hierarchy, ordinal, and content vectors.
243
+
244
+ ### How
245
+
246
+ Run the source example under Getting Started.
247
+
248
+ ### When
249
+
250
+ Re-run the package tests after changing the backend, distance model, or embedding configuration used by your application.
251
+
252
+ ---
253
+
254
+ ## Documentation and Related Packages
255
+
256
+ ### More Documentation
257
+
258
+ See the [component source](https://github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/40-standards/swarmauri_embedding_workspace).
259
+
260
+ ### Related Packages
261
+
262
+ See [swarmauri-core](https://github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/10-interfaces/swarmauri_core) for interfaces and shared types.
263
+
264
+ ### Project Links
265
+
266
+ <!-- readme-standards:begin project-links -->
267
+ - [Repository](https://github.com/swarmauri/swarmauri-sdk)
268
+ - [pypi: swarmauri_embedding_workspace](https://pypi.org/project/swarmauri_embedding_workspace/)
269
+ <!-- readme-standards:end project-links -->
270
+
271
+ ---
272
+
273
+ ## Contributing
274
+
275
+ ### How to Contribute
276
+
277
+ See the [contribution guide](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md).
278
+
279
+ ### Development Setup
280
+
281
+ Use the SDK workspace to run package tests and the README examples.
282
+
283
+ ### Notes for Maintainers
284
+
285
+ Update both maintained examples when changing the public API.
286
+
287
+ ---
288
+
289
+ ## Governance
290
+
291
+ ### Ownership and Decision Making
292
+
293
+ The SDK maintainer review process applies.
294
+
295
+ ### Standards and Policies
296
+
297
+ See the [README policy](https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md).
298
+
299
+ ### Lifecycle and Migration
300
+
301
+ Planning version 0.1.0. Install from a checkout while the package is unpublished.
302
+
303
+ ---
304
+
305
+ ## License and Attribution
306
+
307
+ ### License
308
+
309
+ <!-- readme-standards:begin license -->
310
+ Licensed under `Apache-2.0`. See [LICENSE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/LICENSE).
311
+ <!-- readme-standards:end license -->
312
+
313
+ ### Notices
314
+
315
+ <!-- readme-standards:begin notices -->
316
+ See [NOTICE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/NOTICE) for attribution.
317
+ <!-- readme-standards:end notices -->
@@ -0,0 +1,84 @@
1
+ [project]
2
+ name = "swarmauri_embedding_workspace"
3
+ version = "0.1.0"
4
+ description = "Concatenated hierarchy, ordinal, and content vectors."
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ requires-python = ">=3.10,<3.15"
8
+ authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
9
+ keywords = ["swarmauri", "workspace", "embedding", "hierarchy", "ordinal"]
10
+ classifiers = [
11
+ "Development Status :: 1 - Planning",
12
+ "Programming Language :: Python :: 3.10",
13
+ "Programming Language :: Python :: 3.11",
14
+ "Programming Language :: Python :: 3.12",
15
+ "Programming Language :: Python :: 3.13",
16
+ "Programming Language :: Python :: 3.14",
17
+ ]
18
+ dependencies = ["swarmauri_core>=0.11.2,<0.12", "swarmauri_base>=0.11.1,<0.12"]
19
+ license-files = ["LICENSE", "NOTICE"]
20
+
21
+ [project.urls]
22
+ Repository = "https://github.com/swarmauri/swarmauri-sdk"
23
+
24
+ [project.entry-points."swarmauri.embeddings"]
25
+ WorkspaceEmbedding = "swarmauri_embedding_workspace:WorkspaceEmbedding"
26
+
27
+ [tool.uv.sources]
28
+ swarmauri_core = { workspace = true }
29
+ swarmauri_base = { workspace = true }
30
+
31
+ [tool.readme_standards]
32
+ policy = "package-guide-v1"
33
+ readme = "README.md"
34
+ brand = "swarmauri"
35
+ brand_catalog = "../../../tools/readme/brands.toml"
36
+ repository = "https://github.com/swarmauri/swarmauri-sdk"
37
+ ref = "master"
38
+ package_path = "pkgs/40-standards/swarmauri_embedding_workspace"
39
+ layer = "standards"
40
+ lifecycle = "active"
41
+ license_file = "LICENSE"
42
+ notice_file = "NOTICE"
43
+
44
+ [tool.readme_standards.distributions.pypi]
45
+ name = "swarmauri_embedding_workspace"
46
+ published = false
47
+
48
+ [tool.readme_standards.examples.quick_start]
49
+ source = "docs/readme/quick_start.py"
50
+ test = "tests/unit/test_readme_sources.py"
51
+ language = "python"
52
+ expected_exit_code = 0
53
+
54
+ [tool.readme_standards.examples.usage]
55
+ source = "docs/readme/usage.py"
56
+ test = "tests/unit/test_readme_sources.py"
57
+ language = "python"
58
+ expected_exit_code = 0
59
+
60
+ [tool.readme_standards.statuses.readme]
61
+ label = "CI gate"
62
+ url = "https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"
63
+
64
+ [tool.readme_standards.statuses.tests]
65
+ label = "example source"
66
+ url = "https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/tests/unit/test_readme_sources.py"
67
+
68
+ [tool.readme_standards.statuses.certification]
69
+ label = "not certified"
70
+ url = "https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/40-standards/swarmauri_embedding_workspace/README.md#certification-status"
71
+
72
+ [tool.readme_standards.statuses.governance]
73
+ label = "repository policy"
74
+ url = "https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md"
75
+
76
+ [tool.readme_standards.statuses.evidence]
77
+ label = "source and CI"
78
+ url = "https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"
79
+ [build-system]
80
+ requires = ["poetry-core>=2.0"]
81
+ build-backend = "poetry.core.masonry.api"
82
+
83
+ [dependency-groups]
84
+ dev = ["pytest>=8.0", "ruff>=0.9.9", "readme-standards==0.1.6; python_version >= \"3.11\""]
@@ -0,0 +1,187 @@
1
+ from dataclasses import dataclass
2
+ from hashlib import blake2b
3
+ from math import exp, hypot, isfinite, sqrt
4
+ from pathlib import PureWindowsPath
5
+ from typing import Callable, Literal, Sequence
6
+
7
+ from pydantic import Field
8
+ from swarmauri_base.ComponentBase import ComponentBase
9
+ from swarmauri_base.embeddings.EmbeddingBase import EmbeddingBase
10
+ from swarmauri_base.vectors.VectorBase import VectorBase
11
+ from swarmauri_core.vectors.IVector import IVector
12
+
13
+
14
+ def workspace_path(path: str) -> str:
15
+ """Validate a canonical repository-relative path, preserving case."""
16
+ normalized = path.replace(chr(92), "/")
17
+ parts = normalized.split("/")
18
+ if PureWindowsPath(path).drive or any(
19
+ part in {"", ".", ".."} for part in parts
20
+ ):
21
+ raise ValueError(
22
+ "path must contain canonical workspace-relative components"
23
+ )
24
+ return normalized
25
+
26
+
27
+ @dataclass(frozen=True)
28
+ class WorkspaceChunk:
29
+ path: str
30
+ ordinal: int
31
+ total_chunks: int
32
+ content: str
33
+ start_line: int
34
+ end_line: int
35
+
36
+ def __post_init__(self) -> None:
37
+ object.__setattr__(self, "path", workspace_path(self.path))
38
+ if not 0 <= self.ordinal < self.total_chunks:
39
+ raise ValueError("chunk ordinal must be within the file")
40
+ if not 1 <= self.start_line <= self.end_line:
41
+ raise ValueError("source lines must be one-based and ordered")
42
+
43
+
44
+ @dataclass(frozen=True)
45
+ class WorkspaceQuery:
46
+ content: str | None = None
47
+ path: str | None = None
48
+ ordinal: int | None = None
49
+ relative_position: float | None = None
50
+
51
+ def __post_init__(self) -> None:
52
+ if self.path is not None:
53
+ object.__setattr__(self, "path", workspace_path(self.path))
54
+ if self.ordinal is not None and self.ordinal < 0:
55
+ raise ValueError("chunk ordinal must be non-negative")
56
+ if (
57
+ self.relative_position is not None
58
+ and not 0 <= self.relative_position <= 1
59
+ ):
60
+ raise ValueError("relative position must be between zero and one")
61
+ if (
62
+ not self.content
63
+ and self.path is None
64
+ and self.ordinal is None
65
+ and self.relative_position is None
66
+ ):
67
+ raise ValueError("provide at least one query signal")
68
+
69
+
70
+ def _normalize(values: list[float]) -> list[float]:
71
+ norm = hypot(*values)
72
+ if not isfinite(norm) or norm == 0:
73
+ raise ValueError("embedding block must have a finite, positive norm")
74
+ return [value / norm for value in values]
75
+
76
+
77
+ def _ordinal_channel(position: float | None) -> list[float]:
78
+ if position is None:
79
+ return [0.0] * 9
80
+ return _normalize(
81
+ [exp(-32 * (position - index / 8) ** 2) for index in range(9)]
82
+ )
83
+
84
+
85
+ @ComponentBase.register_type(EmbeddingBase, "WorkspaceEmbedding")
86
+ class WorkspaceEmbedding(EmbeddingBase):
87
+ """Concatenate path hierarchy, ordinal, and content vectors."""
88
+
89
+ type: Literal["WorkspaceEmbedding"] = "WorkspaceEmbedding"
90
+ content_encoder: Callable[[str], IVector] = Field(
91
+ exclude=True, repr=False, frozen=True
92
+ )
93
+ content_dimensions: int = Field(gt=0, frozen=True)
94
+ path_dimensions: int = Field(default=128, ge=8, frozen=True)
95
+ path_weight: float = Field(
96
+ default=1, gt=0, allow_inf_nan=False, frozen=True
97
+ )
98
+ ordinal_weight: float = Field(
99
+ default=1, gt=0, allow_inf_nan=False, frozen=True
100
+ )
101
+ content_weight: float = Field(
102
+ default=1, gt=0, allow_inf_nan=False, frozen=True
103
+ )
104
+ encoder_revision: str = Field(min_length=1, frozen=True)
105
+
106
+ @property
107
+ def dimensions(self) -> int:
108
+ return self.path_dimensions + 18 + self.content_dimensions
109
+
110
+ def _path(self, path: str | None) -> list[float]:
111
+ block = [0.0] * self.path_dimensions
112
+ if path is None:
113
+ return block
114
+ parts = path.split("/")
115
+ for depth in range(1, len(parts) + 1):
116
+ prefix = "/".join(parts[:depth])
117
+ code = int.from_bytes(
118
+ blake2b(prefix.encode(), digest_size=8).digest(), "big"
119
+ )
120
+ block[code % len(block)] += 1
121
+ return _normalize(block)
122
+
123
+ def _content(self, text: str | None) -> list[float]:
124
+ if not text:
125
+ return [0.0] * self.content_dimensions
126
+ vector = self.content_encoder(text)
127
+ values = list(vector.value)
128
+ if len(values) != self.content_dimensions:
129
+ raise ValueError("content encoder returned an unexpected width")
130
+ return _normalize(values)
131
+
132
+ def infer_vector(
133
+ self, data: WorkspaceChunk | WorkspaceQuery | str, *args, **kwargs
134
+ ) -> IVector:
135
+ if isinstance(data, str):
136
+ data = WorkspaceQuery(content=data)
137
+ if isinstance(data, WorkspaceChunk):
138
+ position = (
139
+ data.ordinal / (data.total_chunks - 1)
140
+ if data.total_chunks > 1
141
+ else 0.0
142
+ )
143
+ else:
144
+ position = data.relative_position
145
+ ordinal = data.ordinal
146
+ absolute = ordinal / (ordinal + 8) if ordinal is not None else None
147
+ ordinal_block = _ordinal_channel(absolute) + _ordinal_channel(position)
148
+ # Fixed scaling keeps query masks and indexed vector blocks compatible.
149
+ blocks = (
150
+ (self._path(data.path), self.path_weight),
151
+ (ordinal_block, self.ordinal_weight / 2),
152
+ (self._content(data.content), self.content_weight),
153
+ )
154
+ return VectorBase(
155
+ value=[
156
+ value * sqrt(weight)
157
+ for block, weight in blocks
158
+ for value in block
159
+ ]
160
+ )
161
+
162
+ def fit(self, data: object) -> None:
163
+ """The configured content encoder supplies all learned parameters."""
164
+
165
+ def transform(
166
+ self, data: Sequence[WorkspaceChunk | WorkspaceQuery | str] | str
167
+ ) -> list[IVector]:
168
+ items = [data] if isinstance(data, str) else data
169
+ return [self.infer_vector(item) for item in items]
170
+
171
+ def fit_transform(
172
+ self, data: Sequence[WorkspaceChunk | WorkspaceQuery | str] | str
173
+ ) -> list[IVector]:
174
+ return self.transform(data)
175
+
176
+ def extract_features(self) -> list[str]:
177
+ return ["path", "ordinal", "content"]
178
+
179
+ def save_model(self, path: str) -> None:
180
+ raise NotImplementedError(
181
+ "Persist the injected content encoder in the application"
182
+ )
183
+
184
+ def load_model(self, path: str) -> None:
185
+ raise NotImplementedError(
186
+ "Load the content encoder and inject it at construction"
187
+ )
@@ -0,0 +1,14 @@
1
+ from importlib.metadata import PackageNotFoundError, version
2
+
3
+ from .WorkspaceEmbedding import (
4
+ WorkspaceChunk,
5
+ WorkspaceEmbedding,
6
+ WorkspaceQuery,
7
+ )
8
+
9
+ try:
10
+ __version__ = version("swarmauri_embedding_workspace")
11
+ except PackageNotFoundError:
12
+ __version__ = "0.1.0"
13
+
14
+ __all__ = ["WorkspaceChunk", "WorkspaceEmbedding", "WorkspaceQuery"]