New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancing Elasticsearch vector store implementation #592
base: main
Are you sure you want to change the base?
Conversation
Hi @l-trotta, Thanks for the update. I liked how script_score was quick to implement due to available examples, but I'm pleased we're switching to KNN for better performance. I find the automatic creation of index mappings convenient; however, for my projects, I typically need to define these mappings in advance. Could we consider adding an option to provide index mappings directly in the constructor? Additionally, could you check if the code at ElasticsearchAiSearchFilterExpressionConverter.java needs any improvements? I'm also looking forward to the official documentation for the Elasticsearch vector store of the Spring AI project, which I think @tzolov will address. |
Hi @JM-Lab, Since the index mapping can be added with The filter converter looked fine to me! |
Updated! I'd like to explain why I removed the
And since this implementation uses kNN search, setting this to false would make the data unsearchable. |
This PR provides a more performant search function for the Elasticsearch vector store and removes the bean autoconfiguration.
In depth
Autoconfiguration
The current implementation of
afterPropertiesSet()
automatically creates a new index with a set of properties that only works with OpenAI, or any other model that works with vectors with a dimension of 1536; users adopting other models would currently have to manually delete the index. By default, Elasticsearch automatically creates the correct index settings when it receives the first PUT request for vectors, so in our opinion there's no need for such autoconfiguration.Search
The function used now is script_score, which can be slow for large data samples since it does a brute force comparison with all vectors using the similarity function. This PR replaces it with the approximate knn search, more performant because it only scans the closest neighbours. The similarity functions available for
knn
can be easily configured in the index mapping by setting the correct name.We would also like to contribute to the documentation, should that be done in a different PR?
Thank you @JM-Lab for the original implementation, would you like to review these changes?
(Disclosure: I work for Elastic)