global: snapshot

This commit is contained in:
nym21
2025-04-02 16:20:17 +02:00
parent 0bb869fb33
commit a07b641adb
25 changed files with 583 additions and 244 deletions

View File

@@ -1,4 +1,11 @@
use axum::{Router, routing::get};
use std::collections::BTreeMap;
use axum::{
Router,
extract::State,
response::{IntoResponse, Response},
routing::get,
};
use super::AppState;
@@ -14,5 +21,42 @@ pub trait ApiRoutes {
impl ApiRoutes for Router<AppState> {
fn add_api_routes(self) -> Self {
self.route("/api/query", get(query::handler))
.route("/api/vecs/ids", get(vecids_handler))
.route("/api/vecs/indexes", get(vecindexes_handler))
.route("/api/vecs/id-to-indexes", get(vecid_to_vecindexes_handler))
.route("/api/vecs/index-to-ids", get(vecindex_to_vecids_handler))
}
}
pub async fn vecids_handler(State(app_state): State<AppState>) -> Response {
axum::Json(
app_state
.query
.vec_trees
.id_to_index_to_vec
.keys()
.collect::<Vec<_>>(),
)
.into_response()
}
pub async fn vecindexes_handler(State(app_state): State<AppState>) -> Response {
axum::Json(
app_state
.query
.vec_trees
.index_to_id_to_vec
.keys()
.map(|i| (i.to_string().to_lowercase(), i.possible_values()))
.collect::<BTreeMap<_, _>>(),
)
.into_response()
}
pub async fn vecid_to_vecindexes_handler(State(app_state): State<AppState>) -> Response {
axum::Json(app_state.query.vec_trees.serialize_id_to_index_to_vec()).into_response()
}
pub async fn vecindex_to_vecids_handler(State(app_state): State<AppState>) -> Response {
axum::Json(app_state.query.vec_trees.serialize_index_to_id_to_vec()).into_response()
}