PGVector schema initialization doesn't work when datasource auto-commit is disabled.

Open Beginner friendly
#2,475 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
62/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
java, postgresql, spring-boot
Domain
backend, database

Research direction

Start in vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorStore.java at the jdbcTemplate.execute call around line 421. Reproduce with Hikari auto-commit disabled and verify that initialization commits successfully; done means the PGVector schema and required extensions remain present after initialization.

Written by the indexing model from the issue text.

Description

status: waiting-for-triage

Bug description
If auto commit is disabled, jdbcTemplate.execute doesn't get committed and is rolled back:
https://github.com/spring-projects/spring-ai/blob/690d242c22a70d5d3ebe40436fdbca8a1e481e44/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorStore.java#L421

Environment
Spring AI v1.0.0-M6
Spring Boot 3.4.3
Java 17
PGVector store
Hikari datasource with auto-commit disabled

Steps to reproduce
Start an application with above configuration.

Expected behavior
Schema should be correctly initialized.

Minimal Complete Reproducible example

Workaround

Commit manually:

    jdbcTemplate.execute(
            new ConnectionCallback<String>() {
                public String doInConnection(Connection con) throws SQLException {
                    con.createStatement().execute("CREATE EXTENSION IF NOT EXISTS vector");
                    con.createStatement().execute("CREATE EXTENSION IF NOT EXISTS hstore");
                    con.createStatement().execute("CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\"");
                    con
                        .createStatement()
                        .execute(
                            String.format(
                                """
                                CREATE TABLE IF NOT EXISTS %s (
                                    id uuid DEFAULT uuid_generate_v4() PRIMARY KEY,
                                    content text,
                                    metadata json,
                                    embedding vector(%d)
                                )
                                """,
                                "vector_store",
                                1536
                            )
                        );
                    con.commit();
                    return null;
                }
            }
        );
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 10h
Merged PRs (30d)
5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from spring-projects/spring-ai

All issues in spring-projects/spring-ai

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.