Skip to main content

A lightweight library for nearest neighbor search in Rust.

Project description

NilVec Logo

Overview

NilVec is a high-performance, memory-efficient vector search library designed for large-scale, real-time applications. It decouples metadata from core embeddings during distance calculations, ensuring minimal memory overhead while maintaining high search accuracy and speed.

Recent benchmarks demonstrate that NilVec outperforms leading vector databases, including Chroma, Qdrant, and Milvus, offering substantial improvements in query latency and insertion efficiency.

Key Features

  • Optimized Memory Utilization: Vectors are stored contiguously, and metadata is managed separately, preventing unnecessary memory bloat.
  • High-Speed Query Execution: Benchmarked for superior query latency, outperforming Chroma, Qdrant, and Milvus in real-world workloads.
  • Flexible API: Rust-powered backend with a Python interface, offering efficient insertion, bulk indexing, and metadata-aware filtering.
  • Multi-Backend Benchmarking: Directly compared against Qdrant, Chroma, Milvus, and Redis with real-time performance tracking.

Benchmarks

NilVec has been benchmarked against multiple vector databases:

  • Chroma: Lightweight embedding database optimized for LLM applications.
  • Qdrant: High-performance vector search engine for production environments.
  • Milvus: Open-source vector database designed for massive-scale search.
  • Redis: Real-time vector similarity search with Redis AI.

Results

  • Query Latency: NilVec consistently delivers lower latency compared to Qdrant, Chroma, Milvus, and Redis.
  • Insertion Efficiency: Handles bulk insertions with minimal overhead, maintaining stable performance as the dataset scales.
  • Scalability: Performance remains stable even as the index grows, showcasing NilVec's robustness in large-scale deployments.

Sample Benchmark Code

import time
import random
import numpy as np
import nilvec

# Configuration
DIM = 128
NUM_INSERTS = 10_000
QUERY_INTERVAL = 100
CATEGORIES = ["news", "blog", "report"]

index = nilvec.PyHNSW(DIM, None, None, None, None, "inner_product", ["category"])

for i in range(NUM_INSERTS):
    vector = [random.random() for _ in range(DIM)]
    metadata = {"category": random.choice(CATEGORIES)}
    index.insert(vector, metadata)

    if (i + 1) % QUERY_INTERVAL == 0:
        query = [random.random() for _ in range(DIM)]
        results = index.search(query, 5, ("category", metadata["category"]))
        print(f"Query {i + 1}: {results}")

Installation

NilVec can be installed via pip:

pip install nilvec

To build from source:

git clone https://github.com/cldrake01/nilvec.git
cd nilvec
maturin develop --release

Usage

import nilvec

# Create an index with metadata-aware filtering
index = nilvec.PyHNSW(128, None, None, None, None, "inner_product", ["color", "size"])

# Insert vectors with metadata
vector = [0.1] * 128
metadata = [("color", "blue"), ("size", 42)]
index.insert(vector, metadata)

# Perform a metadata-aware search
query = [0.1] * 128
results = index.search(query, k=5, filter=("color", "blue"))
for distance, vector in results:
    print("Distance:", distance, "Vector:", vector)

Testing

Run the test suite with:

cargo test

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

nilvec-0.1.8.tar.gz (563.9 kB view details)

Uploaded Source

Built Distribution

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

nilvec-0.1.8-cp312-cp312-macosx_11_0_arm64.whl (348.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file nilvec-0.1.8.tar.gz.

File metadata

  • Download URL: nilvec-0.1.8.tar.gz
  • Upload date:
  • Size: 563.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.8.2

File hashes

Hashes for nilvec-0.1.8.tar.gz
Algorithm Hash digest
SHA256 1008a349dc0d607559f2bf37a47e24019bf4f2f3de9e85e75875731d94b10566
MD5 9eef19b092def9c2a1617567c1ba176e
BLAKE2b-256 4906244e7e63c515a3de476ff25e04c90bf7729e1e04fcea26eda8fc649a6e11

See more details on using hashes here.

File details

Details for the file nilvec-0.1.8-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nilvec-0.1.8-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3c3775e9462129d595c72059ea4e24307cfe26098f44127ee84be9bd3dcf9e5b
MD5 a91566c663f52c169bf0aac536184ba6
BLAKE2b-256 9e2a391c756b23566a9fa29abfad1e7e7b811f646519d10eb96c255a3770468d

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