Omar Solano commited on
Commit
e1d5b50
Β·
1 Parent(s): 19c1346

add try except for cohere reranker

Browse files
Files changed (1) hide show
  1. scripts/custom_retriever.py +15 -10
scripts/custom_retriever.py CHANGED
@@ -73,13 +73,18 @@ class CustomRetriever(BaseRetriever):
73
  else:
74
  nodes_context.append(node)
75
 
76
- reranker = CohereRerank(top_n=5, model="rerank-english-v3.0")
77
- nodes_context = reranker.postprocess_nodes(nodes_context, query_bundle)
78
- nodes_filtered = []
79
- for node in nodes_context:
80
- if node.score < 0.15:
81
- continue
82
- else:
83
- nodes_filtered.append(node)
84
- logfire.info(f"Cohere raranking to {len(nodes_filtered)} nodes")
85
- return nodes_filtered
 
 
 
 
 
 
73
  else:
74
  nodes_context.append(node)
75
 
76
+ try:
77
+ reranker = CohereRerank(top_n=5, model="rerank-english-v3.0")
78
+ nodes_context = reranker.postprocess_nodes(nodes_context, query_bundle)
79
+ nodes_filtered = []
80
+ for node in nodes_context:
81
+ if node.score < 0.10: # type: ignore
82
+ continue
83
+ else:
84
+ nodes_filtered.append(node)
85
+ logfire.info(f"Cohere raranking to {len(nodes_filtered)} nodes")
86
+
87
+ return nodes_filtered
88
+ except Exception as e:
89
+ logfire.error(f"Error reranking nodes with Cohere: {e}")
90
+ return nodes_context