Lightweight Nearest Neighbors with Flexible Backends
Project description
Vicinity: The Lightweight Vector Store
Table of contents
Vicinity is the lightest-weight vector store. Just put in some vectors, calculate query vectors, and off you go. It provides a simple and intuitive API for nearest neighbor search, with support for different backends.
Quickstart
Install the package with:
pip install vicinity
The following code snippet demonstrates how to use Vicinity for nearest neighbor search:
import numpy as np
from vicinity import Vicinity
from vicinity.datatypes import Backend
# Create some dummy data
items = ["triforce", "master sword", "hylian shield", "boomerang", "hookshot"]
vectors = np.random.rand(len(items), 128)
# Initialize the Vicinity instance (using the basic backend)
vicinity = Vicinity.from_vectors_and_items(vectors=vectors, items=items, backend_type=Backend.BASIC)
# Query for nearest neighbors with a top-k search
query_vector = np.random.rand(128)
results = vicinity.query([query_vector], k=3)
# Query for nearest neighbors with a threshold search
results = vicinity.query_threshold([query_vector], threshold=0.9)
# Save the vector store
vicinity.save('my_vector_store')
# Load the vector store
vicinity = Vicinity.load('my_vector_store')
Main Features
Vicinity provides the following features:
- Lightweight: Minimal dependencies and fast performance.
- Flexible Backend Support: Use different backends for vector storage and search.
- Dynamic Updates: Insert and delete items in the vector store.
- Serialization: Save and load vector stores for persistence.
- Easy to Use: Simple and intuitive API.
Supported Backends
The following backends are supported:
BASIC
: A simple flat index for vector storage and search.HNSW
: Hierarchical Navigable Small World Graph for approximate nearest neighbor search.
Usage
Creating a Vector Store
You can create a Vicinity instance by providing items and their corresponding vectors:
from vicinity import Vicinity
import numpy as np
items = ["triforce", "master sword", "hylian shield", "boomerang", "hookshot"]
vectors = np.random.rand(len(items), 128)
vicinity = Vicinity.from_vectors_and_items(vectors=vectors, items=items)
Querying
Find the k nearest neighbors for a given vector:
query_vector = np.random.rand(128)
results = vicinity.query([query_vector], k=3)
Find all neighbors within a given threshold:
query_vector = np.random.rand(128)
results = vicinity.query_threshold([query_vector], threshold=0.9)
Inserting and Deleting Items
Insert new items:
new_items = ["ocarina", "bow"]
new_vectors = np.random.rand(2, 128)
vicinity.insert(new_items, new_vectors)
Delete items:
vicinity.delete(["hookshot"])
Saving and Loading
Save the vector store:
vicinity.save('my_vector_store')
Load the vector store:
vicinity = Vicinity.load('my_vector_store')
License
MIT
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
Built Distribution
File details
Details for the file vicinity-0.1.0.tar.gz
.
File metadata
- Download URL: vicinity-0.1.0.tar.gz
- Upload date:
- Size: 49.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73c6839ab28203bd7f25b6a37a5f0c04105e191817a968df0d48ad68a94f8e90 |
|
MD5 | 0bf4abb8262ebd1d5731ebecc874caa0 |
|
BLAKE2b-256 | 30082b6e973a5a5bbf9bb7928f4a2aeab48fbde0791693859a3f2d858ee59ab6 |
File details
Details for the file vicinity-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: vicinity-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92726eadcc632c2a03a647f1a80858cbb6fee86e5fb7ab87f747333b80918098 |
|
MD5 | fa5babf9f311f95c479f745c1a6fe0c7 |
|
BLAKE2b-256 | ebb46880b852659c214127c7414fac5049a463ee55c243945117722256093652 |