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.1-cp312-cp312-win_amd64.whl (616.9 kB view details)

Uploaded CPython 3.12Windows x86-64

lab_1806_vec_db-0.7.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (845.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.7.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (821.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.7.1-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.1-cp311-cp311-win_amd64.whl (617.5 kB view details)

Uploaded CPython 3.11Windows x86-64

lab_1806_vec_db-0.7.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (845.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.7.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (821.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.7.1-cp311-cp311-macosx_11_0_arm64.whl (740.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

lab_1806_vec_db-0.7.1-cp310-cp310-win_amd64.whl (617.1 kB view details)

Uploaded CPython 3.10Windows x86-64

lab_1806_vec_db-0.7.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (844.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.7.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (823.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.7.1-cp310-cp310-macosx_11_0_arm64.whl (740.9 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ae14c72e8767c7a32b7881411e71f1af78a690017a1ccc5f29b01c47f4d2958c
MD5 a97ac92009f36fcdf3034ae1840a4913
BLAKE2b-256 01987be4f0740e54bffae3fef6ee66bb6257f56508b2ad6dc1f47713a4e2e508

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 17f6afbb0aca5efe488c20776cbc5574a44c3423ffa3b6e0ce6012c4d3c3cb68
MD5 867fce16fbecc4da920d4cb792477c97
BLAKE2b-256 3b6897f95648588c4cd65a0c1c2e3eb0ff9d72ab7f2c1a94d4f90f2f92cdf612

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 449608b1ed4f9e704da94487b0824f8c7c4e07ae36613967fb2b7a7e3140c342
MD5 12021cdefaa7e3c683b12be4e5816dac
BLAKE2b-256 f2afbc07e028062baaed54c38fc3daae8fb299521e9e5abf8853c208c9bccac5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e175e894aa97482bffe5189597de54bdf31d165000db3a340ccf3c5276d287d7
MD5 c670d50cf85df61adb30601cc36df68b
BLAKE2b-256 8cff57d99fa19a7091b96597590e77546f913ee2971ecd34e97cb8092864d0ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f3c4a851533a40c7873c7df7e0295f899de199069fd1ca86be9e04f47e54a847
MD5 40a3c4d619f703ce7dc34683752efd74
BLAKE2b-256 a329da7cb12870b226b0eb0becdd6abbec67449b0e28a95321111f7494754a14

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d3ddb0c77321d2707bfa06d19d5bfbfb329eee30c7bead912693b3dba02a0c3d
MD5 ee67ae191c3a9d71eb4d39251d5ea80b
BLAKE2b-256 185f17491319d8ad06bb43c32692d70bccf25c5fd37b44e10ee8b8e08e87e6c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 701b046775b567a4e1c2e06599dd219cc028d8703d9bf5a4fd7c63df6ef3a794
MD5 d821fffd2fe54db22caccc6cc6f29206
BLAKE2b-256 895455ad4dc700a115c84324bc66fef2771fb5f64ebbc33df8b2ffb66940a15a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ba9da12d8f710a614cfe37e69f0a6ed5a1345879d2c8d1554cfd44c060a4a4f4
MD5 156e729295cb0a32e0be4aa52a033c94
BLAKE2b-256 0e45a001098791a5f9479fce146679093b76eda9aae45bf518244852d6a3e30f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a197451140f275e1347c4212789f13594ebe0ee8b02f150ab23600dfe42d5547
MD5 bb909c9a57ae7b02a8da06db49f6f45f
BLAKE2b-256 0710b055254ab0e51639b61ce5a1a099a71d5335b97a3b28c9c6ada6993f9081

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f4068509425842d83e3471a1e6b8cebfd37656fe1ec8b1e2a09f6a18bda1a475
MD5 2ca6b383615c5fb8bc7560f02d729368
BLAKE2b-256 65eeaad5bd60a3a9c1ea5732809fa3f144c4b14a5b8644741515be4265c7e9a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d14eb29370cf09ff0e5574136fefa44e1641fb1688f68a4a15a54cfbcfc441fe
MD5 1094a93c7d1c84ec9467855ed779c251
BLAKE2b-256 d95252814487d5f3eeb3bdcc6e0743ae33c538f3a615fea4c72a7927c1b42aa3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 34ef4224752fafd321ed41b242c25b7695868948b9601258ce533546d45ca29f
MD5 d62939f683872b4516375fd6eed4731c
BLAKE2b-256 fd3421f0f3de6c657793fd589f86c12213f89f54dce0b8f5ae7ebe4609dfd358

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