Skip to main content

Vector Database Lite

Project description

Vector Database Lite (VDBLITE)

Vector Database Lite (like SQLITE but for vector search)

To discuss VDBLITE and ask general questions, use https://github.com/daveshap/VDBLITE/discussions

Quickstart

  1. Install using pip install vdblite
  2. Run a test with the following code:
import vdblite
from time import time
from uuid import uuid4
import sys
from pprint import pprint as pp


if __name__ == '__main__':
    vdb = vdblite.Vdb()
    dimension = 12    # dimensions of each vector                         
    n = 200    # number of vectors                   
    np.random.seed(1)             
    db_vectors = np.random.random((n, dimension)).astype('float32')
    print(db_vectors[0])
    for vector in db_vectors:
        info = {'vector': vector, 'time': time(), 'uuid': str(uuid4())}
        vdb.add(info)
    vdb.details()
    results = vdb.search(db_vectors[10])
    pp(results)

Class Vdb Methods

Vdb.add(payload)

# add a dictionary
info = dict()
vdb.add(info)
# or a list of dictionaries
info = list()
vdb.add(info)

Add a an arbitrary number of records to self.data (master list of data) of your Vdb object. No checks are performed beyond data type.

payload

Payload must be either a list or dict variable type. For instance:

info = {
	'time': 123.456789,
	'vector': [0.1, 0.1, 0.1, 0.1, 0.1],
	'uuid': '174657a5-ba76-47a8-a121-5fda05dde560',
	'content': 'lorem ipsum...',
}

or

info = [
	{'...'},
	{'...'},
	{'...'},
]

Vdb.delete(field, value, firstonly=False)

# delete all records with timestamp at UNIX time of 123.456789
vdb.delete('timestamp', 123.456789, False)

Delete record(s) with fields that match a given value

field

Specify which element within each record to match for deletion

value

Specify value to be matched for deletion

firstonly

Optional. False by default. Will delete all records with fields that match value. Set to True if you only want to delete a single record

Vdb.search(vector, field='vector', count=5)

results = vdb.search([1.0, 0.0], 'vector', 5)

Search for n number of records that are most similar to vector (cosine similarity). Specify field if searching any other field than vector.

vector

1-dimensional numpy array to match your query. Performs cosine similarity against all vectors in self.data

field='vector'

Optional. Specify which field contains the vector for comparison. Records can contain more than one vector. For instance you may have vectors of different dimensionality, or from different models for different purposes.

count=5

Optional. Specify number of matches to return.

Vdb.bound(field, lower_bound, upper_bound)

results = vdb.bound('time', 123.456789, 987.654321)

Return all records with field value between lower_bound and upper_bound e.g. all records with a timestamp between two specific values.

field

Specify which field to compare in all records.

lower_bound

Minimum threshold to return.

upper_bound

Maximum threshold to return.

Vdb.purge()

Delete self.data from memory and reinstantiate.

Vdb.save(filepath)

vdb.save('my_data.vdb')

Save VDB data to file

filepath

Relative or absolute filepath of save file

Vdb.load(filepath)

vdb = Vdb()
vdb.load('my_data.vdb')

Load saved VDB data into memory

filepath

Relative or absolute filepath of save file

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

vdblite-0.1.4.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vdblite-0.1.4-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file vdblite-0.1.4.tar.gz.

File metadata

  • Download URL: vdblite-0.1.4.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for vdblite-0.1.4.tar.gz
Algorithm Hash digest
SHA256 2f941ca19c56c13ec1769c73489923c6aabe9bf2dbf14b453072d0dbb1d3d0d2
MD5 04aaf0e2c9f0beb00591cc3d81395f10
BLAKE2b-256 a45b3b5cd3f39e911236bf44dd9ea8c54393c7ea344d5da26fb09d3c3c1ea4f1

See more details on using hashes here.

File details

Details for the file vdblite-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: vdblite-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for vdblite-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9ab9783552fc2a0a7efc1e8f860f0cda64d39eb8916e0a7da65e0d745094dd39
MD5 2722dc249c90b0e8f4d452c3a2596c8c
BLAKE2b-256 b6d64a1703ca2abf35f56199c96cf6d15d132b387ffbce5b114e03f564c0a63a

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