Skip to main content

Local, in-memory vector database

Project description

Locus

Locus is a local, simple, in-memory vector database.

Why Locus?

  • Easy to use
  • 2 dependencies
  • Store database locally

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(results)

# store the index on disk
index._store_on_disk()

# load the index from disk
new_index = Index.from_file(config.storage_location)

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

locusdb-0.2.0.tar.gz (7.4 kB view hashes)

Uploaded Source

Built Distribution

locusdb-0.2.0-py3-none-any.whl (8.2 kB view hashes)

Uploaded Python 3

Supported by

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