Luiz Henrique Salazar
Luiz Henrique Salazar

Reputation: 77

How to use different VECTOR_TABLE_NAME in Spring AI?

I currently developing a project using Spring AI framework. To work with vector database I'm using the following depency (PGVector Store):

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-pgvector-store-spring-boot-starter</artifactId>
</dependency>

What I'm struggling is how to use a different table name in my project. As default, the PgVectorStore class is set to work with a specific table:

public static final String VECTOR_TABLE_NAME = "vector_store";

Somehow, I can't find a way to update this vector table name to work properly with my database. The Spring AI version I've been working is 0.8.1.

Anyone can help with that? Thanks in advance!

Upvotes: 2

Views: 698

Answers (2)

I faced a similar challenge while working on a project using the Spring AI framework with the PgVectorStore. By default, PgVectorStore uses the vector_store table, but I needed to use a custom table name.

Here's how I managed to use a custom table within my custom schema:

CREATE EXTENSION IF NOT EXISTS vector;
CREATE EXTENSION IF NOT EXISTS hstore;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

CREATE SEQUENCE custom_schema.custom_seq
  INCREMENT 1
  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 1
  CACHE 1;

DROP TABLE IF EXISTS custom_schema.custom_table;
CREATE TABLE IF NOT EXISTS custom_schema.custom_table (
    id int8 NOT NULL UNIQUE default NEXTVAL('custom_schema.custom_seq'),
    unique_id UUID NOT null UNIQUE,
    content text,
    metadata json,
    embedding vector(1536),
    created_on TIMESTAMPTZ,
    modified_on TIMESTAMPTZ,
    CONSTRAINT custom_pkey PRIMARY KEY (id)
);

Using Hibernate for Custom Entity

To work with this custom table using Hibernate, you can use the hibernate-vector dependency to map your custom entity. Here’s how you can configure it:

<dependency>
    <groupId>org.hibernate.orm</groupId>
    <artifactId>hibernate-vector</artifactId>
    <version>6.4.0.Final</version>
</dependency>

This setup allows you to use your custom table with PgVectorStore and Hibernate. For more details on using and configuring PgVectorStore, you can refer to the https://github.com/pgvector/pgvector-java.

Feel free to reach out if you have any questions or need further assistance!

Upvotes: 0

rdiachenko
rdiachenko

Reputation: 763

It's not possible as for 0.8.1 unless you're willing to implement VectorStore with a custom table name. If you check the current PgVectorStore implementation, you'll notice that VECTOR_TABLE_NAME is hardcoded and used throughout query operations, lacking the option to override it through a property.

I haven't encountered any relevant issues for this use case either, so please feel free to contribute or submit one through the Spring AI issue tracker.

Upvotes: 1

Related Questions