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"

# Manually call `db.force_save()` when you are using the database in Jupyter Notebook or FastAPI,
# since the program may not exit normally.

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.

However some platform may have timeout when shutting down, call db.force_save() in lifespan to ensure the data is saved in FastAPI.

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.10,<3.13 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.7.0-cp312-cp312-win_amd64.whl (616.4 kB view details)

Uploaded CPython 3.12Windows x86-64

lab_1806_vec_db-0.7.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (844.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.7.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (821.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.7.0-cp312-cp312-macosx_11_0_arm64.whl (738.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

lab_1806_vec_db-0.7.0-cp311-cp311-win_amd64.whl (616.8 kB view details)

Uploaded CPython 3.11Windows x86-64

lab_1806_vec_db-0.7.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (844.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.7.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (820.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.7.0-cp311-cp311-macosx_11_0_arm64.whl (740.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

lab_1806_vec_db-0.7.0-cp310-cp310-win_amd64.whl (616.6 kB view details)

Uploaded CPython 3.10Windows x86-64

lab_1806_vec_db-0.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (844.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.7.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (822.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.7.0-cp310-cp310-macosx_11_0_arm64.whl (740.8 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file lab_1806_vec_db-0.7.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c3ae95b2908b86a8b2739b9617c760a60835af799dc2b8e7397cd425fc5b4c35
MD5 9300b86e4b588b8fe6476ae2986cd72d
BLAKE2b-256 13a34adfaef1055dbdf04d9bd13f98bc0b9a4463c92fb821c3ba2afe235cd8e7

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.7.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b0fd2efe3f5d3ebb6e38245bdda7f6b59cb5bfa2e164795871c20a4c976c291a
MD5 0f6d65a36e909363cbfcbb023e3abc05
BLAKE2b-256 c718b41ab46ea2e1052b815d529421c5eab25edd20ddbf83fe4cef22d7b2304e

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.7.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c6ea7bb72195564523df0408b8ac8ee541b55359882fadfc700d5f305a04aa55
MD5 cb4acbfa1a649a022cd10f410531e401
BLAKE2b-256 d443fdd09d13f2c81e32be22e5644a677864cbf078d868fa1f3f8a49b02774ae

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.7.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e7a47f72a751fca29886d407c7ee207a9fc105ea4c18fe7e0613fc298d551ea0
MD5 28cb7aaf6d813907c4e0bb5d6e32143a
BLAKE2b-256 38752188712cfb39a6d5b89ea17f7089bce01fc40a2bdd3a6838562bb26576c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 37f2674ced16ff2b0e9832294f215cbe39c96faa49b1e7bb194574e93f2be7f6
MD5 68b4e4ecd042b29fbe2847d9b9d0ea4f
BLAKE2b-256 faf5b65b7bd94b42adf7e83e0f2548c6d2f60cb1898436dcf5b6a864bbec08ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2c1523c2fdda81cd61bb4b01ffa93ef3d58ddda6163f15109922bbdeb86d7506
MD5 a25465a3949f57c3c4ea30aba46468f9
BLAKE2b-256 65daca468858d34da4061be8869625c2496cc9017ec2e0f5e871273c988bb16e

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.7.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 16e89309c6c8089bf85b7d2380c329d7c1117704aa734359d42fa450e1ffad8f
MD5 931963a948fbc65603f7d1f428c94e3e
BLAKE2b-256 d16d15f9cd39957f69f9f92ccba1914a38066b556c311b5c63836abb318ba6b8

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.7.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0cb5eb4395d02288d5bea80eeba851f09ec5be4c9706563873616553fc737abe
MD5 ad8491d1c2893878858de5eb8f01e8b1
BLAKE2b-256 f91b3404c3f186f93ee7800751962b4d0d138762ddf04d5ab0ff1bdfbd2884a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2bf7437b9283f640c4036dada6d6259be05a9c6505581dd2c130bf5815eaaf00
MD5 63b423b3a260ad646957244fe1844445
BLAKE2b-256 d28fc24ec97660f47a2cdb1e01053ad5af1201c5512cebbbfb596501e9735b8e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 82cfa0498ff3576d043b2649799d9a85e0585b5798e2896a4f8f68bfd3deb766
MD5 c4fc03719b16f6ec5e66393dc182f7ff
BLAKE2b-256 0eb975c611efd6cc9fc95f33232a20dc288fc8b2985634aee2564eb1eeb00957

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.7.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3e0b2c6ec16917829ee1fa7070820bca281e36d81626d48faf68ea7a99ba4374
MD5 73efd501af46cd55465fcee7fcf5f291
BLAKE2b-256 becd93a0e8167c24f32ef5fba20386739a4d72a0b833a926d10c80369ae41986

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.7.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6d5ce0d04874a2e2c4853b9a0a1de50b3eea9cf80ee446a5936947fdb147f148
MD5 89821f33a50aceba88879d220d9fb89a
BLAKE2b-256 d55a2376d2d650976ee7863568f57ee8ee25f12b533a24dae28c510c6c164196

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