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

feat (reranking) : Support for reranking models #3764

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

patelvivekdev
Copy link
Contributor

This PR adds support for re-ranking models in the Vercel AI SDK provider. Currently, the SDK supports embedding models from providers like Cohere and Mixedbread AI for building Retrieval-Augmented Generation (RAG) systems. By integrating re-ranking models, developers can enhance these systems by improving the relevance of the retrieved results without additional manual setup or using another SDK.

#3584

@patelvivekdev patelvivekdev marked this pull request as ready for review November 19, 2024 08:11
@patelvivekdev patelvivekdev marked this pull request as draft November 19, 2024 08:11
@patelvivekdev patelvivekdev changed the title feat (reranking) : Added reranking model in provider feat (reranking) : Support for reranking models Nov 19, 2024
@patelvivekdev patelvivekdev marked this pull request as ready for review November 20, 2024 07:58
@patelvivekdev
Copy link
Contributor Author

@lgrammel, Could you please take a look at this PR when you have a chance?

I would appreciate your feedback and guidance on this implementation.

@lgrammel
Copy link
Collaborator

lgrammel commented Nov 26, 2024

The implementation itself looks very good. However, at this point I'm not sure if we want to add reranking models to the AI SDK, because it increases the API surface that we need to manage, and I haven't gotten a chance to look at the different providers to understand what a common, stable API would look like.

What major providers other than Cohere offer re-ranking? I'm very hesitant to add any abstraction that is based on a single provider implementation.

@patelvivekdev
Copy link
Contributor Author

patelvivekdev commented Nov 26, 2024

Thank you for the feedback!

Major providers offering reranking capabilities:

  1. Cohere: Reranking API

  2. Together AI

  3. Voyage AI: Specialized reranking models

  4. MixedBread AI: Reranking endpoint

  5. Jina AI

These providers share common patterns in their APIs:

  • Input: Array of documents + query
  • Similar parameters (top_k/n, return_documents/input)
  • Output: Reranked indices with relevance scores

@patelvivekdev
Copy link
Contributor Author

Adding reranking support enhances the SDK's RAG capabilities:

  1. Complete RAG Pipeline:

    • Current: Embeddings + LLMs
    • With Reranking: Embeddings → Reranking → LLMs
    • Improves relevance of context before LLM processing
  2. Enhanced Semantic Search:

    • After vector similarity search via embeddings
    • Reranking refines results for better accuracy
    • Critical for high-precision information retrieval

This addition would give developers a complete, production-ready RAG solution within the SDK.

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.

2 participants