Skip to main content

A tiny jit vector database with minimal dependencies and maximum performance.

Project description

Tiny Vector Database

A lightweight vector database designed for small projects.

Features

  • Just-in-time (JIT) compiling to optimize vector operations by setting the vector size at compile time.
  • Accelerates vector operations using Eigen.
  • Processes vectors using only Python lists, no need for any additional third-party data formats.
  • Stores vectors as base-64 encoded strings in a SQLite database.

Performance
More than 10x Faster than numpy-based vector operations.

Development Status

It is currently compatible with g++ or clang++.
You may need to modify compile_config parameter in VectorDatabase initialization to inject your compile commands.
To make it work with other compiler, you may need to change tiny_vectordb.jit module.

Installation

pip install tiny_vectordb

Good to go!

Uninstallation (before version 0.1.11)

Uninstallation

Previous to version 0.1.11, the package will emit some compiled files in the source directory, which may not be automatically removed using pip uninstall, so you need to run the following command manually if you want to uninstall the package comletely. (After 0.1.11, you can also use the following command to clean up the cache files.)

python -c "import tiny_vectordb; tiny_vectordb.cleanup()"

After that, you can safely uninstall the package with:

pip uninstall tiny_vectordb

Usage:

from tiny_vectordb import VectorDatabase

collection_configs = [
    {
        "name": "hello",
        "dimension": 256,
    },
    {
        "name": "world",
        "dimension": 1000,
    }
]
database = VectorDatabase("test.db", collection_configs)
collection = database["hello"]

# add vectors
collection.setBlock(
    ["id1", "id2"],             # ids
    [[1] * 256, [2] * 256]      # vectors
)

# search for nearest vectors
search_ids, search_scores = collection.search([1.9] * 256)  

For more usage, see example.py.


Designing Note:

  1. No numpy array is used in the database, because I want it to be as lightweight as possible, and lists of numbers are eaiser to be converted into json for communication with http requests.

  2. The data are always stored in contiguous memory to ensure the best searching performance.
    So the addition and deletion are preferred to be done in batches as they envolve memory reallocation.
    Here are some useful functions for batch operations:

class VectorCollection(Generic[NumVar]):
    def addBlock(self, ids: list[str], vectors: list[list[NumVar]]) -> None:
    def setBlock(self, ids: list[str], vectors: list[list[NumVar]]) -> None:
    def deleteBlock(self, ids: list[str]) -> None:
    def getBlock(self, ids: list[str]) -> list[list[NumVar]]:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tiny_vectordb-0.1.11.tar.gz (22.1 kB view details)

Uploaded Source

File details

Details for the file tiny_vectordb-0.1.11.tar.gz.

File metadata

  • Download URL: tiny_vectordb-0.1.11.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.5

File hashes

Hashes for tiny_vectordb-0.1.11.tar.gz
Algorithm Hash digest
SHA256 578e01a67224c08702e706f6b3734df197f1fa701010e54f56663a16fd707eb1
MD5 46aa0dd54cb1609087758597f8bacc91
BLAKE2b-256 518db24db4510a0efafbbd07279d1dc0074fc00d9a619b53edcd9a91e0b66ff1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page