Skip to content

Fix: ObjectBoxVectorIndex hardcoded 768 dimensions breaks TFLite/ONNX #41

@iberi22

Description

@iberi22

Problem

ObjectBoxVectorIndex in lib/src/vector_index_objectbox.dart has hardcoded dimension of 768:

@HnswIndex(dimensions: 768, distanceType: VectorDistanceType.cosine)
@Property(type: PropertyType.floatVector)
List<double>? vector;

But TFLite embedding models (e.g., universal-sentence-encoder-lite) produce 384-dimensional vectors. ONNX models like all-MiniLM-L6-v2 also produce 384 dimensions.

This means switching from Gemini (768-dim) to TFLite/ONNX will crash at runtime because ObjectBox expects 768-dim vectors.

Root Cause

The HNSW index was designed only for Gemini's text-embedding-004 (768-dim). When using on-device models with different dimensions, the index fails.

Proposed Solution

  1. Make dimension configurable via entity factory:

    • Create separate ObxVectorDoc entities per dimension
    • Or use a single entity with dynamic dimension validation
  2. Update VectorIndex interface to include dimension property

  3. Update memory_graph.dart to use backend's actual dimension during initialization

Impact

Fixes compatibility with:

  • TFLite universal-sentence-encoder-lite (384-dim)
  • ONNX all-MiniLM-L6-v2 (384-dim)
  • Any future embedding model with different dimensions

Files Affected

  • lib/src/vector_index_objectbox.dart - entity definition
  • lib/src/memory_graph.dart - uses hardcoded dimension in initialize()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingjules

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions