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

Introduce SentenceTransformer Reranker #1810

Merged
merged 6 commits into from
Apr 2, 2024

Conversation

machatschek
Copy link
Contributor

Description

This PR introduces support for document reranking, specifically leveraging SentenceTransformer cross-encoders. The addition aims to provide a lightweight and optimized approach to reranking, enhancing the model's response quality and speed.

Motivation

The integration of a reranking feature addresses the need for more relevant and accurate responses by pre-filtering documents before answer generation. The choice of SentenceTransformer's cross-encoder as the reranker is motivated by its efficiency and effectiveness in identifying the most relevant documents, compared to traditional LLM-based reranking methods.

Changes Made

  • Added an optional SentenceTransformerRerank node_postprocessor to ChatService, which facilitates the reranking process using the SentenceTransformer cross-encoder.
  • Updated settings to include rerank-specific configurations, allowing users to enable and customize reranking according to their specific needs. This includes parameters such as model and top_n, where the latter controls the selection process of documents for final response generation.
  • Documentation updates to guide users through enabling reranking, installing necessary dependencies (poetry install --extras rerank-sentence-transformers), and configuring rerank settings effectively for optimal performance.

The reranking feature is disabled by default to accommodate the additional dependencies and the need for users to adjust configurations based on their unique use cases.

Future Considerations

Looking ahead, there's potential to further refine the reranking functionality by:

  • Creating a dedicated reranker component: This would facilitate the incorporation of different reranker types, enhancing flexibility and customization for users.
  • Expanding reranker support: Exploring and integrating additional reranker methods beyond the SentenceTransformer cross-encoder could provide users with more options to tailor the reranking process to their specific requirements.

pabloogc
pabloogc previously approved these changes Apr 1, 2024
Copy link
Collaborator

@pabloogc pabloogc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice job, useful feature too 👏

Copy link
Collaborator

@imartinez imartinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice contribution!

Copy link
Collaborator

@danielgallegovico danielgallegovico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat contribution!

@imartinez imartinez merged commit 83adc12 into zylon-ai:main Apr 2, 2024
7 of 8 checks passed
mrepetto-certx pushed a commit to mrepetto-certx/privateGPT that referenced this pull request Apr 18, 2024
@icsy7867
Copy link
Contributor

icsy7867 commented May 2, 2024

Does llamacpp-python need to be rebuilt for gpu? I would assume so. I've offloaded all of my gpu stuff, so I might have to update my pipeline if so @machatschek

@machatschek
Copy link
Contributor Author

machatschek commented May 2, 2024

Does llamacpp-python need to be rebuilt for gpu? I would assume so. I've offloaded all of my gpu stuff, so I might have to update my pipeline if so @machatschek

The SentenceTransformer reranker does not rely on llamacpp-python. If you want to run the reranker on GPU, you would need to install GPU-enabled PyTorch version. SentenceTransfromer will then use GPU by default if one is available. If you want to overwrite this behaviour, you can set the device parameter in SentenceTransformerRerank to "cpu".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants