No project description provided
Project description
lab-1806-vec-db
Lab 1806 Vector Database.
See Rust source code at GitHub lab-1806-vec-db
Getting Started with Python
Get the latest version from PyPI lab-1806-vec-db.
pip install lab-1806-vec-db
Basic Usage
VecDB is recommended for most cases as a high-level API.
If the default Flat index cannot meet your performance requirements, try:
- Call
build_hnsw_index()when creating a table or adding data. But the delete operation will clear the established HNSW index. - Call
build_pq_index()when all the data is added. But any write operation will clear the established PQ index.
Warning: All the arguments are positional, DO NOT use keyword arguments like upper_bound=0.5.
from lab_1806_vec_db import VecDB
# uv sync --reinstall-package lab_1806_vec_db
# uv run -m examples.test_pyo3
db = VecDB("./tmp/vec_db")
for key in db.get_all_keys():
db.delete_table(key)
keys = db.get_all_keys()
assert len(keys) == 0, "Test failed"
db.create_table_if_not_exists("table_1", 4)
db.add("table_1", [1.0, 0.0, 0.0, 0.0], {"content": "a"})
db.add("table_1", [0.0, 1.0, 0.0, 0.0], {"content": "b"})
db.build_hnsw_index("table_1")
db.add("table_1", [0.0, 0.0, 1.0, 0.0], {"content": "c"})
db.add("table_1", [0.0, 0.0, 1.0, 1.0], {"content": "d", "type": "oops"})
assert db.has_hnsw_index("table_1"), "Add operation should not clear HNSW index"
db.delete("table_1", {"type": "oops"})
assert db.get_len("table_1") == 3, "Test failed"
assert not db.has_hnsw_index(
"table_1"
), "HNSW index should be cleared when a vector is deleted"
db.build_hnsw_index("table_1")
db.build_pq_table("table_1")
result = db.search("table_1", [1.0, 0.0, 0.0, 0.0], 3, None, 0.5)
print(result)
assert len(result) == 1, "Test failed"
assert result[0][0]["content"] == "a", "Test failed"
print("Test passed")
About multi-threading
VecDB is thread-safe. You can use it in multiple threads, and it will handle the lock automatically.
When methods on VecDB is called, GIL will be temporarily released, so other threads can run Python code.
Feel free to use this in FastAPI routes or other environments with ThreadPools.
See also multi-threading example.
About auto-saving
Safe to interrupt the process on Python Level at any time with Exception or KeyboardInterrupt.
See test_exception.py for an example.
Development with Rust
# Install Rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
. "$HOME/.cargo/env"
# Then install the rust-analyzer extension in VSCode.
# You may need to set "rust-analyzer.runnables.extraEnv" in VSCode Machine settings.
# The value should be like {"PATH":""} and make sure that `/home/YOUR_NAME/.cargo/bin` is in it.
# Otherwise you may fail when press the `Run test` button.
# Run tests
# Add `-r` to test with release mode
cargo test
# Or you can click the 'Run Test' button in VSCode to show output.
# Our GitHub Actions will also run the tests.
Test Python Bindings
Install Python >=3.8,<3.12 and uv.
# Run the Python test
uv sync --reinstall-package lab_1806_vec_db
uv run -m examples.test_pyo3
# Build the Python Wheel Release
uv build
Examples Binaries
src/bin/convert_fvecs.rs: Convert the fvecs format to the binary format.src/bin/gen_ground_truth.rs: Generate the ground truth for the query.examples/bench.rs: The benchmark for index algorithms.
Dataset
Download Gist1M dataset from:
-
Official: http://corpus-texmex.irisa.fr/
-
Ours: Recommended faster, and already converted to the binary format.
https://huggingface.co/datasets/pku-lab-1806-llm/gist-for-lab-1806-vec-db
Then, you can run the examples to test the database.
Note that pre-built index file may be outdated. You can build it yourself.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lab_1806_vec_db-0.6.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: lab_1806_vec_db-0.6.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 607.6 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df0e646070869654ee82f2e0ba62eaa7f4b44a56fc27805aa22f25277cbbcd6f
|
|
| MD5 |
e9ee18d811499c72bb240922958982d7
|
|
| BLAKE2b-256 |
5b614ff62e658d155b37f18e3876f36663bc94f142e2ad0775fa6689975dd8bb
|
File details
Details for the file lab_1806_vec_db-0.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: lab_1806_vec_db-0.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 828.8 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2200c2b29091249e06ab224d2c0ba2bbbea5fc5b1121631c594f5276f36d8ed
|
|
| MD5 |
ae2fe3bc5c3f060ca5e95eda196649f3
|
|
| BLAKE2b-256 |
933c72b363d6e1e080988216e94df3766b2b730f4ca9fef969524439d312102a
|
File details
Details for the file lab_1806_vec_db-0.6.0-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: lab_1806_vec_db-0.6.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 606.7 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
723f83208d4ad54aa0c472f64e8515904d319cc1985b3fd46e665e6b1bd62438
|
|
| MD5 |
511e29dec2f6298b27d9e67e0325a67f
|
|
| BLAKE2b-256 |
e8d7e4d26a2750116d46b0d5a991691dbdda993c83d98265dff1f19133bddafa
|
File details
Details for the file lab_1806_vec_db-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: lab_1806_vec_db-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 828.9 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88d8f5e5881893ea57ad1bcab811a0f8d7bd9e07f6f26b6be4355f913407916d
|
|
| MD5 |
5e06a4bc428029d26077f5a521ea5861
|
|
| BLAKE2b-256 |
8bc803dadd242503062aaee24dd3e96795f86a2ecd995cef84f0c4f6f07994bb
|
File details
Details for the file lab_1806_vec_db-0.6.0-cp39-cp39-win_amd64.whl.
File metadata
- Download URL: lab_1806_vec_db-0.6.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 606.9 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8eea18a3bf94def7cb53cf56af2bc94ec2eb4dc4a42f716fb78b73182c775749
|
|
| MD5 |
6f45fc360e8fde893ddd4a207cfbb84a
|
|
| BLAKE2b-256 |
7da77da152dd695ae48b97a9b63cbe99897ea6533176879f6dc1a7a584b6a780
|
File details
Details for the file lab_1806_vec_db-0.6.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: lab_1806_vec_db-0.6.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 830.2 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4c8c89bb1a0078b61913360cf8ae868dcbf1bb732da2b3523ed01c2148d76e6
|
|
| MD5 |
e99868c3759f2bc62780b0c34a70972a
|
|
| BLAKE2b-256 |
193493237689d449f2320e9f30164ed03956ae9cd1cfe814c28e59f90d605909
|
File details
Details for the file lab_1806_vec_db-0.6.0-cp38-cp38-win_amd64.whl.
File metadata
- Download URL: lab_1806_vec_db-0.6.0-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 606.6 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
491b5425af1517b395157476ec603fa4aa36c7b78b6ae79845f7b670f2df6e0b
|
|
| MD5 |
79205ad841d91db8b53608dfbc856489
|
|
| BLAKE2b-256 |
de6b0923e882abac6ac9880816c7a6a2d8e55626826b99c1ca6f89deffdadc4a
|
File details
Details for the file lab_1806_vec_db-0.6.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: lab_1806_vec_db-0.6.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 829.9 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75a4256cd2e32b264acd4f07d7f41072b8223a1d8655c21266196cf6795a51ca
|
|
| MD5 |
f92320a47cd2b631dab909b20ef6ed04
|
|
| BLAKE2b-256 |
dc9fd6a869f3fd212cbadd17a0ace7c9af1aff523af38cd22c76a2300953ec6d
|