Skip to content

Commit b5c9024

Browse files
committed
update: test case
1 parent 37439f5 commit b5c9024

File tree

2 files changed

+189
-91
lines changed

2 files changed

+189
-91
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
source: router/tests/test_http_embed.rs
3+
assertion_line: 33
4+
expression: embeddings_single
5+
---
6+
- - 0.020964028
7+
- 0.04565802
8+
- -0.066505834
9+
- 0.10739284
10+
- -0.013054225
11+
- -0.074676
12+
- 0.13989432
13+
- 0.06780746
14+
- 0.022699486
15+
- -0.011153354
16+
- 0.030836595
17+
- -0.13956568
18+
- -0.0007679629
19+
- 0.05042272
20+
- -0.028967943
21+
- -0.123677045
22+
- 0.016125135
23+
- -0.036846906
24+
- -0.145736
25+
- -0.02373245
26+
- -0.0745195
27+
- -0.046681724
28+
- -0.0482189
29+
- 0.059916265
30+
- -0.04010451
31+
- 0.038125258
32+
- -0.10496603
33+
- 0.05981593
34+
- 0.05392072
35+
- -0.11278696
36+
- 0.07032668
37+
- 0.057939023
38+
- 0.02778035
39+
- 0.08221898
40+
- 0.09622914
41+
- 0.02419897
42+
- 0.07466661
43+
- 0.050956063
44+
- 0.03522559
45+
- -0.0059160567
46+
- -0.006516073
47+
- -0.25893325
48+
- 0.06894633
49+
- -0.019899387
50+
- 0.04731431
51+
- 0.07508748
52+
- -0.029141093
53+
- 0.09708059
54+
- -0.102892384
55+
- 0.0221161
56+
- -0.0635292
57+
- -0.07202666
58+
- -0.08355097
59+
- -0.07089743
60+
- -0.032660127
61+
- 0.039239414
62+
- -0.011755509
63+
- -0.04810411
64+
- 0.088166565
65+
- 0.07864387
66+
- 0.08385171
67+
- -0.062469278
68+
- -0.043762952
69+
- 0.10090823
70+
- 0.044606347
71+
- 0.03526079
72+
- 0.020471726
73+
- -0.04660194
74+
- -0.05844183
75+
- -0.059265647
76+
- -0.026472175
77+
- 0.026590858
78+
- 0.01875294
79+
- 0.1344086
80+
- 0.14505184
81+
- -0.0076243132
82+
- 0.0048931646
83+
- -0.13905056
84+
- 0.10659304
85+
- -0.008705274
86+
- -0.15836889
87+
- -0.08412147
88+
- -0.07179273
89+
- 0.09513935
90+
- 0.044845596
91+
- 0.1462115
92+
- 0.21719754
93+
- 0.057623506
94+
- -0.20648007
95+
- 0.019382326
96+
- 0.03581364
97+
- 0.07008155
98+
- -0.06274128
99+
- -0.011106757
100+
- -0.07717128
101+
- 0.041089788
102+
- 0.015186751
103+
- -0.035322264
104+
- -0.042230345
105+
- 0.44461676
106+
- 0.089619726
107+
- 0.052916277
108+
- -0.010440798
109+
- -0.037045464
110+
- -0.14071313
111+
- -0.07794195
112+
- 0.00072461966
113+
- -0.12116826
114+
- 0.12817718
115+
- 0.011752636
116+
- -0.106016025
117+
- -0.009204605
118+
- 0.05600078
119+
- 0.04988507
120+
- 0.0492185
121+
- -0.12354064
122+
- -0.11913096
123+
- 0.10714254
124+
- -0.05773055
125+
- 0.07365335
126+
- 0.10331037
127+
- 0.0126717
128+
- 0.011246378
129+
- -0.023940507
130+
- 0.056565095
131+
- -0.073130794
132+
- 0.12836735
133+
- -0.0000000000000000000000000000000087874264
134+

router/tests/test_http_embed.rs

Lines changed: 55 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,55 @@
1-
// mod common;
2-
//
3-
// use crate::common::{start_server, Score};
4-
// use anyhow::Result;
5-
// use insta::internals::YamlMatcher;
6-
// use serde_json::json;
7-
// use text_embeddings_backend::DType;
8-
//
9-
// #[tokio::test]
10-
// #[cfg(feature = "http")]
11-
// async fn test_embeddings() -> Result<()> {
12-
// start_server(
13-
// "sentence-transformers/all-MiniLM-L6-v2".to_string(),
14-
// None,
15-
// DType::Float32,
16-
// )
17-
// .await?;
18-
//
19-
// let request = json!({
20-
// "inputs": "test"
21-
// });
22-
// let client = reqwest::Client::new();
23-
// let res = client
24-
// .post("http://0.0.0.0:8090/embed")
25-
// .json(&request)
26-
// .send()
27-
// .await?;
28-
//
29-
// let embeddings_single = res.json::<Vec<Vec<Score>>>().await?;
30-
// let matcher = YamlMatcher::<Vec<Vec<Score>>>::new();
31-
// insta::assert_yaml_snapshot!("embeddings_single", embeddings_single, &matcher);
32-
//
33-
// let test_tokens = vec![[101, 3231, 102]]; // tokenized "test"
34-
// let request = json!({"inputs": &test_tokens});
35-
// let res = client
36-
// .post("http://0.0.0.0:8090/embed")
37-
// .json(&request)
38-
// .send()
39-
// .await?;
40-
//
41-
// let embeddings_single = res.json::<Vec<Vec<Score>>>().await?;
42-
// let matcher = YamlMatcher::<Vec<Vec<Score>>>::new();
43-
// insta::assert_yaml_snapshot!("embeddings_single", embeddings_single, &matcher);
44-
//
45-
// let request = json!({
46-
// "inputs": vec!["test", "test", "test", "test", "test"],
47-
// });
48-
//
49-
// let client = reqwest::Client::new();
50-
// let res = client
51-
// .post("http://0.0.0.0:8090/embed")
52-
// .json(&request)
53-
// .send()
54-
// .await?;
55-
// let embeddings_batch = res.json::<Vec<Vec<Score>>>().await?;
56-
// insta::assert_yaml_snapshot!("embeddings_batch", embeddings_batch, &matcher);
57-
// for embeddings in &embeddings_batch {
58-
// assert_eq!(embeddings, &embeddings_single[0]);
59-
// }
60-
//
61-
// let request =
62-
// json!({"inputs": &test_tokens.repeat(request["inputs"].as_array().unwrap().len())});
63-
// let res = client
64-
// .post("http://0.0.0.0:8090/embed")
65-
// .json(&request)
66-
// .send()
67-
// .await?;
68-
//
69-
// let embeddings_batch = res.json::<Vec<Vec<Score>>>().await?;
70-
// insta::assert_yaml_snapshot!("embeddings_batch", embeddings_batch, &matcher);
71-
// for embeddings in &embeddings_batch {
72-
// assert_eq!(embeddings, &embeddings_single[0]);
73-
// }
74-
//
75-
// let request = json!({
76-
// "inputs": "test"
77-
// });
78-
//
79-
// let client = reqwest::Client::new();
80-
// let res = client
81-
// .post("http://0.0.0.0:8090/embed_all")
82-
// .json(&request)
83-
// .send()
84-
// .await?;
85-
//
86-
// let embeddings_raw = res.json::<Vec<Vec<Vec<Score>>>>().await?;
87-
// let matcher = YamlMatcher::<Vec<Vec<Vec<Score>>>>::new();
88-
// insta::assert_yaml_snapshot!("embeddings_raw", embeddings_raw, &matcher);
89-
//
90-
// Ok(())
91-
// }
1+
mod common;
2+
3+
use crate::common::{start_server, Score};
4+
use anyhow::Result;
5+
use insta::internals::YamlMatcher;
6+
use serde_json::json;
7+
use text_embeddings_backend::DType;
8+
9+
#[tokio::test]
10+
#[cfg(feature = "http")]
11+
async fn test_mrl_embeddings() -> Result<()> {
12+
start_server(
13+
"sentence-transformers/all-MiniLM-L6-v2".to_string(),
14+
None,
15+
DType::Float32,
16+
)
17+
.await?;
18+
19+
let request = json!({
20+
"inputs": "test",
21+
"dimensions": 128,
22+
});
23+
24+
let client = reqwest::Client::new();
25+
let res = client
26+
.post("http://0.0.0.0:8090/embed")
27+
.json(&request)
28+
.send()
29+
.await?;
30+
31+
let embeddings_single = res.json::<Vec<Vec<Score>>>().await?;
32+
let matcher = YamlMatcher::<Vec<Vec<Score>>>::new();
33+
insta::assert_yaml_snapshot!("mrl_embeddings_single", embeddings_single, &matcher);
34+
35+
let request = json!({
36+
"inputs": vec!["test", "test", "test"],
37+
"dimensions": 128,
38+
});
39+
40+
let client = reqwest::Client::new();
41+
let res = client
42+
.post("http://0.0.0.0:8090/embed")
43+
.json(&request)
44+
.send()
45+
.await?;
46+
47+
let embeddings_batch = res.json::<Vec<Vec<Score>>>().await?;
48+
insta::assert_yaml_snapshot!("mrl_embeddings_batch", embeddings_batch, &matcher);
49+
50+
for embeddings in &embeddings_batch {
51+
assert_eq!(embeddings, &embeddings_single[0]);
52+
}
53+
54+
Ok(())
55+
}

0 commit comments

Comments
 (0)