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

Uploaded CPython 3.11Windows x86-64

lab_1806_vec_db-0.6.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (825.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.10Windows x86-64

lab_1806_vec_db-0.6.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (826.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

lab_1806_vec_db-0.6.2-cp39-cp39-win_amd64.whl (605.4 kB view details)

Uploaded CPython 3.9Windows x86-64

lab_1806_vec_db-0.6.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (827.6 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.8Windows x86-64

lab_1806_vec_db-0.6.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (826.8 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 270fd8f97ff305bbb7f5faef3fa535cc144b55767acb08c3955dde543d6df205
MD5 1b11f6ff14843108d2859f7195049c84
BLAKE2b-256 fe44a2d568e16361f6f0a0333a10eb05bc20adae9af746d34b95dbf8a5a72b41

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 161859896a4bbf0f716f135840f8fefb6201614fe5c59996235a0e608ec004ea
MD5 52b218fe52bffd2acc75ebfa496b66db
BLAKE2b-256 3dc35cc80bef576ad2617c8f59d88b010b8e1160576a1e94407f8dd6714c2bd5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 98227c0c30da7f6860d04f2d2a77d4e14d5c35fde206a3942362f7672b904d92
MD5 04ca3ed5107e6366f8f4848a27d324ad
BLAKE2b-256 ecbe7f37ab69cd0761e2016cfec5f54ba0d8fdca3fffb104c49cf30252fff0b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4a4b497470ec72c92dafd5427cd78f3ceafd0240a08ca7c3539dfee877bf496a
MD5 184a7189e68944a6998fd19c819b38aa
BLAKE2b-256 7a96dc282711aaec19964e46202b44ea08b7ce1bb56a6b762e95997cba3226a6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 9ee7f4e8ab8e77085342a229757fbdee76d51f153fc8a44ec4be8acdc0316e52
MD5 aacf4bee7f3500e6dc84df1763f22937
BLAKE2b-256 733701cfcdcd765d905536f45d06280c18bc8d3919b6200e86972c314fbd8cf1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ee5ca6f85e2e33723b093781b954d643f8d6a9e7a6849ef88ee6b7128705b2de
MD5 f5dd9bdb633867a4d8a67682787d2226
BLAKE2b-256 48433700c46b7746d22d47b768cf850369b4701d422e46445ad6a24fb8f65a4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 8f47570e9277d4f95e9192b0241c9891ba3499531c2705eaf992c5a5fcc37890
MD5 3014e7c7e6eeb8a5ebe1c0c17e99e7d5
BLAKE2b-256 b4433af2aed13686782d3333fdce6b65aa8d8f356e93462de6b0b3bb81774a12

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lab_1806_vec_db-0.6.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7c1ada3f946d12bdbd49cca541aa871a4d3aec6aa74df1d014df45f1462caf6f
MD5 f47a2664626ffa6d1814ee4d90b2e3af
BLAKE2b-256 e171463cb197a2bd8c3d1904cc799230347495321fc0eef6f32c478ed7fa8025

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