Local, in-memory vector database
Project description
Locus
Locus is a local, simple, append-only, in-memory vector database based on hnswlib.
Installation
pip install locusdb
Example Code
Some example code to illustrate Locus' functionality.
import numpy as np
from locusdb import Config, Vector, Index
# create a new configuration
config = Config(max_elements=1000, ef_construction=200, M=16, dim=128, space="cosine", storage_location="index.db")
# create a new index instance
index = Index(dimensions=config.dim, config=config)
# create some random vectors
vectors = []
for i in range(10):
embedding = np.random.randn(config.dim)
data = {"id": i, "message": f"test message {i}"}
vector = Vector(embedding=embedding, data=data)
vectors.append(vector)
# add the vectors to the index
for vector in vectors:
index.add_vector(vector)
# retrieve the closest vectors to a query embedding
query_embedding = np.random.randn(config.dim)
results = index.retrieve(query_embedding, number_of_results=3)
print(f"Matches: {results}")
print(f"Items in index: {index.count}")
# store the index on disk
index._store_on_disk()
# load the index from disk
new_index = Index.from_file(config.storage_location)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
locusdb-0.3.0.tar.gz
(7.5 kB
view details)
Built Distribution
File details
Details for the file locusdb-0.3.0.tar.gz
.
File metadata
- Download URL: locusdb-0.3.0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.10.11 Linux/5.15.0-1036-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6dd1aa70c17d7c446b22738a385573afe9078753839fd8ccfcb9760e81f2ea3 |
|
MD5 | 598d4178d00f67f0dd0cfef2ac82489c |
|
BLAKE2b-256 | e3a2be03cf4263a95fad8d90dc343732fc517c00913dee940c623e62cc2fb446 |
File details
Details for the file locusdb-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: locusdb-0.3.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.10.11 Linux/5.15.0-1036-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc6392ae8f4c165765a46c3eedb600f28438e96c754d93a6ed93693eb575afbc |
|
MD5 | 50322e1d47c095dd26dc410586ca3630 |
|
BLAKE2b-256 | 3468cf5e459da454d173d93818e501e0800122331a7a14f221dfd000ed1b3619 |