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"

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.

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

Uploaded CPython 3.11Windows x86-64

lab_1806_vec_db-0.6.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (825.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.4-cp311-cp311-macosx_11_0_arm64.whl (722.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

lab_1806_vec_db-0.6.4-cp310-cp310-win_amd64.whl (605.4 kB view details)

Uploaded CPython 3.10Windows x86-64

lab_1806_vec_db-0.6.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (826.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.4-cp310-cp310-macosx_11_0_arm64.whl (722.8 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

lab_1806_vec_db-0.6.4-cp39-cp39-win_amd64.whl (605.5 kB view details)

Uploaded CPython 3.9Windows x86-64

lab_1806_vec_db-0.6.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (827.9 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.4-cp39-cp39-macosx_11_0_arm64.whl (723.1 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

lab_1806_vec_db-0.6.4-cp38-cp38-win_amd64.whl (605.2 kB view details)

Uploaded CPython 3.8Windows x86-64

lab_1806_vec_db-0.6.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (827.0 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.4-cp38-cp38-macosx_11_0_arm64.whl (723.2 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 64b56c6a953337f4618fa2a3497f4f307172e84c288809224b91c5317ffc34be
MD5 10130dc6501b34de4fd547e76af23dfd
BLAKE2b-256 4a6fe71626a2313d533e23e3c8fa640103d0e6715eda31ad97006d70e42119bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9d5a653671e2e9e62b41797f144ee40a528b2193a7f150d0e56c4fdbb9eddaf2
MD5 04780f25a39c40c3754b941f0f513092
BLAKE2b-256 97929aae9a52ed90c579358688ccd173dcb0762812161fd732e4f7107e278119

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 be347e152e7e01bee209370ffbee955fa0d641069a817ba9b32a0af79a5917d2
MD5 ef3ab1255f2a6a59468fd16190c5cc4e
BLAKE2b-256 d4342fa07608811a6e5f2ef250954de0d43034b0386fa21d421fd6d4f45fc319

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e8fb738707a76da54751b3d06b90ba9f0464b9de167504ac76d86d5c0e473be5
MD5 575667d222eca97d8fc3cea066406c9e
BLAKE2b-256 4acaae60acf07e08f7e6fe135c1c6af1305c058d2cfc984345037f3f27efe359

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 06ecd626e73353efab2f63aebf0c028a9fb3c6ebfe3acddcff818e1c9fdb03e5
MD5 1813cb3cb6ff93b68fd0259582a2adc8
BLAKE2b-256 937505fcda1777acbd4f1bda6c8c301ddf4eeb01c526841f01a58a07bc4f7bc7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 12c36e676235f152b6f56ba314934ddad5d29b03cf5ea697a7d2605540710b6d
MD5 288ca52d0c43e40b9c11826c2e9b00b9
BLAKE2b-256 a902417aecf7bc1832a39e09786c10ba8029ff7fa6b2e9112960797513ef1934

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a8a8ce8103b4849002381c9498aec159052aff72c8f2208522d96841297f462b
MD5 0e516810d5856a36db7b0f222dbb058b
BLAKE2b-256 1571497fb2002432c8100f3d283731d970b4aa0bf42cb9f1ded0f9efde1c873b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 03f395b42402abe6e865d2a1ef36cac65e69feabfb352cde0781667bd5c45dda
MD5 de749c887c8b403f6b59a8404b9b43c8
BLAKE2b-256 b02f993e1a4663dff317bfcaf65ff5652350c94adeb7a28689d66d31dba15fec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.4-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 512ca8e45987678f75d73023b1dcb7e57704cc57270a95b0d5a0cb37283929cd
MD5 a6d9462dce318e602b80adedfdb08de5
BLAKE2b-256 468209fc40cfd458ce631c021290c5cefc80fb241e5b88ba9e32e6f687e56ab4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.4-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 3874d6b959b93b3409a8da914becd684b0168d91a42bc768701cb8493457ba93
MD5 c907c058beedc7f17d15d1fa461eb860
BLAKE2b-256 97f6190b81c3f87fd1e8368d6d8088a48a933b3c6ebb824e2f51b9a9b63a8903

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 24429962373d23f564fb159879af6844a7efb864693fe526e5d63fe1b5b762ff
MD5 2220c81c13e8949774a5ab249d8b43b9
BLAKE2b-256 5642fffbefa01413a1a640a0d3fbaae90a39d76b25a806d74bafa03787a043ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.4-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5d77b0f0875f339d8d2f10a7b715314838cffb5d20271c9ca52ec82f3ae76ee5
MD5 605372fdc4ea17ad0f0642278082a992
BLAKE2b-256 ee37fac496d3c7d31c860397877816c238b744cdc0bc088823b27f64c209591e

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