langchain_rust/semantic_router/index/
index.rs

1use async_trait::async_trait;
2
3use crate::semantic_router::{IndexError, Router};
4
5#[async_trait]
6pub trait Index {
7    async fn add(&mut self, router: &[Router]) -> Result<(), IndexError>;
8
9    async fn delete(&mut self, route_name: &str) -> Result<(), IndexError>;
10
11    /// Query the index with a vector and return the top_k most similar routes.
12    /// Returns a list of tuples with the route name and the similarity score.
13    /// Result<Vec<(route_name,similarity_score)>>
14    async fn query(&self, vector: &[f64], top_k: usize) -> Result<Vec<(String, f64)>, IndexError>;
15
16    async fn get_routers(&self) -> Result<Vec<Router>, IndexError>;
17
18    async fn get_router(&self, route_name: &str) -> Result<Router, IndexError>;
19
20    async fn delete_index(&mut self) -> Result<(), IndexError>;
21}