Vector embeddings (multi-dimensional vectors) are a central building block for AI applications. And accordingly, the ability to store vectors to add long-term memory to your AI applications (e.g. via vector databases) is gaining importance. Sounds fancy, but for the basic use cases, this simply boils down to “arrays of floats” for developers. And this is exactly what ObjectBox database now supports natively. If you want to use vectors on the edge, e.g. in a mobile app or on an embedded device, when offline, independent from an Internet connection, removing the unknown latency, try it…
See the release notes for all new features this release brings.
Code Examples
Let’s start with a simple example: let’s assume some shapes that use a palette of RGB colors. An entity for this might look like this:
1 2 3 4 5 6 7 8 9 | @Entity public class Shape { @Id public long id; // An array of RGB color values that are used by this shape. public int[ ] palette; } |
We can now create a query to find all shapes that use a certain color:
1 2 3 4 5 6 7 | // Find all shapes that use red in their palette try (Query<Shape> query = store.boxFor(Shape.class) .query(Shape_.palette.equal(0xFF0000 /* red */)) .build()) { query.findIds(); } |
Another typical use case is the embedding of certain types of data, like text, audio or images, as vector coordinates. To store such a vector embedding, in the following example we store the floating point coordinates that were computed by a machine learning model for an image together with a reference to the actual image:
1 2 3 4 5 6 7 8 9 10 11 12 13 | @Entity public class ImageEmbedding { @Id public long id; // Link to the actual image, e.g. on Cloud storage public String url; // The coordinates computed for this image (vector embedding) public float[] coordinates; } |
Ready to go?
To update to this release, change the version of objectbox-gradle-plugin to 3.6.0.
To add ObjectBox database to your JVM or Android project read our Getting Started guide.
As always, we look forward to your feedback on GitHub or via our anonymous feedback form and hope you have a great time building apps with ObjectBox! ❤️