langchain_rust/semantic_router/
router.rs1use std::hash::{Hash, Hasher};
2
3#[derive(Debug, Clone)]
4pub struct Router {
5 pub name: String,
6 pub utterances: Vec<String>,
7 pub embedding: Option<Vec<Vec<f64>>>,
8 pub similarity: Option<f64>,
9 pub tool_description: Option<String>,
10}
11impl Router {
12 pub fn new<S: AsRef<str>>(name: &str, utterances: &[S]) -> Self {
13 Self {
14 name: name.into(),
15 utterances: utterances.iter().map(|s| s.as_ref().to_string()).collect(),
16 embedding: None,
17 similarity: None,
18 tool_description: None,
19 }
20 }
21
22 pub fn with_embedding(mut self, embedding: Vec<Vec<f64>>) -> Self {
23 self.embedding = Some(embedding);
24 self
25 }
26
27 pub fn with_tool_description<S: Into<String>>(mut self, tool_description: S) -> Self {
28 self.tool_description = Some(tool_description.into());
29 self
30 }
31
32 pub fn with_similarity(mut self, similarity: f64) -> Self {
33 self.similarity = Some(similarity);
34 self
35 }
36}
37
38impl Eq for Router {}
39impl PartialEq for Router {
40 fn eq(&self, other: &Self) -> bool {
41 self.name == other.name
42 }
43}
44
45impl Hash for Router {
46 fn hash<H: Hasher>(&self, state: &mut H) {
47 self.name.hash(state);
48 }
49}