Hi,

I got this NPE every time I started my application using spring-ai-redis.

java.lang.NullPointerException: Cannot invoke "org.springframework.ai.vectorstore.filter.converter.FilterExpressionConverter.convertExpression(org.springframework.ai.vectorstore.filter.Filter$Expression)" because "this.filterExpressionConverter" is null
    at org.springframework.ai.vectorstore.RedisVectorStore.nativeExpressionFilter(RedisVectorStore.java:394) ~[spring-ai-redis-0.8.0-20240114.220504-53.jar:0.8.0-SNAPSHOT]

It seems that the filterExpressionConverter is not initialized once the index has been created in Redis. The only place, where this field is set, is inside the method afterPropertiesSet() along with the check if index exists & its creation. This is not a necessity to have the index creation and intialization of the filterExpressionConverter field.

I purpose that the initialization to be done before the check of index existence. Thank you.

Cheers, Bram

Comment From: tzolov

@bram-pramono the afterPropertiesSet() is automatically called if the RedisVectorStore is initialised as a @Bean. For example in RedisVectorStoreIT .

But if you decide to create it manually, then you must call the RedisVectorStore#afterPropertiesSet() after setting the properties and before using the client.

I also updated the spring-ai redis docs to note this detail.

Comment From: apihug

I guess, the filterExpressionConverter should be inited at first line of the afterPropertiesSet() not matter the index exist or not. or at least mark it as protected so sub-class can extend the logic.

Comment From: tzolov

Ah, I see it now. Your observation makes perfect sense. Just pushed a patch: 0abf1528dd6d6bb3a6747c4bb435b30bb4c3dd46 that moves the filter configuration to the constructor. Let me know if it solves the issue for you?

@apihug thank you for catching this problem!

Comment From: apihug

my pleasure :-)

Comment From: tzolov

Fixed with https://github.com/spring-projects/spring-ai/commit/0abf1528dd6d6bb3a6747c4bb435b30bb4c3dd46

Comment From: bram-pramono

it looks much better now :) thx @apihug & @tzolov