Skip to content
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

Elasticsearch: support dense, sparse, hybrid with inference in Elasticsearch #699

Open
10 tasks
maxjakob opened this issue Apr 29, 2024 · 7 comments
Open
10 tasks
Labels
integration:elasticsearch new integration Discuss the creation of a new integration in Core

Comments

@maxjakob
Copy link
Contributor

Summary and motivation

Elasticsearch offers multiple retrieval features including

  • approximate dense vector retrieval with embedding inference in Python or in Elasticsearch
  • exact dense vector retrieval with embedding inference in Python
  • sparse vector retrieval with embedding inference in Elasticsearch
  • hybrid retrieval (dense+BM25) with embedding inference in Elasticsearch

Other libraries such as LangChain already have all these options integrated. It would be great to also have them available in Haystack. Elastic is currently working on a Python package that will make the integration of these features easier. Here we want to discuss how to best make them available.

Questions

  • Does Haystack want to enable inference in Elasticsearch? The current design assumes that mapping from input string to embedding vector is done in Python before calling a retriever. With inference in Elasticsearch, this would change. For example, users could configure a dense vector model in Elasticsearch and then use input strings in Haystack.
  • The options mentioned above require different ways of indexing the data. How to best incorporate this requirement? The current document store abstraction kind of assumes that there is only one way of indexing.

Detailed design

Concrete proposal:

  1. ElasticsearchDocumentStore takes an argument retrieval_strategy similarly to how it is down in LangChain. Calls to write_documents make use of the retrieval strategy to know how to index the data.
  2. We add a number of different retrievers (ElasticsearchDenseVectorRetriever, ElasticsearchSparseVectorRetriever, ElasticsearchHybridRetriever, ...) that get initialized with an ElasticsearchDocumentStore. The retrieval strategy has to match the expectation of the individual retrievers. We check that the expectation is met upon initialization. For retrieving documents, the retrievers call a search method on the document store as this is the established pattern.

Checklist

If the request is accepted, ensure the following checklist is complete before closing this issue.

Tasks

Preview Give feedback
@maxjakob maxjakob added the new integration Discuss the creation of a new integration in Core label Apr 29, 2024
@maxjakob
Copy link
Contributor Author

@anakin87 @silvanocerza Would be great to get your input here.

@silvanocerza
Copy link
Contributor

I don't see why not to be fair, I'm not against this at all.
Everything you wrote makes totally sense in my opinion.

@silvanocerza
Copy link
Contributor

Are you going to handle the implementation of this? 👀

@anakin87
Copy link
Member

thank you for your interest!

  • I would like to provide users with new options (such as inference in Elasticsearch) without significantly breaking existing ones.
  • This is the current naming convention for Retrievers. We should discuss together what would be the best names for the new retrievers.

@maxjakob
Copy link
Contributor Author

I agree that breaking changes should be avoided. We can attempt to integrate this into the existing document store. If it proves too hard without breakage we can add a new class (and deprecate the old one). What do you think?

Regarding naming, here are some proposals (I'm completely open to other names):

  • ElasticsearchBM25Retriever
  • ElasticsearchDenseEmbeddingRetriever
    • This would have a hybrid option. Alternatively we can add a ElasticsearchHybridRetriever.
  • ElasticsearchDenseExactEmbeddingRetriever (not convinced we need it but it is more efficient for <10k documents)
  • ElasticsearchSparseEmbeddingRetriever

@maxjakob
Copy link
Contributor Author

I'm going to work on the LangChain integration. It will become the reference implementation for this kind of integration with the package mentioned above.
It would be fantastic if somebody from the community wants to give it a shot and integrate this into Haystack. That somebody would be invited to write a blog post for Elastic Search Labs to get some exposure for them and their Haystack use case in order to make a bit of a marketing noise, if they want to do this kind of thing.

@maxjakob
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration:elasticsearch new integration Discuss the creation of a new integration in Core
Projects
None yet
Development

No branches or pull requests

4 participants