Skip to content

(in prog): add factory, adaptors for indexing strategies#3

Merged
allen-munsch merged 4 commits intomainfrom
index-behaviour
Dec 10, 2025
Merged

(in prog): add factory, adaptors for indexing strategies#3
allen-munsch merged 4 commits intomainfrom
index-behaviour

Conversation

@allen-munsch
Copy link
Owner

@allen-munsch allen-munsch commented Dec 7, 2025

  • in the style of vring, explores quantized vector slice as directory

Core Purpose:

The PR introduces a pluggable indexing strategy system that allows switching between different indexing methods, enabling:

  1. Existing centroid-based strategy (shard-based with bloom filters)
  2. New quantized ring-based strategy (grid/space partitioning)

Key Changes:

1. Strategy Pattern Architecture

  • Created Mosaic.Index.Strategy behaviour defining a common interface
  • Implemented two strategies:
    • Mosaic.Index.Strategy.Centroid - Wraps existing shard router logic
    • Mosaic.Index.Strategy.Quantized - New ring-based spatial partitioning

2. Quantized Ring Implementation

  • Quantization: Converts embeddings to grid coordinates via PathEncoder
  • Cells: Manages SQLite databases for each grid cell (Mosaic.Index.Quantized.Cell)
  • Cell Registry: Tracks and manages cell instances
  • Path Encoding: Uses multi-level binning of embedding dimensions

3. Configuration & Runtime Switching

  • Added index_strategy config option ("centroid" or "quantized")
  • Dynamic strategy selection at application startup
  • Index supervisor that starts the chosen strategy

4. Migration Tools

  • Created Mosaic.Index.Migrator for migrating between strategies
  • Provides verification and switching capabilities

5. Query Engine Integration

  • Modified Mosaic.QueryEngine to use the active strategy
  • Added index_state to maintain strategy-specific state
  • Updated grounding logic to work with both strategies

6. Refactored Existing Components

  • Mosaic.Indexer: Simplified, moved centroid calculation to separate module
  • Mosaic.ShardRouter: Implemented new router behaviour interface
  • Application Supervision: Replaced direct components with strategy supervisor

Technical Details of Quantized Strategy:

How it works:

  1. Vector Normalization: Embeddings are normalized per dimension
  2. Multi-level Binning: Each level bins dims_per_level dimensions into bins buckets
  3. Path Creation: Creates directory-like paths (e.g., "012/045/123")
  4. Cell Management: Each unique path gets a dedicated SQLite database
  5. Neighbor Expansion: Queries search within search_radius of target cells

Benefits:

  • Scalability: Distributes data across many small databases
  • Efficiency: Reduces search space via spatial partitioning
  • Parallelism: Cells can be searched independently
  • Flexibility: Tunable via bins, dims_per_level, search_radius

What's "in prog" (in progress):

  1. Experimental feature: Still being refined and tested
  2. Performance exploration: Comparing centroid vs quantized approaches
  3. Migration readiness: Building tools to switch between strategies
  4. quantized ring-based strategy: Still needs metadata to be wired up

Impact:

  • Backward Compatibility: Existing centroid strategy remains default
  • Extensibility: New strategies can be added by implementing the behaviour
  • Operational Flexibility: Can A/B test strategies or migrate based on workload
  • Research/Exploration: Enables experimenting with novel indexing approaches

Signed-off-by: allen-munsch <james.a.munsch@gmail.com>
Signed-off-by: allen-munsch <james.a.munsch@gmail.com>
Signed-off-by: allen-munsch <james.a.munsch@gmail.com>
Signed-off-by: allen-munsch <james.a.munsch@gmail.com>
@allen-munsch allen-munsch changed the title (in prog): explore quantized rings (in prog): add factory, adaptors for indexing strategies Dec 10, 2025
@allen-munsch allen-munsch marked this pull request as ready for review December 10, 2025 03:02
@allen-munsch allen-munsch merged commit 5ea5a64 into main Dec 10, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant