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

Uploaded CPython 3.12Windows x86-64

lab_1806_vec_db-0.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (847.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.8.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (821.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.8.0-cp312-cp312-macosx_11_0_arm64.whl (746.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

lab_1806_vec_db-0.8.0-cp311-cp311-win_amd64.whl (621.9 kB view details)

Uploaded CPython 3.11Windows x86-64

lab_1806_vec_db-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (848.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.8.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (820.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.8.0-cp311-cp311-macosx_11_0_arm64.whl (751.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

lab_1806_vec_db-0.8.0-cp310-cp310-win_amd64.whl (622.6 kB view details)

Uploaded CPython 3.10Windows x86-64

lab_1806_vec_db-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (847.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.8.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (821.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

lab_1806_vec_db-0.8.0-cp310-cp310-macosx_11_0_arm64.whl (751.9 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6a185ed182dbb69b761df7c5a5fc0079955f41c13a64392f3dbf95f93fa9ed8a
MD5 b8f21d2f6a33c8e1347aedc9d2c456dc
BLAKE2b-256 b95b465190ad749530601f4d712809caad423c32be83fefcf4e870b544bba0be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 24329fdaa43aae8bd3904c0666be8ca4f428f3775ff64b0bdad8800c6c5070a7
MD5 7820fadceaa84a6c5dd6da9dc2218740
BLAKE2b-256 10cc362a5fef3a6dbb96898c9304604549554869839be76a7dad49df47777afd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ec56095002a9e155aca2657a5f7db982b51ede3abb938cc9e9c37132444fb600
MD5 e683a7efa52db1c3d55ebd0c7b631425
BLAKE2b-256 b079f86b05187fcc606f547f55ee7b4920a46a44b209beabe18e41999b4d8878

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 75c5b2aa57d84518c16e434eaf158c7a77cabd43435a4d4afc7efda8131dbcbf
MD5 3270529c757c224c70b83671d51d157a
BLAKE2b-256 538879cca5685a2e4991244c3a99fad2a57e30d10415db4ad9e3010abdc574c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 84fd4aad8fe219234f00604b0ceffd19e1d7527b31b6677b162399ee506356ea
MD5 93a04d5af21221778bb3b68524a46eac
BLAKE2b-256 0086d5176027502c4ca74ece88b922237b1b202454a74a00eeeba3224439e9a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c2de07a798e69ba0c3e9a5df0e80df1d0c54152f2dd059c5f16c5e355e0b0b42
MD5 17d7329f0f82898991125a3b2efdb6db
BLAKE2b-256 c172e74f62cb7141405b8a54801eb598cebef9bc9572712911c5cfde5ae29cb7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 52f0ee63a8a965d194d988a0d8afde6fc7b13749257033f5810de37a06029327
MD5 7d029f79c88ebda535df934803c0db3d
BLAKE2b-256 642d470d8842ece24e8f1a06b61a65003a20a986d67821d6dffa905235440ab2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 df653ac97bf30774760a17c4f571376c19a17638dc662188f9be60a3b06d9b56
MD5 6be57fc813b9041cb8d59c689eb91de1
BLAKE2b-256 3360b1e7bca62f9228e767d074893b200caa00d9c372e9927b91a0becbd9b7dd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 15d1546e27f5916ddd0e48af08d215c4c0f763321a27e88ec3a28737327e36cd
MD5 87f84761f0676ecc6509a1d86716677d
BLAKE2b-256 fb959114c66112be48afcd70ce8fe8363f7e156343ab08892c047ad09b469798

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5c95586d882c197c6eb6971b82bb66c7f6032fa6c0dbd0101b4d5befc1bbc19f
MD5 bb818084d7d0df05bc47579adaf839b5
BLAKE2b-256 6fbaf8b306dea5fcac0fc9028ee48947fdc36f9c6f53aaeb9ece69d82771d1d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 90c105bc16c2518546c5ffbf24f1529b2f6b3749979d49f6e3d5f3c684d48ec3
MD5 89ff6c1aeeea7608a1ac22f395b34f9a
BLAKE2b-256 6d0d4bb0652793a031daeb67607ec482fa732dcd04442fee765c92d5927291a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.8.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d99bc5c77dc46f8edb674b97828c7fad9d453101b00b1dda9a3e547d08d4d7aa
MD5 7548c2851cbcc2b0804720ed67787af7
BLAKE2b-256 bb27e3202f77069e975a05ea4d1b6257f86d250376cdd0303d86be08363a8896

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