Description
Bug description
When using PGvector as vector store for VectorStoreChatMemoryAdvisor to save conversation history, there is org.postgresql.util.PSQLException "ERROR: syntax error at or near "conversationId"". The problem happens because in adviseRequest method in VectorStoreChatMemoryAdvisor single quotes added around DOCUMENT_METADATA_CONVERSATION_ID, which causes an error when parse it in JDBCTemplate.
var searchRequest = SearchRequest.query(request.userText())
.withTopK(this.doGetChatMemoryRetrieveSize(context))
.withFilterExpression(
"'" + DOCUMENT_METADATA_CONVERSATION_ID + "'=='" + this.doGetConversationId(context) + "'");
Environment
SpringAI - 1.0.0-M1
SpringBoot - 3.2.6
Java - 21
Steps to reproduce
- Create simple application with org.springframework.ai:spring-ai-openai-spring-boot-starter and org.springframework.ai:spring-ai-pgvector-store-spring-boot-starter dependencies
- Configure PGvector as instructed in [https://docs.spring.io/spring-ai/reference/api/vectordbs/pgvector.html#_run_postgres_pgvector_db_locally](PGvector docs)
- Create new
ChatClient
bean withVectorStoreChatMemoryAdvisor
default advisor and provide advisor with autowired vector store - Try to prompt created chatClient. When
VectorStoreChatMemoryAdvisor
tries to do similarity search, exception will be thrown.
Expected behavior
Return conversation history if any present in PGvector
Custom solution
I extended from VectorStoreChatMemoryAdvisor
, copiedadviseRequest
method and manually removed this single quotes around DOCUMENT_METADATA_CONVERSATION_ID
. It completely worked for me.