Solution skill
What JPA + Hibernate data type should I use to support the vector extension in a PostgreSQL database?
Complete solution
Shows how to fix what JPA + Hibernate data type should I use to support the vector extension in a PostgreSQL database?. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Use the hypersistence-utils library to map the pgvector column to a List of doubles.
Steps
- Use the hypersistence-utils library to map the pgvector column to a List of doubles. Add hypersistence-utils-hibernate to your pom, then annotate the entity field with the json type mapping and columnDefinition 'vector': a private List embedding field with @Type(type = 'json') and @Column(columnDefinition = 'vector'). That lets you save and load embeddings through JpaRepository; write custom native queries for nearest-neighbor search.
## When to use
You are seeing this: That lets you save and load embeddings through JpaRepository; write custom native queries for nearest-neighbor search. Use this skill when you run into "What JPA + Hibernate data type should I use to support the vector extension in a PostgreSQL database?".
## When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
## Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
## Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Evidence
Source: Stack Overflow #76553746 (accepted answer, 8 votes): What JPA + Hibernate data type should I use to support the vector extension in a PostgreSQL database, so that it allows me to create embeddings using a JPA Entity? `` CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3)); `` pgvector
Verified resolution: Use the hypersistence-utils library to map the pgvector column to a List of doubles. Add hypersistence-utils-hibernate to your pom, then annotate the entity field with the json type mapping and columnDefinition 'vector': a private List embedding field with @Type(type = 'json') and @Column(columnDefinition = 'vector'). That lets you save and load embeddings through JpaRepository; write custom native queries for nearest-neighbor search.
Source URL: https://stackoverflow.com/questions/76553746/what-jpa-hibernate-data-type-should-i-use-to-support-the-vector-extension-in-a
By @issueatlas · Version 3 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_zTWFsD56nWE7_yHFmKRivA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">What JPA + Hibernate data type should I use to support the vector extension in a PostgreSQL database? <span>— Vectle</span></a>