zeusdb-vector-database 0.1.1__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zeusdb-vector-database
3
- Version: 0.1.1
3
+ Version: 0.2.0
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Requires-Dist: numpy>=2.2.6,<3.0.0
@@ -11,7 +11,7 @@ License-File: LICENSE
11
11
  License-File: NOTICE
12
12
  Summary: Blazing-fast vector DB with real-time similarity search and metadata filtering.
13
13
  Author-email: ZeusDB <contact@zeusdb.com>
14
- License: Apache-2.0
14
+ License-Expression: Apache-2.0
15
15
  Requires-Python: >=3.10
16
16
  Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
17
17
  Project-URL: Repository, https://github.com/zeusdb/zeusdb-vector-database
@@ -56,22 +56,30 @@ ZeusDB leverages the HNSW (Hierarchical Navigable Small World) algorithm for spe
56
56
 
57
57
  ## ⭐ Features
58
58
 
59
- 🔍 Approximate Nearest Neighbor (ANN) search with HNSW
59
+ 🐍 User-friendly Python API for adding vectors and running similarity searches
60
+
61
+ 🔥 High-performance Rust backend optimized for speed and concurrency
62
+
63
+ 🔍 Approximate Nearest Neighbor (ANN) search using HNSW for fast, accurate results
64
+
65
+ 📦 Product Quantization (PQ) for compact storage, faster distance computations, and scalability for Big Data
66
+
67
+ 📥 Flexible input formats, including native Python types and zero-copy NumPy arrays
68
+
69
+ 🗂️ Metadata-aware filtering for precise and contextual querying
60
70
 
61
- 📋 Supports multiple distance metrics: `cosine`, `L1`, `L2`
62
71
 
63
- 🔥 High-performance Rust backend
64
72
 
65
- 📥 Supports multiple input formats using a single, easy-to-use Python method
66
73
 
67
- 🗂️ Metadata-aware filtering at query time
74
+ <!--
75
+ 📋 Supports multiple distance metrics: `cosine`, `L1`, `L2`
68
76
 
69
- 🐍 Simple and intuitive Python API
77
+ 📥 Supports multiple input formats using a single, easy-to-use Python method
70
78
 
71
79
  ⚡ Smart multi-threaded inserts that automatically speed up large batch uploads
72
80
 
73
81
  🚀 Fast, concurrent searches so you can run multiple queries at the same time
74
-
82
+ -->
75
83
 
76
84
  <br/>
77
85
 
@@ -207,16 +215,19 @@ index = vdb.create(
207
215
  )
208
216
  ```
209
217
 
210
- #### 📘 `create()` Parameters
218
+ <br/>
219
+
220
+ #### 📘 Parameters - `create()`
211
221
 
212
222
  | Parameter | Type | Default | Description |
213
223
  |------------------|--------|-----------|-----------------------------------------------------------------------------|
214
224
  | `index_type` | `str` | `"hnsw"` | The type of vector index to create. Currently supports `"hnsw"`. Future options include `"ivf"`, `"flat"`, etc. Case-insensitive. |
215
225
  | `dim` | `int` | `1536` | Dimensionality of the vectors to be indexed. Each vector must have this length. The default dim=1536 is chosen to match the output dimensionality of OpenAI’s text-embedding-ada-002 model. |
216
- | `space` | `str` | `"cosine"`| Distance metric used for similarity search. Options include `"cosine"`. Additional metrics such as `"l2"`, and `"dot"` will be added in future versions. |
226
+ | `space` | `str` | `"cosine"`| Distance metric used for similarity search. Options include `"cosine"`, `"L1"` and `"L2"`.|
217
227
  | `m` | `int` | `16` | Number of bi-directional connections created for each new node. Higher `m` improves recall but increases index size and build time. |
218
228
  | `ef_construction`| `int` | `200` | Size of the dynamic list used during index construction. Larger values increase indexing time and memory, but improve quality. |
219
229
  | `expected_size` | `int` | `10000` | Estimated number of elements to be inserted. Used for preallocating internal data structures. Not a hard limit. |
230
+ | `quantization_config` | `dict` | `None` | Product Quantization configuration for memory-efficient vector compression. |
220
231
 
221
232
  <br/>
222
233
 
@@ -296,7 +307,9 @@ print(add_result) # AddResult(inserted=2, errors=0, shape=(2, 2))
296
307
 
297
308
  Each format is parsed and validated automatically. Invalid records are skipped, and detailed error messages are returned to help with debugging and retry workflows.
298
309
 
299
- #### 📘 `add()` Parameters
310
+ <br/>
311
+
312
+ #### 📘 Parameters - `add()`
300
313
 
301
314
  The `add()` method inserts one or more vectors into the index. Multiple data formats are supported to accommodate different workflows, including native Python types and NumPy arrays.
302
315
 
@@ -319,10 +332,9 @@ Helpful for validation, logging, and debugging.
319
332
 
320
333
  Query the index using a new vector and retrieve the top-k nearest neighbors. You can also filter by metadata or return the original stored vectors.
321
334
 
322
- #### 🔍 Basic Search (Returning Top 2 most similar)
335
+ #### 🔍 Search Example 1 - Basic (Returning Top 2 most similar)
323
336
 
324
337
  ```python
325
- print("\n--- Query returning two most similar results ---")
326
338
  results = index.search(vector=query_vector, top_k=2)
327
339
  print(results)
328
340
  ```
@@ -335,12 +347,12 @@ print(results)
335
347
  ]
336
348
  ```
337
349
 
338
- #### 🔍 Query with metadata filter
350
+ #### 🔍 Search Example 2 - Query with metadata filter
339
351
 
340
352
  This filters on the given metadata after conducting the similarity search.
341
353
 
342
354
  ```python
343
- print("\n--- Querying with filter: author = 'Alice' ---")
355
+ query_vector = [0.1, 0.2, 0.3, 0.1, 0.4, 0.2, 0.6, 0.7]
344
356
  results = index.search(vector=query_vector, filter={"author": "Alice"}, top_k=5)
345
357
  print(results)
346
358
  ```
@@ -354,12 +366,11 @@ print(results)
354
366
  ]
355
367
  ```
356
368
 
357
- #### 🔍 Include Vector in Similarity Results
369
+ #### 🔍 Search Example 3 - Search results include vectors
358
370
 
359
371
  You can optionally return the stored embedding vectors alongside metadata and similarity scores by setting `return_vector=True`. This is useful when you need access to the raw vectors for downstream tasks such as re-ranking, inspection, or hybrid scoring.
360
372
 
361
373
  ```python
362
- print("\n--- Querying with filter and returning embedding vectors ---")
363
374
  results = index.search(vector=query_vector, filter={"split": "test"}, top_k=2, return_vector=True)
364
375
  print(results)
365
376
  ```
@@ -372,13 +383,66 @@ print(results)
372
383
  ]
373
384
  ```
374
385
 
375
- #### 📘 `query()` Parameters
386
+ #### 🔍 Search Example 4 - Batch Search with a list of vectors
387
+
388
+ Perform a similarity search on multiple query vectors simultaneously, returning results for each query.
376
389
 
377
- The `query()` method retrieves the top-k most similar vectors from the index given an input query vector. Results include the vector ID, similarity score, metadata, and (optionally) the stored vector itself.
390
+ ```python
391
+ query_vector =
392
+ [
393
+ [0.1, 0.2, 0.3],
394
+ [0.4, 0.5, 0.6]
395
+ ]
396
+ results = index.search(vector=query_vector, top_k=3)
397
+ print(results)
398
+ ```
399
+
400
+ *Output*
401
+ ```
402
+ [
403
+ [{'id': 'a', 'score': 4.999447078546382e-09, 'metadata': {'category': 'A'}}, {'id': 'b', 'score': 0.02536815218627453, 'metadata': {'category': 'B'}}, {'id': 'c', 'score': 0.04058804363012314, 'metadata': {'category': 'A'}}],
404
+ [{'id': 'b', 'score': 4.591760305316939e-09, 'metadata': {'category': 'B'}}, {'id': 'c', 'score': 0.0018091063247993588, 'metadata': {'category': 'A'}}, {'id': 'a', 'score': 0.025368161499500275, 'metadata': {'category': 'A'}}]
405
+ ]
406
+ ```
407
+
408
+ #### 🔍 Search Example 5 - Batch Search with NumPy Array
409
+
410
+ Perform a similarity search on multiple query vectors from a NumPy array, returning results for each query.
411
+
412
+ ```python
413
+ query_vector = np.array(
414
+ [
415
+ [0.1, 0.2, 0.3],
416
+ [0.7, 0.8, 0.9]
417
+ ], dtype=np.float32)
418
+
419
+ results = index.search(vector=query_vector, top_k=3)
420
+ print(results)
421
+ ```
422
+
423
+ #### 🔍 Search Example 6 - Batch Search with metadata filter
424
+
425
+ Performs similarity search on multiple query vectors with metadata filtering, returning filtered results for each query.
426
+
427
+ ```python
428
+ results = index.search(
429
+ [[0.1, 0.2, 0.3], [0.7, 0.8, 0.9]],
430
+ filter={"category": "A"},
431
+ top_k=3
432
+ )
433
+ print(results)
434
+ ```
435
+
436
+
437
+ <br/>
438
+
439
+ #### 📘 Parameters - `search()`
440
+
441
+ The `search()` method retrieves the top-k most similar vectors from the index given an input query vector. Results include the vector ID, similarity score, metadata, and (optionally) the stored vector itself.
378
442
 
379
443
  | Parameter | Type | Default | Description |
380
444
  |------------------|----------------------------------|-----------|-----------------------------------------------------------------------------|
381
- | `vector` | `List[float]` or `np.ndarray` | *required* | The query vector to compare against the index. Must match the index dimension. |
445
+ | `vector` | `List[float]` or `List[List[float]]` or `np.ndarray` | *required* | The query vector (single: `List[float]`) or batch of query vectors (`List[List[float]]` or 2D `np.ndarray`) to compare against the index. Must match the index dimension. |
382
446
  | `filter` | `Dict[str, str] \| None` | `None` | Optional metadata filter. Only vectors with matching key-value metadata pairs will be considered in the search. |
383
447
  | `top_k` | `int` | `10` | Number of nearest neighbors to return. |
384
448
  | `ef_search` | `int \| None` | `max(2 × top_k, 100)` | Search complexity parameter. Higher values improve accuracy at the cost of speed. |
@@ -500,6 +564,156 @@ print(partial)
500
564
 
501
565
  ⚠️ `get_records()` only returns results for IDs that exist in the index. Missing IDs are silently skipped.
502
566
 
567
+ <br />
568
+
569
+
570
+ ## 🗜️ Product Quantization
571
+
572
+ Product Quantization (PQ) is a vector compression technique that significantly reduces memory usage while preserving high search accuracy. Commonly used in HNSW-based vector databases, PQ works by dividing each vector into subvectors and quantizing them independently. This enables compression ratios of 4× to 256×, making it ideal for large-scale, high-dimensional datasets.
573
+
574
+ ZeusDB Vector Database’s PQ implementation features:
575
+
576
+ ✅ Intelligent Training – PQ model trains automatically at defined thresholds
577
+
578
+ ✅ Efficient Memory Use – Store 4× to 256× more vectors in the same RAM footprint
579
+
580
+ ✅ Fast Approximate Search – Uses Asymmetric Distance Computation (ADC) for high-speed search computation
581
+
582
+ ✅ Seamless Operation – Index automatically switches from raw to quantized storage modes
583
+
584
+ <br />
585
+
586
+ ### 📘 Quantization Configuration Parameters
587
+
588
+ To enable PQ, pass a `quantization_config` dictionary to the `.create()` index method:
589
+
590
+ | Parameter | Type | Description | Valid Range | Default |
591
+ |-----------|------|-------------|-------------|---------|
592
+ | `type` | `str` | Quantization algorithm type | `"pq"` | *required* |
593
+ | `subvectors` | `int` | Number of vector subspaces (must divide dimension evenly) | 1 to dimension | `8` |
594
+ | `bits` | `int` | Bits per quantized code (controls centroids per subvector) | 1-8 | `8` |
595
+ | `training_size` | `int` | Minimum vectors needed for stable k-means clustering | ≥ 1000 | 1000 |
596
+ | `max_training_vectors` | `int` | Maximum vectors used during training (optional limit) | ≥ training_size | `None` |
597
+
598
+
599
+ <br/>
600
+
601
+
602
+ ### 🔧 Usage Example
603
+
604
+ ```python
605
+ from zeusdb_vector_database import VectorDatabase
606
+ import numpy as np
607
+
608
+ # Create index with product quantization
609
+ vdb = VectorDatabase()
610
+
611
+ # Configure quantization for memory efficiency
612
+ quantization_config = {
613
+ 'type': 'pq', # `pq` for Product Quantization
614
+ 'subvectors': 8, # Divide 1536-dim vectors into 8 subvectors of 192 dims each
615
+ 'bits': 8, # 256 centroids per subvector (2^8)
616
+ 'training_size': 10000, # Train when 10k vectors are collected
617
+ 'max_training_vectors': 50000 # Use max 50k vectors for training
618
+ }
619
+
620
+ # Create index with quantization
621
+ # This will automatically handle training when enough vectors are added
622
+ index = vdb.create(
623
+ index_type="hnsw",
624
+ dim=1536, # OpenAI `text-embedding-3-small` dimension
625
+ quantization_config=quantization_config # Add the compression configuration
626
+ )
627
+
628
+ # Add vectors - training triggers automatically at threshold
629
+ documents = [
630
+ {
631
+ "id": f"doc_{i}",
632
+ "values": np.random.rand(1536).astype(float).tolist(),
633
+ "metadata": {"category": "tech", "year": 2026}
634
+ }
635
+ for i in range(15000)
636
+ ]
637
+
638
+ # Training will trigger automatically when 10k vectors are added
639
+ result = index.add(documents)
640
+ print(f"Added {result.total_inserted} vectors")
641
+
642
+ # Check quantization status
643
+ print(f"Training progress: {index.get_training_progress():.1f}%")
644
+ print(f"Storage mode: {index.get_storage_mode()}")
645
+ print(f"Is quantized: {index.is_quantized()}")
646
+
647
+ # Get compression statistics
648
+ quant_info = index.get_quantization_info()
649
+ if quant_info:
650
+ print(f"Compression ratio: {quant_info['compression_ratio']:.1f}x")
651
+ print(f"Memory usage: {quant_info['memory_mb']:.1f} MB")
652
+
653
+ # Search works seamlessly with quantized storage
654
+ query_vector = np.random.rand(1536).astype(float).tolist()
655
+ results = index.search(vector=query_vector, top_k=3)
656
+
657
+ # Simply print raw results
658
+ print(results)
659
+ ```
660
+
661
+ Results
662
+ ```python
663
+ [
664
+ {'id': 'doc_9719', 'score': 0.5133496522903442, 'metadata': {'category': 'tech', 'year': 2026}},
665
+ {'id': 'doc_8148', 'score': 0.5139288306236267, 'metadata': {'category': 'tech', 'year': 2026}},
666
+ {'id': 'doc_7822', 'score': 0.5151920914649963, 'metadata': {'category': 'tech', 'year': 2026}},
667
+ ]
668
+ ```
669
+
670
+ <br />
671
+
672
+ ### ⚙️ Configuration Guidelines
673
+
674
+ For Balanced Memory & Accuracy (Recommended to start with)
675
+ ```python
676
+ quantization_config = {
677
+ 'type': 'pq',
678
+ 'subvectors': 8, # Balanced: moderate compression, good accuracy
679
+ 'bits': 8, # 256 centroids per subvector (high precision)
680
+ 'training_size': 10000 # Or higher for large datasets
681
+ }
682
+ # Achieves ~16x–32x compression with strong recall for most applications
683
+ ```
684
+
685
+
686
+ For Memory Optimization:
687
+ ```python
688
+ quantization_config = {
689
+ 'type': 'pq',
690
+ 'subvectors': 16, # More subvectors = better compression
691
+ 'bits': 6, # Fewer bits = less memory per centroid
692
+ 'training_size': 20000
693
+ }
694
+ # Achieves ~32x compression ratio
695
+ ```
696
+
697
+ For Accuracy Optimization:
698
+ ```python
699
+ quantization_config = {
700
+ 'type': 'pq',
701
+ 'subvectors': 4, # Fewer subvectors = better accuracy
702
+ 'bits': 8, # More bits = more precise quantization
703
+ 'training_size': 50000 # More training data = better centroids
704
+ }
705
+ # Achieves ~4x compression ratio with minimal accuracy loss
706
+ ```
707
+
708
+ ### 📊 Performance Characteristics
709
+
710
+ - Training: Occurs once when threshold is reached (typically 1-5 minutes for 50k vectors)
711
+ - Memory Reduction: 4x-256x depending on configuration
712
+ - Search Speed: Comparable or faster than raw vectors due to ADC optimization
713
+ - Accuracy Impact: Typically 1-5% recall reduction with proper tuning
714
+
715
+ Quantization is ideal for production deployments with large vector datasets (100k+ vectors) where memory efficiency is critical.
716
+
503
717
 
504
718
  <br/>
505
719