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

Implement rank_fields compatibility with langchain-cohere and BedrockClientV2.rerank #628

Open
btiernay opened this issue Jan 6, 2025 · 2 comments
Assignees

Comments

@btiernay
Copy link

btiernay commented Jan 6, 2025

Describe the improvement

Support compatibility with langchain-cohere for rerank with AWS Bedrock by adding rank_fields parameter support to cohere.BedrockClientV2.rerank . Currently I have to do the following hack to get this to work, which removes anything that isn't in the formal method signature:

    # HACK: Override the `rerank` method to remove any unsupported parameters in this version of LangChain.
    cohere.BedrockClientV2.rerank = (lambda original:
                                     lambda self, *args, **kwargs: original(
                                         self, *args,
                                         **{k: v for k, v in kwargs.items() if
                                            k in inspect.signature(original).parameters}
                                     )
                                     )(cohere.BedrockClientV2.rerank)

Without it, I get:

...
  File ./langchain_cohere/rerank.py", line 123, in compress_documents
    for res in self.rerank(documents, query):
               ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "./langchain_cohere/rerank.py", line 90, in rerank
    results = self.client.rerank(
        query=query,
    ...<4 lines>...
        max_chunks_per_doc=max_chunks_per_doc,
    )
TypeError: V2Client.rerank() got an unexpected keyword argument 'rank_fields'

cohere.BedrockClientV2 is required in my case because its the only client that supports rerank. See langchain-ai/langchain-cohere#12 for additional context.

Code snippet of expected outcome

Simply use cohere.BedrockClientV2

@Gungz
Copy link

Gungz commented Jan 13, 2025

  • 1 on this, would be great if we can have it, I also face the same issue today.

@billytrend-cohere
Copy link
Collaborator

Hey, taking a look into this, thanks

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

No branches or pull requests

3 participants