ruvector-core 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,55 @@
|
|
|
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, metric):
|
|
12
|
+
data = np.ascontiguousarray(value, dtype=np.float64)
|
|
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
|
+
if np.any(np.abs(data) > 1e10):
|
|
18
|
+
raise ValueError("vector magnitude must not exceed 1e10 for stable native metrics")
|
|
19
|
+
if metric == "cosine":
|
|
20
|
+
scale = np.max(np.abs(data), axis=-1, keepdims=True)
|
|
21
|
+
if np.any(scale == 0):
|
|
22
|
+
raise ValueError("cosine vectors must have nonzero norm")
|
|
23
|
+
data = data / scale
|
|
24
|
+
data = data / np.linalg.norm(data, axis=-1, keepdims=True)
|
|
25
|
+
return np.ascontiguousarray(data, dtype=np.float32)
|
|
26
|
+
|
|
27
|
+
from ruvector import Collection, HnswIndex, RabitqIndex, SearchHit
|
|
28
|
+
__all__ = ["VectorStore", "Collection", "HnswIndex", "RabitqIndex", "SearchHit"]
|
|
29
|
+
|
|
30
|
+
class VectorStore:
|
|
31
|
+
"""Validated batch ingestion and search over the native HNSW Collection."""
|
|
32
|
+
def __init__(self, dimensions: int, *, metric: str = "cosine"):
|
|
33
|
+
self.dimensions = _integer(dimensions, "dimensions")
|
|
34
|
+
if metric not in {"cosine", "euclidean", "dot", "manhattan"}:
|
|
35
|
+
raise ValueError("unsupported metric")
|
|
36
|
+
self.metric = metric
|
|
37
|
+
self.collection = Collection.create(dimensions, metric=metric)
|
|
38
|
+
|
|
39
|
+
def add(self, vectors, *, metadata=None):
|
|
40
|
+
data = _array(vectors, 2, "vectors", self.metric)
|
|
41
|
+
if data.shape[1] != self.dimensions:
|
|
42
|
+
raise ValueError("vector dimension mismatch")
|
|
43
|
+
if metadata is not None and (len(metadata) != len(data) or any(m is not None and not isinstance(m, dict) for m in metadata)):
|
|
44
|
+
raise ValueError("metadata must contain one dict or None per vector")
|
|
45
|
+
return self.collection.insert_batch(data, metadatas=metadata)
|
|
46
|
+
|
|
47
|
+
def search(self, query, *, k: int = 10, filter=None):
|
|
48
|
+
q = _array(query, 1, "query", self.metric)
|
|
49
|
+
if len(q) != self.dimensions:
|
|
50
|
+
raise ValueError("query dimension mismatch")
|
|
51
|
+
_integer(k, "k", 100000)
|
|
52
|
+
return self.collection.search(q, k, filter=filter)
|
|
53
|
+
|
|
54
|
+
def __len__(self):
|
|
55
|
+
return len(self.collection)
|
ruvector_core/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ruvector-core
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Native vector search with ergonomic batch ingestion.
|
|
5
|
+
Project-URL: Homepage, https://github.com/ruvnet/RuVector
|
|
6
|
+
Project-URL: Documentation, https://github.com/ruvnet/RuVector/tree/main/python/portfolio/ruvector-core
|
|
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,core,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-core
|
|
24
|
+
|
|
25
|
+

|
|
26
|
+
|
|
27
|
+
Native vector search with ergonomic batch ingestion.
|
|
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-core==0.2.0
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from ruvector_core import VectorStore
|
|
39
|
+
store = VectorStore(2)
|
|
40
|
+
store.add([[1, 0], [0, 1]])
|
|
41
|
+
assert store.search([1, 0], k=1)[0].id == 0
|
|
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
|
+
HNSW is approximate. Metadata filters are applied after ANN retrieval, with Collection overfetch retries. No embedding model is included.
|
|
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-core) · [Issues](https://github.com/ruvnet/RuVector/issues)
|
|
57
|
+
|
|
58
|
+
Coordinates are limited to absolute values of `1e10` and dimensions to 65,536, preventing overflow in native float32 distance accumulation. Rescale larger vectors before ingestion or querying.
|
|
59
|
+
|
|
60
|
+
Cosine vectors are normalized in float64 before float32 conversion to preserve tiny nonzero directions. Zero vectors are rejected for cosine; other metrics retain their original magnitudes.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
ruvector_core/__init__.py,sha256=PYMdB1d1Sh7x4KaS6qrxDuDlUpa_f2SH4V4bU--T828,2563
|
|
2
|
+
ruvector_core/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
ruvector_core-0.2.0.dist-info/METADATA,sha256=jlH8i7Ap4Lu98LxLz7hnChFtowku_2TL9etOHKJ2iaA,2584
|
|
4
|
+
ruvector_core-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
5
|
+
ruvector_core-0.2.0.dist-info/licenses/LICENSE,sha256=UP77k1YK9EITacmck8whTNg1sxgat_FjI_nm8t7YcOM,1060
|
|
6
|
+
ruvector_core-0.2.0.dist-info/RECORD,,
|
|
@@ -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.
|