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.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.8-cp311-cp311-win_amd64.whl (617.3 kB view details)

Uploaded CPython 3.11Windows x86-64

lab_1806_vec_db-0.6.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (844.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.8-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (821.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.6.8-cp311-cp311-macosx_11_0_arm64.whl (740.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

lab_1806_vec_db-0.6.8-cp310-cp310-win_amd64.whl (617.0 kB view details)

Uploaded CPython 3.10Windows x86-64

lab_1806_vec_db-0.6.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (844.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.8-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (822.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.6.8-cp310-cp310-macosx_11_0_arm64.whl (741.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

lab_1806_vec_db-0.6.8-cp39-cp39-win_amd64.whl (617.1 kB view details)

Uploaded CPython 3.9Windows x86-64

lab_1806_vec_db-0.6.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (845.1 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.8-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (823.0 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.6.8-cp39-cp39-macosx_11_0_arm64.whl (741.6 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

lab_1806_vec_db-0.6.8-cp38-cp38-win_amd64.whl (617.0 kB view details)

Uploaded CPython 3.8Windows x86-64

lab_1806_vec_db-0.6.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (844.7 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.8-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (822.7 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.6.8-cp38-cp38-macosx_11_0_arm64.whl (741.3 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.8-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 12d8a72c3aec6eb5df2e059c064f00f3fed5d96dac99e061d1a77a5a720b5b34
MD5 05be6115319dd4277ed0ea129987cf5a
BLAKE2b-256 e79d00d8f7c82850b6dc5dcf2728f9b624dc952a8e98992154ff1c14ca61c520

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3acc5a8b1bdbc443d01d58ba063eb039928132bc151de354127b144ba0505964
MD5 20db25e553da2cff115e8700d5021205
BLAKE2b-256 2086f2a6a91f5bd2c37a7c9485c88bda8c16a36b0c18c0985e982cf99acacf9a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.8-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5be1f003d02d35538da360dbed04ed1fb9fd2b790a976153241491b61a7e8d8c
MD5 9921764eae9c400bc05804f4baffad40
BLAKE2b-256 7df36578d31ce35c3c2bed39cb9aba9a1322346c3411c77094ea9d8818f384cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.8-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0e4b1501b050db89a393c93c722f186d061e20ca348ca0ae118ef0df6dcca8e3
MD5 8ac8bbd87f4704b6bd13f1ba78c12caf
BLAKE2b-256 541a9e7b8e1e8ff634891069023c19f2d04d2662ebbbf87e09e7f0990762325b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.8-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 481eb2efd1aba4ec4485d9287363e57c67862979a09bc7c6fae9e949b58ece4a
MD5 0b0ff3ff1df20b348709f5879a5d4c4f
BLAKE2b-256 5251fdbe888242b1ce3b2dee893ca14d2072ac0f8ed942d22e1397e31fe12536

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a2fdd170e9d6ee8330e28409494f59ba75f92a914ece5af5999b42283cf1879e
MD5 df4e32f583b592b172a189a1c2b66fb8
BLAKE2b-256 6b5e5ad2441ae98e37c3ac5f02990504dd9bd670f67194e2853701dc373bff20

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.8-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 15786d71de37c43d94d5d2f19455355b63a3647e50491601222391dac92de864
MD5 d2ebe01a25df076134feb3d010346c4c
BLAKE2b-256 f60462dd245ca2a9fa834d55e4604d76305451954a6a8482fd870ce4a20a5fe0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.8-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f4e17c9c4a0d1cd13de3ecbf2e26b518f57d0c6b79d72b59f02d3b2a4f194d99
MD5 7021f1152d8f13be9de00de589663519
BLAKE2b-256 f154eed76f7216bd444b09ff52a1e13aed7ca52ae95a3e2e0fe3c93fd9d28a73

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.8-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d67928b1b48fb62b064f1b037c02a50b7ef895df1b94ebb7286ebbbfd86ea3c3
MD5 48b44ac6fdb3c6ed6c7c9735e93ed93e
BLAKE2b-256 2d43b0c267aaca789024fabddacc5f7acbe085c89396d63984235ab5627e910b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2321e846abd0d23ec57503f4d897dae0e79c9ed6f9326157defe0c2c9a9ca6c8
MD5 5584d0633d81f7129286322d22348d74
BLAKE2b-256 f7e44525529754d52cdcc1263f12caf5181a59dbca4d7919c54f0bc70c8e1812

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.6.8-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.8-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8299585b07865ab4ecf9b6898cec3239f35e80fe39a43bb2a33cb4621234d6b0
MD5 48867bb2eb8f56c411e2fb43dd8a4f07
BLAKE2b-256 ef6e0ae7026371be669bae7b703b5c03e424ad3986eb66476717a319cb66cc8f

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.6.8-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.8-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 23e4ae41e30ccce32ac0390379fd2e8d4fcade146b05dc7b984a2242f2d2c5b3
MD5 efa8d22dda466ab2b76696f7eb260c9e
BLAKE2b-256 5a0a01856fe38fa63ccbc2749b561f2df2db6901d96e71577b43bc04ef3d5777

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.8-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 58354ce05f057972419f841dabede74f25f157c04db075515d668db50180b4f0
MD5 abd88d2896ebbc0ee274e7f56f4d364d
BLAKE2b-256 c043be1a37d22d1c0260209e70e9310432e834005a1ec4f71d15264b1495ceaa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.8-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 393cf6760fe9b7bafb8877957afbf3cab7c28ccf9a10700f11e3a7a313b2da01
MD5 085c2c4b5c35cd70e7237da9ae4c18b2
BLAKE2b-256 1e6a6ed01dbcbd24240e812e16ae0f74867f9acbef437174c874536417ac93a4

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.6.8-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.8-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9225a3385dbd378a9eefa85fecd9a4d6de9cfbd9d13ae4362927248da5126b81
MD5 dd3d19098eb36fbfc74317b7ba3542f6
BLAKE2b-256 e4ca1db5b8e8abcbb9324cf1d89d7222cb9d3b889bbd597abff87cae494d6754

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.6.8-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.8-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d34835bf5d1da7e361ae0eeff1d389618d2ff3d05fa8f1653bb79532cc48148f
MD5 7b32e69a4c2c6c3f1056ebfc21dd6267
BLAKE2b-256 b44f4b71ac30dbb1bab12fe3785468c55c5753f40d1308e42d59112644bfda24

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