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

Uploaded CPython 3.11Windows x86-64

lab_1806_vec_db-0.6.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (845.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.7-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.6.7-cp311-cp311-macosx_11_0_arm64.whl (724.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

lab_1806_vec_db-0.6.7-cp310-cp310-win_amd64.whl (606.3 kB view details)

Uploaded CPython 3.10Windows x86-64

lab_1806_vec_db-0.6.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (844.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.7-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (822.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.6.7-cp310-cp310-macosx_11_0_arm64.whl (724.8 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

lab_1806_vec_db-0.6.7-cp39-cp39-win_amd64.whl (606.4 kB view details)

Uploaded CPython 3.9Windows x86-64

lab_1806_vec_db-0.6.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (845.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.7-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (823.4 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.6.7-cp39-cp39-macosx_11_0_arm64.whl (725.2 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

lab_1806_vec_db-0.6.7-cp38-cp38-win_amd64.whl (606.1 kB view details)

Uploaded CPython 3.8Windows x86-64

lab_1806_vec_db-0.6.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (845.5 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.7-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (822.6 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.6.7-cp38-cp38-macosx_11_0_arm64.whl (725.2 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 cce2fc054ed5e754733f431d1ea8913e84238457810ef79c192d927a9050fb64
MD5 709e7fe32a4b8a940aeeec5302ae6a1d
BLAKE2b-256 336f38bec1225d95a2232e8e393096deae6a846daf35de8a517ca2e7c17b866a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a4d7476dd4a707ce9b17df28bc387371b2d3b4631d48bbc1ca811e726c348806
MD5 4097942da7cebf1abc8ed504c7c26ff4
BLAKE2b-256 7402eee16cb60f07393c93a813db6eb15030da022bcd71f28b3afe864044eecf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.7-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0524cf1a18db972f367468bbf50359791698736b6e3a3ce1bf63b3d6b2e953ba
MD5 53bbbcbdca225dec192701454abea396
BLAKE2b-256 bec5834cb76199efd7128dfe578afa0ee10d2bc31200d2c01941d388d6f13cde

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0b6dcff89f21870bcd9e4e5c3259cd6455696b42c1cdfe4a6633824ce3b8d94b
MD5 a35b431e4f7382a9b9c9cabba2393360
BLAKE2b-256 f763fc8239bf89c922133df754eb51df4e52e416c7aa3a51e61b2fedb9ef1961

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d92211e7c49780710c1dfc8d9f87f86b57f43924ce9a8a5be299ba9ec10565df
MD5 ba93a74a4484d86e05da13311ffe99b9
BLAKE2b-256 5634655b6e4ec466501ab3db183d7b58d0cea6c4e1605cc65ebe93fde44668dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 634a609b0953bc5e223e899a53648c0640c9651e22debf6c4365e6e51be66b06
MD5 d2d59fc69e6faa27c5a32b9c793d9fa3
BLAKE2b-256 c9d2e2d8bff1c3baa8b3825590895daae9768e718e8051c18085394ccc648913

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.7-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c83a8e8cb6adc1a6308f97fbe68b04e1cd5aa6695c712d84872f2cf6dd32699c
MD5 a3ed7f6272ff62ffde8cc27bc8558eb5
BLAKE2b-256 bfd66b25fa50d4621baf4008036666826cf1e90a8ff0166afdf6edabd4ffee61

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.7-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bf5d0a1c96b4dbefea79544fcd8447731b96bacab8a8211167bb50c91bb7b4ae
MD5 9acd4964d4e10706cc4e1fcbd9ca133c
BLAKE2b-256 df3318fcfd5001e513391b51592ad1ab8520619de2b3db42faa8407da2e5b675

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.7-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 2c7b73b7f48fee2a5c330fd065c8453ed0b135e7bb2b4dd79faacda53183af42
MD5 42d9514865c1fd4c4e64cfe2a6a7fd7c
BLAKE2b-256 093fce7fe216a1b52cb9360ad74321e788e17ee14007dd6ad6d7910da0abad3d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0b0f4c601ab7d89d77d8a044bddd8b6e2e6351b13726d9c42e3462f12c960816
MD5 d0df6fcabb7c284d2ba5f452873bced2
BLAKE2b-256 93d48b12ca3f43fbc734ae8ad3af7225ff2494a2debe6a37dd5a38aa1099fccc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.7-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1a1e21e6da875c74a2de55ede1c5e2e7f182e635902708e3e01b678654d53cbd
MD5 9c1403e1a52e30c6f63a9fef817931ad
BLAKE2b-256 17d9c22e82f158c4aae22e7ce68ceb5f2b52315445947983ebbf2f384d4e22e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.7-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0b23b2776eca3294833ffcaa6f467c7ca6e84ae8ca06888ef2af14b87930bbb0
MD5 373dca54f38f594bcd2cb0381f7a4152
BLAKE2b-256 1c8d15accae52d1034d63a02b7261ceb163195fbed3417860dedbfafe6a18824

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.7-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 5f53da616b43ce81e5791eb41ca9ddf938617f54d11bc2df7ad9d31341f47cf6
MD5 dff8545e79261c7172f09f5c53451612
BLAKE2b-256 d8deecd8fd026178ff10350baeac50b09a32b74d7074eb5dba89bf336266513a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 aef0b6c0e672fe64a45bc03b88af3908e05e5ea886ae72d88caa3a7dbdb958dc
MD5 4caa3e2fd3b82c0b769ff04a860eb3ad
BLAKE2b-256 d80ecd85446baf11dc92bdfea23221f9a466747e584fb30aea2b7dfb261d6bda

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.7-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 675087084a94451ac4923d07a330f882db3a726b47771d82d6495a1f319f9773
MD5 32277ec40746670caf95da8b864370b4
BLAKE2b-256 acb30222a334c93453e6579ae0c533c00726fea1d024ba4ee68d0e72db99a81e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.7-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8bb93d6265f0519628af454963b9acee4bfafc27eedd6c8106e85b66b5c8c3bc
MD5 a88cc5560299f15ae4a14807416b7194
BLAKE2b-256 45bcd4ef60be95b416ec5d6c6f3876bab0d1e1470e1a3c1d73f53a24497d97b2

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