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()
Comment From: sunyuhan1998
Hi @tonyschwartz , I originally thought this was a bug as well, and even tried submitting a PR, but I noticed that in fact, we should use group
to manually specify the nesting, like this:
b.and(
b.group(
b.or(
b.eq( "tenantId", tenantId1 ),
b.eq( "tenantId", tenantId2 )
)
),
b.ne( "docId", docId )
).build()