spring-projects / spring-projects/spring-ai

similaritySearch throwing Exception due to schema name

Open
#4,130 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

Bug description
When doing a similaritySearch using the VectorStore on a database where the schema name contains a - i run into an exception.

PreparedStatementCallback; bad SQL grammar [SELECT *, embedding <=> ? AS distance FROM demo-1998.vector_store WHERE embedding <=> ? < ?  AND metadata::jsonb @@ '($.entityType == "PROCESS" ...)'::jsonpath  ORDER BY distance LIMIT ? ]

I'm pretty sure that it is related to the schema name here. A possible fix could be wrapping the schema name in " on SpringAI side.

Environment
Dependencies using Spring Boot 3.5.4 and Java 20

implementation("org.springframework.ai:spring-ai-starter-mcp-server-webmvc")
implementation("org.springframework.ai:spring-ai-starter-model-azure-openai")
implementation("org.springframework.ai:spring-ai-starter-vector-store-pgvector")

Steps to reproduce

  • Do a similaritySearch call on a database schema which has a - in its name

Expected behavior
No exceptions are thrown

Minimal Complete Reproducible example

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.

Research direction

Start at the VectorStore similaritySearch path that produces the PostgreSQL SQL shown in the exception, and trace how the schema name enters that query. Reproduce with a schema containing a hyphen, then verify that the query completes without an exception and that ordinary schema names still work.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, postgresql
Domain
databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.