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 @app.on_event("shutdown") or other similar hooks to ensure the data is saved.

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

Uploaded CPython 3.11Windows x86-64

lab_1806_vec_db-0.6.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (844.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (821.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.6.6-cp311-cp311-macosx_11_0_arm64.whl (724.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

lab_1806_vec_db-0.6.6-cp310-cp310-win_amd64.whl (606.2 kB view details)

Uploaded CPython 3.10Windows x86-64

lab_1806_vec_db-0.6.6-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.6.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (822.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.6.6-cp310-cp310-macosx_11_0_arm64.whl (724.7 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.9Windows x86-64

lab_1806_vec_db-0.6.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (845.3 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.6-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (822.9 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.6.6-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.6-cp38-cp38-win_amd64.whl (606.1 kB view details)

Uploaded CPython 3.8Windows x86-64

lab_1806_vec_db-0.6.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (845.3 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.6-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (822.3 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.6.6-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.6-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fbe647c85419bdcc0e9291f9e64cd2e90dfbb84ced72a91b4a10194932dfb4e1
MD5 3f8b4565a40acc479d32f7f3d4ff1932
BLAKE2b-256 8eec8c623cf51867432ab9ca9aad86e053db0a98d3d80a9c363fb429c4ec7f86

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6b602b3dbf86f5952394156928597eb2f2b04cba67dc168543fe2e859448c535
MD5 70ab5ed27c2a0ad0c2d2b9dd50dd5d0e
BLAKE2b-256 e4ce2fcfc65014e21113af4e632caa50cf0bc39948f6364df4164fa6f3a341e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 44bb583070ea2e1aab650c8c9b5b6d4e7a6d87d3579fa172df6382e5f9e2e31c
MD5 18c03dbf0e17c19a128aba1b6fc57e5c
BLAKE2b-256 54f5d4f6e1d11ad5ded34322482f42d35da21b204000298e346aa1e0d163735b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.6-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6639353ae304ddec783a93ad1e8a2b916ec26ac70f361fa1cb5d3f4841701e51
MD5 40cae95ea73e93a42ac7c1c86266b5be
BLAKE2b-256 a4b05420e0a7b5554646a3ba9888155e1180849d32ba33adf118727311d3ff5f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ddd99d0fb1398ca332654ce47a5a80f95a9d7a19559c695e7b0d1d864723a704
MD5 82899ba9f51102955a55a7d7bd59db15
BLAKE2b-256 357c276a8aa89e23d1d32af65445414b89c91d9ba8a06b55b727d1151600f5ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 772b79aa91e80ff1496f5a8e4240d15d80f8accd03de2eb7e5318bebb9060699
MD5 441ba8805cd81c7f7eb1298de865857b
BLAKE2b-256 a94afd98fe4e92481f170e93189fcf0920ab5b5abcf2dddf1c4ef9bfac9bb7b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ad4289c53ef5c629f1909499f031f86da8d3d5ddf236d4c92039fd29e977a71f
MD5 9f7352c349dc61bcdc00f1897c680c7a
BLAKE2b-256 af3517fd9cc670fc66d3d5b4f3fc0b3454cb8971f76e31cfb31aee9cfede503e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.6-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c861a4be74989192e7a09f25d55a5775d9ddf0cbe5e35dda472619bc778e338b
MD5 117a392430a3d1c31c18804ef81e9de6
BLAKE2b-256 f0a5aa2c46daf4274bc6c25750a25cd60f61b301b65d80ed62e3409b37f717f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 4799cff5631e1dc713dd253b92743eb7f05798acfafba236c96768de08a6c244
MD5 9fcbf659ae6f3cda308249a330381bad
BLAKE2b-256 e14fe90c434fea3bb7970446bdfb8c3791ea3785f7593ae66f294bfe7ba6b68e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bf0ef5ce155fa871b0da4aa603cf511880bf011df4d6afffb5c521a5e7f9d16d
MD5 3729e2d297efaed615d0962987595c7d
BLAKE2b-256 98c0773bc234f3cb5b2e8042c271f2b4980c5234a9edf8cb63162e59a877d840

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.6-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e295d47d7988edd46f038162c8bcc57c3a47ec9cbbb777767b53c3bf21c60551
MD5 2a68e01d930a0b7185dd24d0cf72e261
BLAKE2b-256 539d7b4462b4e1f8eb1a5417416ad80e348067387450742cc2b5d3e40aff1320

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.6-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3cb99c7bb14f475abe315ecbae67e85490b62396a6e728b0e05c382cdfebe60c
MD5 469b8fb6cab1a5485250210ba2750eeb
BLAKE2b-256 d30a3c9ecc415cab404f8b108f8ce61b56f5879e494bca093362c24d356be716

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.6-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 82fddf9db47e1479f7d477a4c52651eb2a3824fd0ecf19c6e2e30060284e7a59
MD5 0e9430f75f0ae6537c043c84a2daa807
BLAKE2b-256 6b155ebe4d75be82dce73c32c9c45267f95af99179da57dd98375d912b7b33cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 95de0330454ac9212bf4e5c64d2d1265d793a6739b5dae275d47d366a1a8c4e2
MD5 181f0bedfa0299d1953afa4117f91747
BLAKE2b-256 a859bd9075843ffbefb9b42957985115f8ae831a9d68814a5373a6c307dec90d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.6-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e13c0a8885d9167c884f776842567c4482e98e72e90c8244fa1df82f1ad891df
MD5 0357cf1f40753c8765d7dcbe71475af4
BLAKE2b-256 bec9b34647f4525d75b20a8a192caa0adfa67e54dca376caba2160b8631b9b63

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.6-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9a3653dc4e3121f10ca838ff2cbecce54b8b816943cf14ed0cb72846fb32e4c0
MD5 4cbb5c171b6b83588e8812563bfcd726
BLAKE2b-256 01a2d20114219094e030f3e89e618a6f39077321d22df0b430f0fd633a22f0d5

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