vxdb 0.2.1__tar.gz → 0.3.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.
- {vxdb-0.2.1 → vxdb-0.3.1}/Cargo.lock +3 -3
- {vxdb-0.2.1 → vxdb-0.3.1}/Cargo.toml +1 -1
- {vxdb-0.2.1 → vxdb-0.3.1}/PKG-INFO +14 -3
- {vxdb-0.2.1 → vxdb-0.3.1}/README.md +13 -2
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-core/src/distance/cosine.rs +20 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-core/src/distance/dot.rs +17 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-core/src/distance/euclidean.rs +24 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-python/src/lib.rs +3 -1
- {vxdb-0.2.1 → vxdb-0.3.1}/pyproject.toml +1 -1
- {vxdb-0.2.1 → vxdb-0.3.1}/python/vxdb/__init__.py +1 -1
- vxdb-0.3.1/python/vxdb/embedded.py +122 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-core/Cargo.toml +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-core/src/collection.rs +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-core/src/distance/mod.rs +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-core/src/error.rs +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-core/src/filter.rs +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-core/src/hybrid.rs +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-core/src/index/flat.rs +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-core/src/index/hnsw.rs +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-core/src/index/mod.rs +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-core/src/lib.rs +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-core/src/storage/metadata.rs +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-core/src/storage/mmap.rs +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-core/src/storage/mod.rs +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-core/src/storage/persistent.rs +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-core/src/storage/wal.rs +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-core/src/types.rs +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/crates/vxdb-python/Cargo.toml +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/python/vxdb/_vxdb.pyi +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/python/vxdb/client.py +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/python/vxdb/embedding.py +0 -0
- {vxdb-0.2.1 → vxdb-0.3.1}/python/vxdb/py.typed +0 -0
|
@@ -1761,7 +1761,7 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
|
|
1761
1761
|
|
|
1762
1762
|
[[package]]
|
|
1763
1763
|
name = "vxdb-core"
|
|
1764
|
-
version = "0.
|
|
1764
|
+
version = "0.3.1"
|
|
1765
1765
|
dependencies = [
|
|
1766
1766
|
"memmap2",
|
|
1767
1767
|
"parking_lot",
|
|
@@ -1775,7 +1775,7 @@ dependencies = [
|
|
|
1775
1775
|
|
|
1776
1776
|
[[package]]
|
|
1777
1777
|
name = "vxdb-python"
|
|
1778
|
-
version = "0.
|
|
1778
|
+
version = "0.3.1"
|
|
1779
1779
|
dependencies = [
|
|
1780
1780
|
"pyo3",
|
|
1781
1781
|
"serde_json",
|
|
@@ -1784,7 +1784,7 @@ dependencies = [
|
|
|
1784
1784
|
|
|
1785
1785
|
[[package]]
|
|
1786
1786
|
name = "vxdb-server"
|
|
1787
|
-
version = "0.
|
|
1787
|
+
version = "0.3.1"
|
|
1788
1788
|
dependencies = [
|
|
1789
1789
|
"axum",
|
|
1790
1790
|
"clap",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: vxdb
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Classifier: Development Status :: 4 - Beta
|
|
5
5
|
Classifier: Intended Audience :: Developers
|
|
6
6
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
@@ -185,16 +185,27 @@ vxdb stores **pre-computed vectors** — bring any embedding model you want. We
|
|
|
185
185
|
| **Ollama** (local LLMs) | `pip install ollama` | No (local) | — |
|
|
186
186
|
|
|
187
187
|
|
|
188
|
-
Or
|
|
188
|
+
Or let vxdb embed for you. Attach an `embedding_function` to a collection and
|
|
189
|
+
work in **text** — pass `documents` to `upsert` and `query_text` to `query`:
|
|
189
190
|
|
|
190
191
|
```python
|
|
191
|
-
from vxdb
|
|
192
|
+
from vxdb import Database, EmbeddingFunction
|
|
192
193
|
|
|
193
194
|
class MyEmbedder(EmbeddingFunction):
|
|
194
195
|
def embed(self, texts: list[str]) -> list[list[float]]:
|
|
195
196
|
return your_model.encode(texts)
|
|
197
|
+
|
|
198
|
+
db = Database()
|
|
199
|
+
docs = db.create_collection("docs", embedding_function=MyEmbedder()) # dimension inferred
|
|
200
|
+
|
|
201
|
+
docs.upsert(ids=["a", "b"], documents=["how to train a model", "best pasta recipe"])
|
|
202
|
+
docs.query(query_text="machine learning", top_k=5)
|
|
196
203
|
```
|
|
197
204
|
|
|
205
|
+
The `embedding_function` can be an `EmbeddingFunction` subclass or any callable
|
|
206
|
+
`list[str] -> list[list[float]]`. Passing `vectors`/`vector` explicitly always
|
|
207
|
+
works and bypasses embedding — vxdb never requires or imports your model library.
|
|
208
|
+
|
|
198
209
|
---
|
|
199
210
|
|
|
200
211
|
## Server Mode
|
|
@@ -157,16 +157,27 @@ vxdb stores **pre-computed vectors** — bring any embedding model you want. We
|
|
|
157
157
|
| **Ollama** (local LLMs) | `pip install ollama` | No (local) | — |
|
|
158
158
|
|
|
159
159
|
|
|
160
|
-
Or
|
|
160
|
+
Or let vxdb embed for you. Attach an `embedding_function` to a collection and
|
|
161
|
+
work in **text** — pass `documents` to `upsert` and `query_text` to `query`:
|
|
161
162
|
|
|
162
163
|
```python
|
|
163
|
-
from vxdb
|
|
164
|
+
from vxdb import Database, EmbeddingFunction
|
|
164
165
|
|
|
165
166
|
class MyEmbedder(EmbeddingFunction):
|
|
166
167
|
def embed(self, texts: list[str]) -> list[list[float]]:
|
|
167
168
|
return your_model.encode(texts)
|
|
169
|
+
|
|
170
|
+
db = Database()
|
|
171
|
+
docs = db.create_collection("docs", embedding_function=MyEmbedder()) # dimension inferred
|
|
172
|
+
|
|
173
|
+
docs.upsert(ids=["a", "b"], documents=["how to train a model", "best pasta recipe"])
|
|
174
|
+
docs.query(query_text="machine learning", top_k=5)
|
|
168
175
|
```
|
|
169
176
|
|
|
177
|
+
The `embedding_function` can be an `EmbeddingFunction` subclass or any callable
|
|
178
|
+
`list[str] -> list[list[float]]`. Passing `vectors`/`vector` explicitly always
|
|
179
|
+
works and bypasses embedding — vxdb never requires or imports your model library.
|
|
180
|
+
|
|
170
181
|
---
|
|
171
182
|
|
|
172
183
|
## Server Mode
|
|
@@ -47,6 +47,26 @@ impl DistanceMetric for CosineDistance {
|
|
|
47
47
|
mod tests {
|
|
48
48
|
use super::*;
|
|
49
49
|
|
|
50
|
+
#[test]
|
|
51
|
+
fn test_matches_naive_across_dims() {
|
|
52
|
+
use rand::rngs::StdRng;
|
|
53
|
+
use rand::{Rng, SeedableRng};
|
|
54
|
+
let mut rng = StdRng::seed_from_u64(11);
|
|
55
|
+
for dim in [1usize, 7, 8, 9, 16, 100, 384, 769] {
|
|
56
|
+
let a: Vec<f32> = (0..dim).map(|_| rng.gen::<f32>()).collect();
|
|
57
|
+
let b: Vec<f32> = (0..dim).map(|_| rng.gen::<f32>()).collect();
|
|
58
|
+
let got = cosine(&a, &b);
|
|
59
|
+
let dot: f32 = a.iter().zip(&b).map(|(x, y)| x * y).sum();
|
|
60
|
+
let na: f32 = a.iter().map(|x| x * x).sum::<f32>().sqrt();
|
|
61
|
+
let nb: f32 = b.iter().map(|x| x * x).sum::<f32>().sqrt();
|
|
62
|
+
let naive = 1.0 - dot / (na * nb);
|
|
63
|
+
assert!(
|
|
64
|
+
(got - naive).abs() <= 1e-3,
|
|
65
|
+
"dim={dim}: {got} vs naive {naive}"
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
50
70
|
const EPS: f32 = 1e-6;
|
|
51
71
|
|
|
52
72
|
#[test]
|
|
@@ -35,6 +35,23 @@ impl DistanceMetric for DotProductDistance {
|
|
|
35
35
|
mod tests {
|
|
36
36
|
use super::*;
|
|
37
37
|
|
|
38
|
+
#[test]
|
|
39
|
+
fn test_matches_naive_across_dims() {
|
|
40
|
+
use rand::rngs::StdRng;
|
|
41
|
+
use rand::{Rng, SeedableRng};
|
|
42
|
+
let mut rng = StdRng::seed_from_u64(13);
|
|
43
|
+
for dim in [1usize, 7, 8, 9, 16, 100, 384, 769] {
|
|
44
|
+
let a: Vec<f32> = (0..dim).map(|_| rng.gen::<f32>()).collect();
|
|
45
|
+
let b: Vec<f32> = (0..dim).map(|_| rng.gen::<f32>()).collect();
|
|
46
|
+
let got = dot(&a, &b);
|
|
47
|
+
let naive: f32 = -a.iter().zip(&b).map(|(x, y)| x * y).sum::<f32>();
|
|
48
|
+
assert!(
|
|
49
|
+
(got - naive).abs() <= 1e-3 * naive.abs().max(1.0),
|
|
50
|
+
"dim={dim}: {got} vs naive {naive}"
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
38
55
|
const EPS: f32 = 1e-6;
|
|
39
56
|
|
|
40
57
|
#[test]
|
|
@@ -42,6 +42,30 @@ impl DistanceMetric for EuclideanDistance {
|
|
|
42
42
|
mod tests {
|
|
43
43
|
use super::*;
|
|
44
44
|
|
|
45
|
+
#[test]
|
|
46
|
+
fn test_matches_naive_across_dims() {
|
|
47
|
+
// Exercises the multi-accumulator/chunked path at dims around and well
|
|
48
|
+
// past the 8-wide block (the small-vector tests only hit the remainder).
|
|
49
|
+
use rand::rngs::StdRng;
|
|
50
|
+
use rand::{Rng, SeedableRng};
|
|
51
|
+
let mut rng = StdRng::seed_from_u64(7);
|
|
52
|
+
for dim in [1usize, 7, 8, 9, 16, 100, 384, 769] {
|
|
53
|
+
let a: Vec<f32> = (0..dim).map(|_| rng.gen::<f32>()).collect();
|
|
54
|
+
let b: Vec<f32> = (0..dim).map(|_| rng.gen::<f32>()).collect();
|
|
55
|
+
let got = euclidean(&a, &b);
|
|
56
|
+
let naive = a
|
|
57
|
+
.iter()
|
|
58
|
+
.zip(&b)
|
|
59
|
+
.map(|(x, y)| (x - y) * (x - y))
|
|
60
|
+
.sum::<f32>()
|
|
61
|
+
.sqrt();
|
|
62
|
+
assert!(
|
|
63
|
+
(got - naive).abs() <= 1e-3 * naive.max(1.0),
|
|
64
|
+
"dim={dim}: {got} vs naive {naive}"
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
45
69
|
const EPS: f32 = 1e-6;
|
|
46
70
|
|
|
47
71
|
#[test]
|
|
@@ -122,7 +122,9 @@ fn results_to_py(py: Python<'_>, results: Vec<vxdb_core::types::SearchResult>) -
|
|
|
122
122
|
/// extracting a `List[List[float]]`.
|
|
123
123
|
fn extract_vectors(vectors: &Bound<'_, PyAny>) -> PyResult<Vec<Vec<f32>>> {
|
|
124
124
|
if let Ok(buf) = PyBuffer::<f32>::get_bound(vectors) {
|
|
125
|
-
|
|
125
|
+
// `dim > 0` guards `chunks(0)`, which panics. A zero-width buffer falls
|
|
126
|
+
// through to the list path and yields a clean dimension/empty error.
|
|
127
|
+
if buf.dimensions() == 2 && buf.is_c_contiguous() && buf.shape()[1] > 0 {
|
|
126
128
|
let dim = buf.shape()[1];
|
|
127
129
|
let flat = buf.to_vec(vectors.py())?;
|
|
128
130
|
return Ok(flat.chunks(dim).map(<[f32]>::to_vec).collect());
|
|
@@ -4,7 +4,7 @@ build-backend = "maturin"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "vxdb"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.3.1"
|
|
8
8
|
description = "A lightweight, high-performance vector database with a Rust backend. Hybrid search, embedded + server modes, zero dependencies."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from importlib.metadata import PackageNotFoundError, version
|
|
4
4
|
|
|
5
|
-
from vxdb._vxdb import Collection, Database
|
|
6
5
|
from vxdb.client import Client
|
|
6
|
+
from vxdb.embedded import Collection, Database
|
|
7
7
|
from vxdb.embedding import EmbeddingFunction
|
|
8
8
|
|
|
9
9
|
__all__ = ["Database", "Collection", "Client", "EmbeddingFunction"]
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""Embedded-mode ``Database`` / ``Collection`` with optional auto-embedding.
|
|
2
|
+
|
|
3
|
+
Thin Python wrappers over the native ``_vxdb`` engine. When a collection is
|
|
4
|
+
created with an ``embedding_function``, you may pass raw ``documents`` to
|
|
5
|
+
``upsert`` and text to ``query`` / ``hybrid_query`` and the vectors are computed
|
|
6
|
+
for you. With no embedding function, every call behaves exactly like the native
|
|
7
|
+
classes (the native ``vector`` / ``vectors`` argument stays first and positional,
|
|
8
|
+
so existing code is unaffected).
|
|
9
|
+
|
|
10
|
+
The ``embedding_function`` may be an :class:`vxdb.EmbeddingFunction` instance or
|
|
11
|
+
any plain callable ``list[str] -> list[list[float]]``.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from vxdb._vxdb import Database as _NativeDatabase
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _embed(embedding_function, texts):
|
|
18
|
+
if embedding_function is None:
|
|
19
|
+
raise ValueError(
|
|
20
|
+
"no embedding_function is set on this collection; either pass "
|
|
21
|
+
"`vectors=` explicitly or create the collection with an "
|
|
22
|
+
"`embedding_function`"
|
|
23
|
+
)
|
|
24
|
+
if hasattr(embedding_function, "embed"):
|
|
25
|
+
return embedding_function.embed(texts)
|
|
26
|
+
if callable(embedding_function):
|
|
27
|
+
return embedding_function(texts)
|
|
28
|
+
raise TypeError("embedding_function must be an EmbeddingFunction (with .embed) or a callable")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Collection:
|
|
32
|
+
"""A collection with optional automatic embedding.
|
|
33
|
+
|
|
34
|
+
Wraps the native collection; delegates everything, adding text-in
|
|
35
|
+
convenience when an ``embedding_function`` is present.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
def __init__(self, native, name, embedding_function=None):
|
|
39
|
+
self._native = native
|
|
40
|
+
self.name = name
|
|
41
|
+
self.embedding_function = embedding_function
|
|
42
|
+
|
|
43
|
+
def upsert(self, ids, vectors=None, metadata=None, documents=None):
|
|
44
|
+
if vectors is None:
|
|
45
|
+
if documents is None:
|
|
46
|
+
raise ValueError(
|
|
47
|
+
"upsert requires `vectors`, or `documents` together with an embedding_function on the collection"
|
|
48
|
+
)
|
|
49
|
+
vectors = _embed(self.embedding_function, documents)
|
|
50
|
+
self._native.upsert(ids=ids, vectors=vectors, metadata=metadata, documents=documents)
|
|
51
|
+
|
|
52
|
+
def query(self, vector=None, top_k=10, filter=None, query_text=None):
|
|
53
|
+
if vector is None:
|
|
54
|
+
if query_text is None:
|
|
55
|
+
raise ValueError(
|
|
56
|
+
"query requires `vector`, or `query_text` together with an embedding_function on the collection"
|
|
57
|
+
)
|
|
58
|
+
vector = _embed(self.embedding_function, [query_text])[0]
|
|
59
|
+
return self._native.query(vector=vector, top_k=top_k, filter=filter)
|
|
60
|
+
|
|
61
|
+
def hybrid_query(self, vector=None, query=None, top_k=10, alpha=0.5):
|
|
62
|
+
# `vector` stays first to match the native positional order
|
|
63
|
+
# `hybrid_query(vector, query, ...)`. `query` (the BM25 text) is required;
|
|
64
|
+
# `vector` is embedded from it when omitted.
|
|
65
|
+
if query is None:
|
|
66
|
+
raise ValueError("hybrid_query requires `query` text (the keyword/BM25 component)")
|
|
67
|
+
if vector is None:
|
|
68
|
+
vector = _embed(self.embedding_function, [query])[0]
|
|
69
|
+
return self._native.hybrid_query(vector=vector, query=query, top_k=top_k, alpha=alpha)
|
|
70
|
+
|
|
71
|
+
def keyword_search(self, query, top_k=10):
|
|
72
|
+
return self._native.keyword_search(query=query, top_k=top_k)
|
|
73
|
+
|
|
74
|
+
def delete(self, ids):
|
|
75
|
+
return self._native.delete(ids)
|
|
76
|
+
|
|
77
|
+
def count(self):
|
|
78
|
+
return self._native.count()
|
|
79
|
+
|
|
80
|
+
def __repr__(self):
|
|
81
|
+
return repr(self._native)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class Database:
|
|
85
|
+
"""An embedded database. Drop-in for the native ``Database`` plus
|
|
86
|
+
per-collection ``embedding_function`` support."""
|
|
87
|
+
|
|
88
|
+
def __init__(self, path=None):
|
|
89
|
+
self._native = _NativeDatabase(path)
|
|
90
|
+
self._embedders = {}
|
|
91
|
+
|
|
92
|
+
def create_collection(
|
|
93
|
+
self,
|
|
94
|
+
name,
|
|
95
|
+
dimension=None,
|
|
96
|
+
metric="cosine",
|
|
97
|
+
index="flat",
|
|
98
|
+
embedding_function=None,
|
|
99
|
+
):
|
|
100
|
+
if dimension is None:
|
|
101
|
+
if embedding_function is None:
|
|
102
|
+
raise ValueError("create_collection requires `dimension`, or an `embedding_function` to infer it from")
|
|
103
|
+
# Infer the dimension once from a probe embedding.
|
|
104
|
+
dimension = len(_embed(embedding_function, ["dimension probe"])[0])
|
|
105
|
+
native = self._native.create_collection(name, dimension, metric, index)
|
|
106
|
+
if embedding_function is not None:
|
|
107
|
+
self._embedders[name] = embedding_function
|
|
108
|
+
return Collection(native, name, embedding_function)
|
|
109
|
+
|
|
110
|
+
def get_collection(self, name):
|
|
111
|
+
native = self._native.get_collection(name)
|
|
112
|
+
return Collection(native, name, self._embedders.get(name))
|
|
113
|
+
|
|
114
|
+
def list_collections(self):
|
|
115
|
+
return self._native.list_collections()
|
|
116
|
+
|
|
117
|
+
def delete_collection(self, name):
|
|
118
|
+
self._embedders.pop(name, None)
|
|
119
|
+
return self._native.delete_collection(name)
|
|
120
|
+
|
|
121
|
+
def __repr__(self):
|
|
122
|
+
return repr(self._native)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|