You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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= (lambdaoriginal:
lambdaself, *args, **kwargs: original(
self, *args,
**{k: vfork, vinkwargs.items() ifkininspect.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
The text was updated successfully, but these errors were encountered:
Describe the improvement
Support compatibility with
langchain-cohere
for rerank with AWS Bedrock by addingrank_fields
parameter support tocohere.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:Without it, I get:
cohere.BedrockClientV2
is required in my case because its the only client that supportsrerank
. See langchain-ai/langchain-cohere#12 for additional context.Code snippet of expected outcome
Simply use
cohere.BedrockClientV2
The text was updated successfully, but these errors were encountered: