Nestor Milyaev
Nestor Milyaev

Reputation: 6595

Java with JPA and vectorscale: SQL Error [42704]: ERROR: type "vectorscale" does not exist

I'm building a prototype ML system using Postgres-based extension vectorscale. It goes as follows:

I use a docker image timescale/timescaledb-ha:pg17

  1. I've created a table for embeddings:

    CREATE TABLE IF NOT EXISTS products.products_embedding ( embedding_id int8 NOT NULL PRIMARY KEY, "text" varchar(255), embedding vector(3072), metadata json );

  2. I've installed a vectorscale extension:

    CREATE EXTENSION IF NOT EXISTS vectorscale CASCADE;

That all worked well and I can see the extension created:

SELECT * 
FROM pg_extension; - that lists my `vectorscale` and `vector` extensions

Now, when I try to query the db, using Java JPA repository, as in:

@Query(nativeQuery = true, value = "SELECT * FROM products.products_embedding ORDER BY embedding <=> cast('[:embedding]' as vectorscale) LIMIT :limit")
List<ProductsEmbedding> findByEmbedding(List<Float> embedding, int limit);

, that blows in my face with the following error:

SQL Error [42704]: ERROR: type "vectorscale" does not exist

I get the same result if I plain query in Postgres:

SELECT *
FROM products.argos_products_embedding
ORDER BY embedding <=> cast ('[0.002165521029382944,..(truncated for brievety)..]' as vectorscale)
LIMIT 10;

Why the extension is not found?

BTW, it works if I try

SELECT *
FROM products.argos_products_embedding
ORDER BY embedding <=> cast ('[0.002165521029382944,..(truncated for brievety)..]' as vector)
LIMIT 10;

I have had the 'vectorextension installed earlier on on the same container, and I believe vectorscale is built on top ofvector`, so that works in Postgres.

It still doesn't work in Java though:

@Query(nativeQuery = true, value = "SELECT * FROM products.products_embedding ORDER BY embedding <=> cast('[:embedding]' as vector) LIMIT :limit")
List<ProductsEmbedding> findByEmbedding(List<Float> embedding, int limit);

Still breaks complaining that ERROR: type \"vector\" does not exist\n Position: 95

Any idea why the extensions are only found half the time, please?

Upvotes: 0

Views: 33

Answers (0)

Related Questions