Skip to content

Fix ObjectBox hardcoded 768 dimensions#46

Merged
iberi22 merged 1 commit into
mainfrom
fix/objectbox-dynamic-dimensions-16529490341314575802
Apr 16, 2026
Merged

Fix ObjectBox hardcoded 768 dimensions#46
iberi22 merged 1 commit into
mainfrom
fix/objectbox-dynamic-dimensions-16529490341314575802

Conversation

@iberi22
Copy link
Copy Markdown
Owner

@iberi22 iberi22 commented Apr 16, 2026

The ObjectBox vector index previously had a hardcoded dimension of 768, which caused crashes when using on-device models like MiniLM-L6-v2 (384 dimensions). This PR makes the dimension configurable.

Key changes:

  • VectorIndex: Added int get dimension.
  • ObjectBoxVectorIndex: Now an abstract class with a factory. It uses ObxVectorDoc for 768-dim and ObxVectorDoc384 for 384-dim.
  • MemoryGraph: Passes the adapter's dimension to the vector index during initialization.
  • Added test/vector_dimension_test.dart to verify the fix.

Fixes #41


PR created automatically by Jules for task 16529490341314575802 started by @iberi22

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for 384-dimensional vector embeddings alongside existing 768-dimensional support.
    • Vector index initialization now accepts a configurable dimension parameter.
    • Automatic dimension synchronization between embeddings adapter and vector storage.
  • Tests

    • Added tests validating vector dimension compatibility across the system.
  • Chores

    • Removed generated analysis and configuration files.

- Updated `VectorIndex` interface to include `dimension` property.
- Refactored `ObjectBoxVectorIndex` to support 384 and 768 dimensions using a factory pattern and dimension-specific entities (`ObxVectorDoc` and `ObxVectorDoc384`).
- Updated `MemoryGraph` to automatically use the correct dimension from the `EmbeddingsAdapter`.
- Regenerated ObjectBox code to include the new entity.
- Added comprehensive tests for multiple vector dimensions.
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fc15eb4d-2ab8-4b03-bd43-28d67968b3d1

📥 Commits

Reviewing files that changed from the base of the PR and between 087a65b and 71a71ef.

📒 Files selected for processing (9)
  • .flutter-plugins-dependencies
  • analyze_final.txt
  • analyze_output.txt
  • lib/objectbox-model.json
  • lib/objectbox.g.dart
  • lib/src/memory_graph.dart
  • lib/src/vector_index.dart
  • lib/src/vector_index_objectbox.dart
  • test/vector_dimension_test.dart

📝 Walkthrough

Walkthrough

The PR adds configurable vector dimensionality support to ObjectBoxVectorIndex, addressing hardcoded 768-dimension limitations. It introduces a new ObxVectorDoc384 entity, adds a dimension property to the VectorIndex interface, refactors ObjectBoxVectorIndex into an abstract factory pattern supporting 384 and 768 dimensions, and updates MemoryGraph to propagate the embeddings adapter's dimension during initialization. New test coverage validates dimension compatibility.

Changes

Cohort / File(s) Summary
Cleanup
.flutter-plugins-dependencies, analyze_final.txt, analyze_output.txt
Removed generated/temporary analysis artifacts and plugin dependency metadata.
Vector Index Interface
lib/src/vector_index.dart
Added abstract getter int get dimension; to extend the VectorIndex interface contract.
ObjectBox Model & Generated Code
lib/objectbox-model.json, lib/objectbox.g.dart
Added new entity ObxVectorDoc384 with 384-dimensional HNSW vector index; updated model bookkeeping identifiers (lastEntityId, lastIndexId) and generated serialization/deserialization logic.
Vector Index ObjectBox Implementation
lib/src/vector_index_objectbox.dart
Introduced ObxVectorEntity interface abstracting common vector entity fields; refactored concrete ObjectBoxVectorIndex to abstract factory pattern with open(...) and constructor accepting dimension parameter (default 768); added dimension-specific implementations (_ObjectBoxVectorIndex768, _ObjectBoxVectorIndex384); updated search and add-document operations to validate vector dimensions against implementation and use generic query properties.
Memory Graph
lib/src/memory_graph.dart
Updated ObjectBoxVectorIndex initialization to pass embeddingsAdapter.dimension instead of relying on hardcoded default.
Test Coverage
test/vector_dimension_test.dart
Added comprehensive test suite with MockEmbeddingsAdapter validating 768-dim and 384-dim initialization, semantic search functionality across dimensions, and unsupported dimension error handling.

Sequence Diagram(s)

sequenceDiagram
    participant MemoryGraph
    participant EmbeddingsAdapter
    participant ObjectBoxVectorIndex
    participant VectorIndexImpl as Dimension-Specific Implementation
    participant ObjectBoxStore

    MemoryGraph->>EmbeddingsAdapter: query dimension property
    EmbeddingsAdapter-->>MemoryGraph: return dimension (384 or 768)
    MemoryGraph->>ObjectBoxVectorIndex: factory call with dimension
    ObjectBoxVectorIndex->>ObjectBoxVectorIndex: dispatch to correct implementation
    alt dimension == 768
        ObjectBoxVectorIndex->>VectorIndexImpl: create _ObjectBoxVectorIndex768
    else dimension == 384
        ObjectBoxVectorIndex->>VectorIndexImpl: create _ObjectBoxVectorIndex384
    else unsupported
        ObjectBoxVectorIndex-->>ObjectBoxVectorIndex: throw ArgumentError
    end
    VectorIndexImpl->>ObjectBoxStore: initialize with dimension-specific entity
    VectorIndexImpl-->>MemoryGraph: return configured index
    MemoryGraph->>VectorIndexImpl: semantic search with embeddings
    VectorIndexImpl->>VectorIndexImpl: validate embedding length vs dimension
    VectorIndexImpl->>ObjectBoxStore: query with dimension-specific properties
    ObjectBoxStore-->>VectorIndexImpl: return results
    VectorIndexImpl-->>MemoryGraph: return search results
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • Fix: Prepare package for publishing #4: Both PRs modify the same core vector/embedding surface (changes to memory_graph and the embedding/vector dimension interfaces), creating direct code-level dependencies.
  • release: 0.2.0 – cleanup, roadmap, publish prep #12: The main PR and this PR touch the same core vector-indexing implementation files (lib/src/vector_index.dart, lib/src/vector_index_objectbox.dart, lib/src/memory_graph.dart, and ObjectBox model files), making them directly related at the code level.

Poem

🐰 Dimensions dance, no longer bound,
384, 768 vectors found,
Factory magic makes it clean,
The best adapter flow I've seen!
Different embeddings, all embrace,
In ObjectBox's flexible space.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/objectbox-dynamic-dimensions-16529490341314575802

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for multiple vector dimensions (specifically 384 and 768) within the ObjectBox vector index implementation. It refactors the ObjectBoxVectorIndex into a factory-based architecture with a base class and specific entity implementations for different dimensions, ensuring type safety and correct HNSW configuration. The changes also include updates to the MemoryGraph to automatically select the appropriate index based on the embedding adapter's dimensions and a new test suite to verify compatibility. Review feedback highlights opportunities to improve performance by removing redundant toList() calls on Float32List during document insertion and search operations.

vector: vec.toList(growable: false),
);
_box.query(_docKeyProperty.equals(key)).build().findFirst();
final entity = _createEntity(key, content, vec.toList(growable: false));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Calling toList() on a Float32List creates a new List<double> and copies all elements. Since Float32List already implements List<double>, this conversion is unnecessary and impacts performance during document insertion.

Suggested change
final entity = _createEntity(key, content, vec.toList(growable: false));
final entity = _createEntity(key, content, vec);

.query(ObxVectorDoc_.vector
.nearestNeighborsF32(q.toList(growable: false), topK))
.query(_vectorProperty.nearestNeighborsF32(
q.toList(growable: false), topK))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Redundant toList() call. q is a Float32List, which is already a List<double>. Removing this avoids an unnecessary allocation and copy during every search operation.

Suggested change
q.toList(growable: false), topK))
.query(_vectorProperty.nearestNeighborsF32(q, topK))

@iberi22 iberi22 marked this pull request as ready for review April 16, 2026 23:40
@iberi22 iberi22 merged commit f5b5124 into main Apr 16, 2026
4 of 7 checks passed
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.

Fix: ObjectBoxVectorIndex hardcoded 768 dimensions breaks TFLite/ONNX

1 participant