Omar Solano
commited on
Commit
Β·
e1d5b50
1
Parent(s):
19c1346
add try except for cohere reranker
Browse files- 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 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
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
|