Skip to main content

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:

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

lab_1806_vec_db-0.6.1-cp311-cp311-win_amd64.whl (605.6 kB view details)

Uploaded CPython 3.11Windows x86-64

lab_1806_vec_db-0.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (826.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.1-cp310-cp310-win_amd64.whl (604.8 kB view details)

Uploaded CPython 3.10Windows x86-64

lab_1806_vec_db-0.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (826.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.1-cp39-cp39-win_amd64.whl (604.9 kB view details)

Uploaded CPython 3.9Windows x86-64

lab_1806_vec_db-0.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (828.1 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.1-cp38-cp38-win_amd64.whl (604.7 kB view details)

Uploaded CPython 3.8Windows x86-64

lab_1806_vec_db-0.6.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (827.3 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file lab_1806_vec_db-0.6.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8712b7294c8fabd798f8e50ff971a86e3b4815eaf76535c0acf4ac5d5f668cbe
MD5 02e9b6ac26c221341c2dd622b53e7771
BLAKE2b-256 c58584c2ae2bae17a11f2c41d352ff54d8719c7d9e56b51d7de9c84b7b571514

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d217726fde6b9355596a0715334db7190954efc398792775b52804568fadac32
MD5 6941fcab4814720ba1c0fb75d1fe30b6
BLAKE2b-256 a0f088fa5e21953179c99a70bb30dd42e39079439c4f01b558d2cc8b7c7ab226

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.6.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 cb66b7271f84df8e8c9e2a64ba001b9ad2b66fac30c0a963e1d4db0ee25f8697
MD5 224af6441d550715ffa4362a044c6290
BLAKE2b-256 b8670e5dbc036eeadc40bf79f60da4e185c16ec7749a5c4ccf2109deecd59094

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f66c9a5a72cad5269bc84a0f6fe5bceb800225bf85c9996e9ba0dad226f693d5
MD5 1b086474771edc9b52ed478d8610d350
BLAKE2b-256 953db846c595025b43b2a5ebd3b642ad0bec7dfa5e91f43935bbb436eefb6031

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.6.1-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 fb7c4c6d7155523b60e548a7cf93d32ee30625c3e68046660208c0b2a447f049
MD5 2961a0c1b7686634220578b91a2b8991
BLAKE2b-256 385ad0c515d4956856a9aaf91b39c499983ee4ab9cc632fc9139e1b2f5111454

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bf6aec16ad84feea8672372c88d44cb1297ba2fa0300a25b8bae9b9e560ece9c
MD5 f3df29fa444f75a91b37400ab9aea522
BLAKE2b-256 902923e89298d0624cd36d9230fa6b1a14ebf8f5e8821d8eb0d42507ea44b03f

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.6.1-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 e299a0096bd6d593d3d55acad41b9a8158bd539dca3de2ebda18b7b815485a23
MD5 c0c503da0050ef737cfe52944a82700e
BLAKE2b-256 e5149888e037a7dfa256b40a5f49380782284d470b6f74ddfd26226a74cc87a7

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.6.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 84559f1f844ae5e87a4d8f3bdd9479db1c765bfc52c3aae9788de1d17a1c0b3f
MD5 d5a8e45a53815fe47acf4aff0023aead
BLAKE2b-256 9e0ac1fb14d9294fd9c0614cc2df6578752c6b69786ad5274d2b5b68d450fb7d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page