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.8.1-cp312-cp312-win_amd64.whl (665.7 kB view details)

Uploaded CPython 3.12Windows x86-64

lab_1806_vec_db-0.8.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (898.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.8.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (875.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.8.1-cp312-cp312-macosx_11_0_arm64.whl (789.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

lab_1806_vec_db-0.8.1-cp311-cp311-win_amd64.whl (664.5 kB view details)

Uploaded CPython 3.11Windows x86-64

lab_1806_vec_db-0.8.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (898.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.8.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (875.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.8.1-cp311-cp311-macosx_11_0_arm64.whl (794.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

lab_1806_vec_db-0.8.1-cp310-cp310-win_amd64.whl (664.5 kB view details)

Uploaded CPython 3.10Windows x86-64

lab_1806_vec_db-0.8.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (898.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.8.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (875.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.8.1-cp310-cp310-macosx_11_0_arm64.whl (794.0 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f50e1bfb9146e6aa50d8b11e07a3a753ac56277c42db56a8fcae5376d2b55c14
MD5 07f01d486b6c580fdf371b47411a0159
BLAKE2b-256 244db2db958384fafa02b8c86d227de2dc0ddd875273313a4e2d8f5cb13c97fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5f8a1c5e64c74c61a49a1729cd1765b5c0dce8752be81349c7697066df23d24b
MD5 44ce64411958a2650bb8c83ea2f74c35
BLAKE2b-256 d3e493e41fd625528ad799f77232a7e016c68ba191f514fcbc169aba5d3840a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0333aefb8212dbf68844c96dff21a10748b9cecdeccaa381181ab2448fdc9021
MD5 63df39172a728ecd0e1e5782f43ad723
BLAKE2b-256 ca41c7a56533b89bdacf29f08a96fab7db741c2cf8bbf6d8372f4a7fb05f7eb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 94abb61be47255ab077c704498ecd9ca47c3ad444951a1c31647e28771f0109d
MD5 5f24231419f37e92917b8ac75992aac4
BLAKE2b-256 3fd477f385e567ec4c9e21e4d4a9bc43a41ae5c96f2086a16664582b0dae5f02

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 06ec7a1c2c947409fd08ea4fd33b662c0048db3f4d772786fd1bbc75293abca8
MD5 7f6b6bbcd5e71b1f3f5db5073d1a8dc0
BLAKE2b-256 45eab52381a8dd9a062f443d0df30ce02e12755370a7bedecbdaf6ded2c3a285

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ec9bd69d1704e6f77d9ba48261b4529d68ba2fb6ae15516b16cb1ac7ea3c8014
MD5 e0f53775265838e45df1ba0ed40ffb5a
BLAKE2b-256 182a5a9a73bab5e11b92db3e921f91d74c69754b00d8eb20f1e76faff0dfccc6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 be863210d468a88fc3046bdc4806aad68f1172e4d09e3d20c764fea7fac62be6
MD5 18e678ca7ff58df2ad31f01fbeda23da
BLAKE2b-256 71a63a8c86e9c07afe50fb74145e2adca68c94ab04b30f2de1f8c9678380a767

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bcbcd1119710ddd763ef40da4e57d72fcba515de13fe40c543b9e5212046e309
MD5 dd25221ef809c2528df7b9848fb66a82
BLAKE2b-256 53d9c2329334ab3fe98d6b20b818e452557a62e246e71b4cf1a946e212586f75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 31ff4fdc325cc80090c62c2dc39e095e13f43b37afc05f890f9ef8d1dbd49880
MD5 873d7d969d48e57827e3defb4fa61814
BLAKE2b-256 912ef9ef1af0a94da77abf56a15a098305f32ec36c280f105a1ee2e18fbd2584

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a08e866d4cc7990b5464efb91479dea8629df559da22cbe3ee174f051c72f05f
MD5 f49ba728ece894f82f4da5225b2b8dd7
BLAKE2b-256 1b2fac2e105df243ea6d87072bdd6da9eb1e0b1acb4c8de699289f782d3fb1d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d19e2f4c0d0619d936164ce54171c6baabde30334591b6ef3f52608389b9a4b3
MD5 457ccdebdd6be1434a0c3424d8069b98
BLAKE2b-256 b586aae8182581465963564419c8dda85c6f5a10f554ad05a45e4ad80ad40ef9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 afe9445734d61c3a139dd55ab922f2105f9b07ac86b3cfeac3fb8bb18fab1fcf
MD5 2bdf9d32a0955a2cdf49630f43dce7b4
BLAKE2b-256 ffce1e3b50dc6013a5bebdad8672c23e6583ebd0e01bfff96948106a098b498a

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