Skip to content

VectorStoreChatMemoryAdvisor is not working correctly with PGvector #800

Closed
@MarkKorenevskiy

Description

@MarkKorenevskiy

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

  1. 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
  2. Configure PGvector as instructed in [https://docs.spring.io/spring-ai/reference/api/vectordbs/pgvector.html#_run_postgres_pgvector_db_locally](PGvector docs)
  3. Create new ChatClient bean with VectorStoreChatMemoryAdvisor default advisor and provide advisor with autowired vector store
  4. 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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions