-
-
Notifications
You must be signed in to change notification settings - Fork 190
Add global Rerank interface with Cohere Rerank model support #276
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
Open
infinityrobot
wants to merge
33
commits into
crmne:main
Choose a base branch
from
infinityrobot:add-cohere-reranking-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add global Rerank interface with Cohere Rerank model support #276
infinityrobot
wants to merge
33
commits into
crmne:main
from
infinityrobot:add-cohere-reranking-support
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 tasks
1e2ae2a
to
36669f1
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Important
Note! This PR is branched off and is dependent on the Cohere
Provider
implementation in #275.Reranking has been submitted as a separate contribution to allow for a meaningful review independent of the core Cohere
Provider
implementation. The diff here might be a bit complicated until the core Cohere implementation is approved.What this does
Note
This PR adds support for reranking to RubyLLM, enabling semantic reranking of search results and document collections. The initial implementation supports Cohere's Rerank models.
Why add reranking?
Reranking is a standard step in retrieval-augmented generation (RAG) pipelines that bridges retrieval and generation workflows. It's not application-specific logic but rather a foundational communication pattern with LLMs that most users implementing search, recommendation, or RAG systems will need.
Reranking broadly serves multiple common use cases:
Implementation overview
The reranking implementation is primarily via a new
RubyLLM::Rerank
class which operates via a pattern that mirrors that of the currentRubyLLM::Embedding
implementation.Note
To facilitate easy reranking, a
default_rerank_model
attribute has been added toConfiguration
which is set to Cohere'srerank-v3.5
.The main entry point is
RubyLLM.rerank(...)
which delegates toRubyLLM::Rerank.rank(...)
. This method accepts:query
– The search query to evaluate documents againstdocuments
– An array of text documents to reranktop_n
– Top number of results to returnmax_tokens_per_doc
– Max tokens per doc for chunkingmodel
,provider
, ,context
,assume_model_exists
Using the
Provider
Reranking
interface – e.g.,RubyLLM::Providers::Cohere::Reranking
– the API payload with the query, documents, and parameters are prepared and submitted.If successful, the response is parsed and a
Rerank
object is returned with:model
– The ID of the model usedresults
– The results of the reranking, returned as an array ofRerankResult
objects sorted byrelevance_score
containing:index
– The originaldocument
index indocuments
relevance_score
– Score between 0-1 with 1 being perfectly relevantdocument
– The document content testedsearch_units
– The billable units returned by providers like Cohere, TogetherAI, etc.Usage example
Implementation notes
docs/guides/rerank.md
rerank-v3.5
,rerank-english-v3.0
,rerank-multilingual-v3.0
, etc.)rerank_context.rerank(...)
)Type of change
Scope check
Quality check
overcommit --install
and all hooks passmodels.json
,aliases.json
)API changes
Related issues
No related issues.