import numpy as np
from vicinity import Vicinity, Backend, Metric
# Create some dummy data as strings or other serializable objects
items = ["triforce", "master sword", "hylian shield", "boomerang", "hookshot"]
vectors = np.random.rand(len(items), 128)
# Initialize the Vicinity instance (using the basic backend and cosine metric)
vicinity = Vicinity.from_vectors_and_items(
vectors=vectors,
items=items,
backend_type=Backend.BASIC,
metric=Metric.COSINE
)
# Create a query vector
query_vector = np.random.rand(128)
# Query for nearest neighbors with a top-k search
results = vicinity.query(query_vector, k=3)
# Query for nearest neighbors with a threshold search
results = vicinity.query_threshold(query_vector, threshold=0.9)
# Query with a list of query vectors
query_vectors = np.random.rand(5, 128)
results = vicinity.query(query_vectors, k=3)