Skip to content

PgVectorStore does not handle ANDs and ORs together properly when using the FilterExpressionBuilder #3577

Open
@tonyschwartz

Description

@tonyschwartz

Bug description
When using the FilterExpressionBuilder with PgVectorStore, for example:

FilterExpressionBuilder b = new FilterExpressionBuilder();
b.and(
	b.or(
		b.eq( "tenantId", context.getTenantId() ),
		b.eq( "tenantId", this.globalTenantId )
	),
	b.ne( "docId", userJobDescriptionDocId )
).build()

and sending that to the SearchRequest.builder, it doesn't work properly because the final expression that is generated does not use parentheses, and so the expression is broken. you end up with: x || y && z

Environment
any

Steps to reproduce
see description

Expected behavior
The expressions, ANDs and ORs should contain parentheses.

Minimal Complete Reproducible example

FilterExpressionBuilder b = new FilterExpressionBuilder();
chatClientRequestSpec.advisors(
					QuestionAnswerAdvisor.builder( vectorStore ).searchRequest(
						SearchRequest.builder().query( chatRequest.getPrompt() ).similarityThreshold( .70 ).topK( 5 ).filterExpression(
							b.and(
								b.or(
									b.eq( "tenantId", tenantId1 ),
									b.eq( "tenantId", tenantId2 )
								),
								b.ne( "docId", docId )
							).build()
						).build()
					).build()
).stream().chatResponse()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions