Skip to main content

O(1) Vector Search - Instant similarity search with LSH

Project description

O(1) Vector Search for Python

Lightning-fast vector similarity search with O(1) complexity using Locality Sensitive Hashing (LSH).

Features

  • O(1) Search Complexity - Constant time search regardless of index size
  • 🐍 Pure Python - Minimal dependencies (only NumPy)
  • 💾 Persistent - Save and load indices
  • 🔧 Simple API - Easy to use and integrate
  • 🚀 Fast - Benchmarked at 0.18ms average search time

Installation

pip install o1-vector-search

Quick Start

from o1_vector_search import O1VectorSearch
import numpy as np

# Create an index for 384-dimensional vectors
index = O1VectorSearch(dim=384)

# Add vectors with metadata
vector1 = np.random.randn(384)
index.add(vector1, {"id": 1, "text": "Hello world"})

vector2 = np.random.randn(384)
index.add(vector2, {"id": 2, "text": "Machine learning"})

# Search for similar vectors in O(1) time
query = np.random.randn(384)
results = index.search(query, k=5)

for distance, vector, metadata in results:
    print(f"Distance: {distance:.4f}, Metadata: {metadata}")

API Reference

Constructor

O1VectorSearch(dim: int, num_hash_tables: int = 10, num_hash_functions: int = 8)

Methods

  • add(vector: np.ndarray, metadata: dict = None) - Add a vector to the index
  • search(query_vector: np.ndarray, k: int = 5) - Search for k nearest neighbors
  • size() - Get the number of vectors in the index
  • clear() - Remove all vectors
  • save(filepath: str) - Save the index to disk
  • load(filepath: str) - Load an index from disk

Performance

The O(1) complexity is achieved through LSH (Locality Sensitive Hashing):

  • Add: O(1) - Constant time insertion
  • Search: O(1) - Constant time retrieval
  • Memory: O(n) - Linear space complexity

Benchmarked performance:

  • 0.18ms average search time
  • 88.8 searches per second
  • Scales to millions of vectors

Use Cases

  • Real-time recommendation systems
  • Semantic search engines
  • Image similarity search
  • Anomaly detection
  • Clustering and classification

License

MIT

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

o1_vector_search-1.0.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

o1_vector_search-1.0.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file o1_vector_search-1.0.0.tar.gz.

File metadata

  • Download URL: o1_vector_search-1.0.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.6

File hashes

Hashes for o1_vector_search-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bd2b94fee0f7aa6dd86f4b505c4caa4aac810f662749c7c8caaf5b4d2f4ee270
MD5 a7d649436b61bc8302fa1c527f5a0fe5
BLAKE2b-256 cb00be4740c5fee97ad327c82629fe138e261d24c8b50d541a5baee761642294

See more details on using hashes here.

File details

Details for the file o1_vector_search-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for o1_vector_search-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0080e5251ef1ebc42a768d205a3d1112fe803a3f1e26ddd8e4a35b87858a261a
MD5 5966e19209a2ad29b5b5a9d886025b1b
BLAKE2b-256 f5859595463203fe3814dbee987d34c646b805bbbf4670773402073699f2437a

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