Hibernate / Hibernate 7 Basics Interview Questions
How does Hibernate 7 support vector data types for AI/ML applications?
Hibernate 7 (especially 7.2+) adds native support for vector data types used in AI embeddings, enabling semantic search alongside relational data.
import org.hibernate.annotations.Array; import org.hibernate.type.SqlTypes; @Entity public class Document { @Id @GeneratedValue private Long id; private String content; // Float32 vector (e.g. OpenAI text-embedding-3 embeddings): @JdbcTypeCode(SqlTypes.VECTOR) @Array(length=1536) // number of dimensions private float[] embedding; // Binary vector (Hibernate 7.2+): @JdbcTypeCode(SqlTypes.VECTOR_BINARY) @Array(length=24) private byte[] binaryVector; // Half-precision float16 (Hibernate 7.2+): @JdbcTypeCode(SqlTypes.VECTOR_FLOAT16) @Array(length=1536) private float[] halfPrecisionEmbedding; } // Vector similarity search (pgvector required): List<Object[]> similar = session .createNativeQuery( "SELECT d.id, d.content, d.embedding <=> :queryVec AS distance " + "FROM document d ORDER BY distance ASC LIMIT 10", Object[].class) .setParameter("queryVec", queryEmbedding) .getResultList(); // HQL distance functions (Hibernate 7.1+): List<Document> results = session .createQuery("FROM Document d ORDER BY cosine_distance(d.embedding, :vec) ASC", Document.class) .setParameter("vec", queryEmbedding).setMaxResults(10).getResultList();
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
