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

Uploaded CPython 3.11Windows x86-64

lab_1806_vec_db-0.6.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (825.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.3-cp310-cp310-win_amd64.whl (604.8 kB view details)

Uploaded CPython 3.10Windows x86-64

lab_1806_vec_db-0.6.3-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.3-cp39-cp39-win_amd64.whl (604.9 kB view details)

Uploaded CPython 3.9Windows x86-64

lab_1806_vec_db-0.6.3-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.3-cp38-cp38-win_amd64.whl (604.7 kB view details)

Uploaded CPython 3.8Windows x86-64

lab_1806_vec_db-0.6.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (827.1 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1c5bfa67b919674e0ab18ab33ded25673980a4433f90532407372d5cd3ad0884
MD5 153f188b218ebb56d2959c331b7f877f
BLAKE2b-256 102c80e0d088b82b8891595028f9e1cd01d5c6e4dc171d17ea0d16e7ad40acba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2561a5b9d58f26c311d6593416a2e7a9a6ebeba0711980186493cd382a32bd4c
MD5 83ed4baa4343beebe90f916112287c36
BLAKE2b-256 5e9a1a1f99ad8d4e240582b6520216ad57927740325fd2681ded5307908aa1e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7469850da25a2166d002ca1c4df5a2e67969cb5e7d161db5ad9cebc4d7061e5d
MD5 1c5b22402a079cef9cfef279833f88bd
BLAKE2b-256 0aae9b0f9c941d325e6ddb2d235e486e44fd01fa1657a3065d1028e5bddb5c1c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2aa31f431a819416e031d02ed42c7ee40fe8660ff2180e8095f0c86cca3aec3a
MD5 262507fd8a2afb2c7fd360e68fca9330
BLAKE2b-256 7fa142d189c4e305763774aad9eb70c869a841208092d3ea4a1c7532cc71c0b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 7bd3b5059ff43ed19cf88780a69e6e6200b9958e152b0f51bfd1951713ccc3d1
MD5 ec824f8e6ca4e0a8451af2768f0a76c9
BLAKE2b-256 b9bc314a7de8fb1e075941b80183509a7fced996a7975a4d8f6366aebdf079dd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 09ae84b2046b5fe09ac6a8bfe13a35e467780a79d7ef76443434d30f92bc22f6
MD5 4341ab627fdb377adf479b3c59d434b0
BLAKE2b-256 6e1b5580751541e756e4f01bbef75d133ff788ea6728f633a26c69d7812be39a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 11d6d2135ac6682a3c3b4bd8d7e09cc6f2648f96236a9d2b043b7fb6d782d07a
MD5 64b2cccf193b561f500d99974ca07ba1
BLAKE2b-256 76ff7c7b3332e8ce1d06b97afdd3108b6fed2889a08f4b68cf7bf162f06ebf75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1c7faf90f500265d5ba13880a366320b6be5c09c8af1ab62bf616150699ce42f
MD5 8d20809c362a7f9a56a920b2b11d192b
BLAKE2b-256 17e92df5f5b0cba43864b171cb685e73447d7f707e544701670bae23df1f135b

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