ruvector-attention 0.2.0__py3-none-any.whl

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,37 @@
1
+ """Validated Python convenience APIs backed by RuVector Rust."""
2
+ import numpy as np
3
+
4
+ _MAX_DIM = 65536
5
+
6
+ def _integer(value, name, upper=_MAX_DIM):
7
+ if isinstance(value, bool) or not isinstance(value, int) or not 1 <= value <= upper:
8
+ raise ValueError(f"{name} must be an integer in [1, {upper}]")
9
+ return value
10
+
11
+ def _array(value, ndim, name):
12
+ data = np.ascontiguousarray(value, dtype=np.float32)
13
+ if data.ndim != ndim or not data.size or data.shape[-1] > _MAX_DIM:
14
+ raise ValueError(f"{name} has an invalid or empty shape")
15
+ if not np.isfinite(data).all():
16
+ raise ValueError(f"{name} must be finite")
17
+ return data
18
+
19
+ from dataclasses import dataclass
20
+ from ruvector import AttentionReranker
21
+ __all__ = ["AttentionResult", "attend", "AttentionReranker"]
22
+
23
+ @dataclass(frozen=True)
24
+ class AttentionResult:
25
+ blended: np.ndarray
26
+ weights: np.ndarray
27
+
28
+ def attend(query, candidates) -> AttentionResult:
29
+ """Native scaled dot product attention; keys and values are candidates."""
30
+ q = _array(query, 1, "query")
31
+ data = _array(candidates, 2, "candidates")
32
+ if data.shape[1] != len(q):
33
+ raise ValueError("query and candidate dimensions must match")
34
+ blended, weights = AttentionReranker(len(q)).rerank(q, data)
35
+ if not np.isfinite(blended).all() or not np.isfinite(weights).all():
36
+ raise ValueError("attention overflow; rescale input")
37
+ return AttentionResult(blended, weights)
File without changes
@@ -0,0 +1,56 @@
1
+ Metadata-Version: 2.4
2
+ Name: ruvector-attention
3
+ Version: 0.2.0
4
+ Summary: Native scaled dot product attention for embedding aggregation.
5
+ Project-URL: Homepage, https://github.com/ruvnet/RuVector
6
+ Project-URL: Documentation, https://github.com/ruvnet/RuVector/tree/main/python/portfolio/ruvector-attention
7
+ Project-URL: Repository, https://github.com/ruvnet/RuVector
8
+ Project-URL: Issues, https://github.com/ruvnet/RuVector/issues
9
+ Project-URL: Changelog, https://github.com/ruvnet/RuVector/blob/main/python/portfolio/CHANGELOG.md
10
+ Author: RuVector Team
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Keywords: ai,attention,embeddings,rust,ruvector
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Rust
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Requires-Python: >=3.10
19
+ Requires-Dist: numpy>=1.21
20
+ Requires-Dist: ruvector==0.1.3
21
+ Description-Content-Type: text/markdown
22
+
23
+ # ruvector-attention
24
+
25
+ ![RuVector attention animated overview](https://raw.githubusercontent.com/ruvnet/RuVector/main/docs/python-portfolio/attention.svg)
26
+
27
+ Native scaled dot product attention for embedding aggregation.
28
+
29
+ ## Getting started
30
+
31
+ Requires Python 3.10 or later and a platform supported by the `ruvector==0.1.3` native wheel.
32
+
33
+ ```sh
34
+ python -m pip install ruvector-attention==0.2.0
35
+ ```
36
+
37
+ ```python
38
+ from ruvector_attention import attend
39
+ result = attend([1, 0], [[1, 0], [0, 1]])
40
+ assert result.weights[0] > result.weights[1]
41
+ assert result.blended.shape == (2,)
42
+ ```
43
+
44
+ ## How it works
45
+
46
+ Python sequences → finite contiguous float32 validation → shared RuVector native Rust runtime → typed Python or NumPy results. No Node.js process is used.
47
+
48
+ ## Scope and limits
49
+
50
+ This exposes scaled dot product attention with candidates as both keys and values. It does not expose every npm attention mechanism or a trained cross encoder. Candidate ordering is equivalent to dot product.
51
+
52
+ This is a Python convenience API backed by the shared native runtime, not complete npm API parity. Invalid dimensions and nonfinite inputs are rejected.
53
+
54
+ ## Documentation
55
+
56
+ [Portfolio and architecture](https://github.com/ruvnet/RuVector/tree/main/python/portfolio) · [Source](https://github.com/ruvnet/RuVector/tree/main/python/portfolio/ruvector-attention) · [Issues](https://github.com/ruvnet/RuVector/issues)
@@ -0,0 +1,6 @@
1
+ ruvector_attention/__init__.py,sha256=V-zcce3e2isn_f0C8z5JKohLsKazjG7AzNFZUaYQKIg,1442
2
+ ruvector_attention/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ ruvector_attention-0.2.0.dist-info/METADATA,sha256=Of7FEud6d8sDrTLETOqXG6YoU93QDF-8CdG4M3JGQJE,2358
4
+ ruvector_attention-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
+ ruvector_attention-0.2.0.dist-info/licenses/LICENSE,sha256=UP77k1YK9EITacmck8whTNg1sxgat_FjI_nm8t7YcOM,1060
6
+ ruvector_attention-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 rUv
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.