@@ -963,6 +963,13 @@ pub async fn cross_encoder(
963963
964964 let mut results = results. clone ( ) ;
965965
966+ let ureq_agent = ureq:: AgentBuilder :: new ( )
967+ . tls_connector ( Arc :: new ( native_tls:: TlsConnector :: new ( ) . map_err ( |_| {
968+ ServiceError :: InternalServerError ( "Failed to acquire tls connection" . to_string ( ) )
969+ } ) ?) )
970+ . timeout ( std:: time:: Duration :: from_secs ( 5 ) )
971+ . build ( ) ;
972+
966973 if results. len ( ) <= 20 {
967974 let reranker_api_key = dataset_config. RERANKER_API_KEY . clone ( ) ;
968975 if server_origin != default_server_origin {
@@ -979,8 +986,8 @@ pub async fn cross_encoder(
979986 } ,
980987 } ] ;
981988
982- let resp = ureq :: post ( & server_origin )
983- . timeout ( std :: time :: Duration :: from_secs ( 5 ) )
989+ let resp = ureq_agent
990+ . post ( & server_origin )
984991 . set (
985992 "Authorization" ,
986993 & format ! ( "Bearer {}" , reranker_api_key. clone( ) ) ,
@@ -1011,14 +1018,7 @@ pub async fn cross_encoder(
10111018 }
10121019 } else {
10131020 // Assume Cohere integration for small batch.
1014- let resp = ureq:: AgentBuilder :: new ( )
1015- . tls_connector ( Arc :: new ( native_tls:: TlsConnector :: new ( ) . map_err ( |_| {
1016- ServiceError :: InternalServerError (
1017- "Failed to acquire tls connection" . to_string ( ) ,
1018- )
1019- } ) ?) )
1020- . timeout ( std:: time:: Duration :: from_secs ( 5 ) )
1021- . build ( )
1021+ let resp = ureq_agent
10221022 . post ( & embedding_server_call)
10231023 . set ( "Content-Type" , "application/json" )
10241024 . set (
@@ -1048,14 +1048,7 @@ pub async fn cross_encoder(
10481048 } ) ;
10491049 }
10501050 } else {
1051- let resp = ureq:: AgentBuilder :: new ( )
1052- . tls_connector ( Arc :: new ( native_tls:: TlsConnector :: new ( ) . map_err ( |_| {
1053- ServiceError :: InternalServerError (
1054- "Failed to acquire tls connection" . to_string ( ) ,
1055- )
1056- } ) ?) )
1057- . timeout ( std:: time:: Duration :: from_secs ( 5 ) )
1058- . build ( )
1051+ let resp = ureq_agent
10591052 . post ( & embedding_server_call)
10601053 . set ( "Content-Type" , "application/json" )
10611054 . set (
0 commit comments