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

Uploaded CPython 3.11Windows x86-64

lab_1806_vec_db-0.6.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (845.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (822.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.6.5-cp311-cp311-macosx_11_0_arm64.whl (722.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

lab_1806_vec_db-0.6.5-cp310-cp310-win_amd64.whl (605.3 kB view details)

Uploaded CPython 3.10Windows x86-64

lab_1806_vec_db-0.6.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (846.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (823.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.6.5-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.5-cp39-cp39-win_amd64.whl (605.4 kB view details)

Uploaded CPython 3.9Windows x86-64

lab_1806_vec_db-0.6.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (846.9 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.5-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (823.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.6.5-cp39-cp39-macosx_11_0_arm64.whl (723.2 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

lab_1806_vec_db-0.6.5-cp38-cp38-win_amd64.whl (605.1 kB view details)

Uploaded CPython 3.8Windows x86-64

lab_1806_vec_db-0.6.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (846.4 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.5-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (823.4 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.6.5-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.5-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 bce6d4222c20d988b14ee83427c0dcbac288235fbaaaf0a60b2d9ca3877380e9
MD5 f7731baeaffa4dc50d04c14461cdb96d
BLAKE2b-256 ece5ce26449a860809f571f4f73fac7b38f98d46a4301b9260ba4245632952e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f7fba6e4eb2e8e5df10b3e5663b715e35b1fb25920d0ec0f5adde924231553f1
MD5 27f3aa4b84ca6458d282971442f57015
BLAKE2b-256 98e7d5e49bd2292be5fe8eeb12038295739039a70a7a2c8c3d59c92bc69b9ea8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 540a006ea662127b5665cbdc2025636a01e09b54ad8ac16c5bca3c62b2370918
MD5 dd84ca2de5ac1f2d7a6295b2814dbccf
BLAKE2b-256 a33ce301809c47bdcaf201d6b88f4e0487bed33ee9614e9ba37f209475cfaaa4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7186393e87004194bdbb81fa5086909b016af880c780877ea94b03f2eccd6014
MD5 d23dc1c734a025673cfe7402aa82d3b7
BLAKE2b-256 5bdc2d96d6f44bc699c5feb7898af74af6be17207d6d608b89eff15ff885908b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 216bf11aefc71b37f7b7d94994d977e4ad0f9d4454c6659160071b9122b866e1
MD5 54a0f153b61f2311adfb152b50171c1a
BLAKE2b-256 a254660ad9624051dc56e28e2c05883c93756179689b329a3b5ac2036a9719a6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 02071454e5bfc9f4c0538e76dc864ebb933e209ce50f5de2e20f92badf62cfa2
MD5 f5c9d38529234382cdb34ca82c089612
BLAKE2b-256 842618c09c928e3812962f67e2492aa46b3adecf327439a05faade0a879c700a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1e59f0ca21c13e45c6cbe597b7ea1e606e4ad86ff88bd3888c71802e63de9188
MD5 825ae7ce57f1dc4533af7143dad9558a
BLAKE2b-256 926ebd162533e35619f5ccb7a0239d1fe950263c63a1e0a526041268e3c23858

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cdebdd183a013778a016cb96b2eb6b9255e8f96c54d635fdfa4d30012beb0b7a
MD5 40a9a9dc465c263fda0b3402605203ec
BLAKE2b-256 f841fab3f036a7231eb87290357a76b2bf1cacb01db7f0cd6c9e687587a7f9d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ce4c56600f508c53fdb437e59720b8c0cdc808e49715614ff6fa83a88beebcf0
MD5 0ac79ef84ed683e5a7598c58ff2b5a80
BLAKE2b-256 99c6c5a813e2c89d3572813a8e4e0dfa9dc0fedd993d7b1d93cc68ba2d24d0ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fa16a195467dcdbd53560056402e62fc7cf14eeb35b4c5d2edb770b102ced03a
MD5 593dfdf638cc66876db6f6296e16a4f4
BLAKE2b-256 ec543fe77499418f67bff27f624cfc102ca52358c4e9c2278574132a4be5c94c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.5-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b5ea73d8bf23296d49d65b44268b34e7e2d2ecb1ec8e24c7f598365c5b65c998
MD5 ad964ea97f70508f8592ff1550dc78bf
BLAKE2b-256 aaa68f3597b9eb13209efa9dc4715e054f34379c7f8a7cf6152e7726d089f8cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 227d63f527af152b26cd81a023c8d285a5e337472c2f29b8e580092e233885b7
MD5 57b1fcd6ce0733e9e0820e8e401030ff
BLAKE2b-256 d9f063831fb8cada5c1255055a0a8b94a1bf8f5b72bb9ccdb8ff0c6fa2711431

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.5-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 97351cee210b6b76d13305a0f23ed5c5ab4810e1a9f066b35b03354f4b5ea643
MD5 3b7d9a886322e4ab2bfc92062ea34c93
BLAKE2b-256 0642f02a3901ef547cd76c01fed96e7c0afa9f8e19e7405cd44cecd65daaa418

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c5bbbe302175e8782ac516ebb710872bca48c35fcb7f6471b82ec0cb7c4465ec
MD5 f4be1841a4f0eb3eb614898d16773695
BLAKE2b-256 b7ec3a46809fa0d7255abc3fc3501de14d7355d17e5e947e62f25e91263d58a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.5-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 febdf3fd257b6c81645ee65c914eec6e7862ecf2c84c2679a49710cb2a9c2b27
MD5 a7af44d2694cacf9d3a28b5ee285b6c4
BLAKE2b-256 f2e72124ac227a26862f5407462ab175f75255c2bd3553beecd4478492c2c52e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.5-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2cc634e3494609de44840c2e1b6051a74ff99b938a2498d3a8b4132a1a24279e
MD5 514e054c4c36d392b4b6236a3660d71a
BLAKE2b-256 7e18da0b858930e9fe29b5c212b13cebee4e9b1134994dfc5703466a57889fdd

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