|
4 | 4 | //! |
5 | 5 | //! With this SDK, you can seamlessly manage various database tables related to documents, text chunks, text splitters, LLM (Language Model) models, and embeddings. By leveraging the SDK's capabilities, you can efficiently index LLM embeddings using PgVector for fast and accurate queries. |
6 | 6 |
|
| 7 | +use once_cell::sync::Lazy; |
7 | 8 | use parking_lot::RwLock; |
8 | 9 | use sqlx::{postgres::PgPoolOptions,PgPool}; |
9 | 10 | use std::collections::HashMap; |
@@ -123,24 +124,15 @@ fn internal_init_logger(level: Option<String>, format: Option<String>) -> anyhow |
123 | 124 |
|
124 | 125 | // Normally the global async runtime is handled by tokio but because we are a library being called |
125 | 126 | // by javascript and other langauges, we occasionally need to handle it ourselves |
126 | | -#[allow(dead_code)] |
127 | | -staticmutRUNTIME:Option<Runtime> =None; |
| 127 | +staticRUNTIME:Lazy<Runtime> =Lazy::new(||{ |
| 128 | +Builder::new_multi_thread() |
| 129 | +.enable_all() |
| 130 | +.build() |
| 131 | +.expect("Error creating tokio runtime") |
| 132 | +}); |
128 | 133 |
|
129 | | -#[allow(dead_code)] |
130 | 134 | fnget_or_set_runtime<'a>() ->&'aRuntime{ |
131 | | -unsafe{ |
132 | | -ifletSome(r) =&RUNTIME{ |
133 | | - r |
134 | | -}else{ |
135 | | -// Need to use multi thread for JavaScript |
136 | | -let runtime =Builder::new_multi_thread() |
137 | | -.enable_all() |
138 | | -.build() |
139 | | -.expect("Error creating tokio runtime"); |
140 | | -RUNTIME =Some(runtime); |
141 | | -get_or_set_runtime() |
142 | | -} |
143 | | -} |
| 135 | +&RUNTIME |
144 | 136 | } |
145 | 137 |
|
146 | 138 | #[cfg(feature ="python")] |
|