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.10,<3.13 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.7.2-cp312-cp312-win_amd64.whl (621.1 kB view details)

Uploaded CPython 3.12Windows x86-64

lab_1806_vec_db-0.7.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (845.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.7.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (823.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.7.2-cp312-cp312-macosx_11_0_arm64.whl (741.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

lab_1806_vec_db-0.7.2-cp311-cp311-win_amd64.whl (621.5 kB view details)

Uploaded CPython 3.11Windows x86-64

lab_1806_vec_db-0.7.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (844.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.7.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (823.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.7.2-cp311-cp311-macosx_11_0_arm64.whl (745.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

lab_1806_vec_db-0.7.2-cp310-cp310-win_amd64.whl (621.1 kB view details)

Uploaded CPython 3.10Windows x86-64

lab_1806_vec_db-0.7.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (844.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.7.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (823.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.7.2-cp310-cp310-macosx_11_0_arm64.whl (745.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file lab_1806_vec_db-0.7.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 39dd850b1b68cfbf4c6186732d6f678ce3b5b25f4b088a2c78a33c24831f9a51
MD5 b6f5a8d7611c5f8ed8fdb86c5d661601
BLAKE2b-256 17232e8eaa5c9eb9889670c6f714ee419dbbb9729ebd577914406032a81d187c

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.7.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 652dae679551965b3edb8b37f622f85fb1cd68722703a693790a89769479c155
MD5 772e814d94a82ef440e017b8909c249e
BLAKE2b-256 b4bd7896ec8a91af31c15837fd84b78270a5628b0ea2ae1edcb42262ee69f063

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.7.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 eee4dd86914d5978b88bae04ba3cdd3b9779ca4821fd69e30d14e32400803811
MD5 b55fc2ec4996ec5dcb91ad131e6b8f4e
BLAKE2b-256 4c6eb41551a49155f35ed4a725febc8cf71df363f4d4a6d1f55d31a33590f1ad

See more details on using hashes here.

File details

Details for the file lab_1806_vec_db-0.7.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4512a9fe24d33351bfb00f1be29afbb9f0e628cbed9936cc12970fa5ec63b73f
MD5 2cf839192b6fc4eb2f270254274ac4d6
BLAKE2b-256 6bcaa9891e7e5dcb40e7fcc038adff59e5f21a4aefdf71065fbaaab632db91dd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a809db659bdf228fb9e7f62448f13ec90762f5c17b5ba8962a4ea14b0880e361
MD5 a061b221e349a4813436e989a7e4afd8
BLAKE2b-256 cba1ab5301a47fadb6941723a380ec4c7e1625ee6495bbaacd75f67374fe7fad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 32703c97eb1de13c5810035d9648dd142ffd180a2a7c513e4b43408184af28fa
MD5 938f463b35fcd3c1c4d9c400f56dbcce
BLAKE2b-256 f8601f11f4395b16e021b3d03d15c2a4d2670bab15789563a6122015dd93c859

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ec4bc47f733b804f11cbef4ae2a35925b65d0b03c2ee827ac9fb2679b9154266
MD5 1c195696cc6cf1b2717b6c641c93cbaf
BLAKE2b-256 af769c4b25b31dd7d16c5654fa0c7dfa6a0bfc3f1429ea8fa1abda980904b222

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 48dfee975c9d1e0187ee5731e48f26765b91994e706e34d96cdc81e782d70c03
MD5 c8e5c8873acf6f3a22be190554e700e4
BLAKE2b-256 91a96d953e372eb61939d5173540f336649e4308620b0c0e9e7fc7836ca06c9c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c5d4622546d8296c7b8de830d33062b98c04cee5c6b882549006d1f8935e9aa0
MD5 f64d2484584fde4b504370dea8d90629
BLAKE2b-256 da67cd5fbebb5a55948634793eedfd71f5cd0ae272ca76cc11544897f719a841

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1fe0525ae26bc3d6451f5a5a65c7b374a85828c2a69a5d879a0fb9f9dc15aeaf
MD5 e7b5130d17016d161ace1deff1f10243
BLAKE2b-256 28fb5649df24ef3752f76044d09d4c55c31031e006e33c85c9e6658520b44ad1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6221e162743f6e457126c87a6c652625ee4858e171b0d66d01fa719e04588552
MD5 22bfb97e9823687cb0c21a48965548d4
BLAKE2b-256 69728a679133e4753bed6e72e2f273f43e0055c5b60eb697eddb56bffef2022b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.7.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 adfc9f54be93e67bf1e2dd64df92f23be254dd16f34217e265667f84682e66d8
MD5 bdabb46cff80ce2438e3e197bb8a96a3
BLAKE2b-256 d3063e9e678fa490cb19fca16a5e5024cb2d911e560f39e84a47adb3dc58fb0c

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