add a test on the settings value

This commit is contained in:
Tamo 2024-09-19 11:16:30 +02:00
parent 3f6301dbc9
commit e8d7c00d30
2 changed files with 85 additions and 8 deletions

View File

@ -643,12 +643,19 @@ fn embedder_analytics(
.max() .max()
}); });
let binary_quantization_used = setting.as_ref().map(|map| {
map.values()
.filter_map(|config| config.clone().set())
.any(|config| config.binary_quantized.set().is_some())
});
json!( json!(
{ {
"total": setting.as_ref().map(|s| s.len()), "total": setting.as_ref().map(|s| s.len()),
"sources": sources, "sources": sources,
"document_template_used": document_template_used, "document_template_used": document_template_used,
"document_template_max_bytes": document_template_max_bytes "document_template_max_bytes": document_template_max_bytes,
"binary_quantization_used": binary_quantization_used,
} }
) )
} }

View File

@ -4,6 +4,76 @@ use crate::common::{GetAllDocumentsOptions, Server};
use crate::json; use crate::json;
use crate::vector::generate_default_user_provided_documents; use crate::vector::generate_default_user_provided_documents;
#[actix_rt::test]
async fn retrieve_binary_quantize_status_in_the_settings() {
let server = Server::new().await;
let index = server.index("doggo");
let (value, code) = server.set_features(json!({"vectorStore": true})).await;
snapshot!(code, @"200 OK");
snapshot!(value, @r###"
{
"vectorStore": true,
"metrics": false,
"logsRoute": false,
"editDocumentsByFunction": false,
"containsFilter": false
}
"###);
let (response, code) = index
.update_settings(json!({
"embedders": {
"manual": {
"source": "userProvided",
"dimensions": 3,
}
},
}))
.await;
snapshot!(code, @"202 Accepted");
server.wait_task(response.uid()).await.succeeded();
let (settings, code) = index.settings().await;
snapshot!(code, @"200 OK");
snapshot!(settings["embedders"]["manual"], @r###"{"source":"userProvided","dimensions":3}"###);
let (response, code) = index
.update_settings(json!({
"embedders": {
"manual": {
"source": "userProvided",
"dimensions": 3,
"binaryQuantized": false,
}
},
}))
.await;
snapshot!(code, @"202 Accepted");
server.wait_task(response.uid()).await.succeeded();
let (settings, code) = index.settings().await;
snapshot!(code, @"200 OK");
snapshot!(settings["embedders"]["manual"], @r###"{"source":"userProvided","dimensions":3,"binaryQuantized":false}"###);
let (response, code) = index
.update_settings(json!({
"embedders": {
"manual": {
"source": "userProvided",
"dimensions": 3,
"binaryQuantized": true,
}
},
}))
.await;
snapshot!(code, @"202 Accepted");
server.wait_task(response.uid()).await.succeeded();
let (settings, code) = index.settings().await;
snapshot!(code, @"200 OK");
snapshot!(settings["embedders"]["manual"], @r###"{"source":"userProvided","dimensions":3,"binaryQuantized":true}"###);
}
#[actix_rt::test] #[actix_rt::test]
async fn binary_quantize_before_sending_documents() { async fn binary_quantize_before_sending_documents() {
let server = Server::new().await; let server = Server::new().await;
@ -32,7 +102,7 @@ async fn binary_quantize_before_sending_documents() {
})) }))
.await; .await;
snapshot!(code, @"202 Accepted"); snapshot!(code, @"202 Accepted");
server.wait_task(response.uid()).await; server.wait_task(response.uid()).await.succeeded();
let documents = json!([ let documents = json!([
{"id": 0, "name": "kefir", "_vectors": { "manual": [-1.2, -2.3, 3.2] }}, {"id": 0, "name": "kefir", "_vectors": { "manual": [-1.2, -2.3, 3.2] }},
@ -40,7 +110,7 @@ async fn binary_quantize_before_sending_documents() {
]); ]);
let (value, code) = index.add_documents(documents, None).await; let (value, code) = index.add_documents(documents, None).await;
snapshot!(code, @"202 Accepted"); snapshot!(code, @"202 Accepted");
index.wait_task(value.uid()).await; index.wait_task(value.uid()).await.succeeded();
// Make sure the documents DB has been cleared // Make sure the documents DB has been cleared
let (documents, _code) = index let (documents, _code) = index
@ -94,7 +164,7 @@ async fn binary_quantize_after_sending_documents() {
})) }))
.await; .await;
snapshot!(code, @"202 Accepted"); snapshot!(code, @"202 Accepted");
server.wait_task(response.uid()).await; server.wait_task(response.uid()).await.succeeded();
let documents = json!([ let documents = json!([
{"id": 0, "name": "kefir", "_vectors": { "manual": [-1.2, -2.3, 3.2] }}, {"id": 0, "name": "kefir", "_vectors": { "manual": [-1.2, -2.3, 3.2] }},
@ -102,7 +172,7 @@ async fn binary_quantize_after_sending_documents() {
]); ]);
let (value, code) = index.add_documents(documents, None).await; let (value, code) = index.add_documents(documents, None).await;
snapshot!(code, @"202 Accepted"); snapshot!(code, @"202 Accepted");
index.wait_task(value.uid()).await; index.wait_task(value.uid()).await.succeeded();
let (response, code) = index let (response, code) = index
.update_settings(json!({ .update_settings(json!({
@ -116,7 +186,7 @@ async fn binary_quantize_after_sending_documents() {
})) }))
.await; .await;
snapshot!(code, @"202 Accepted"); snapshot!(code, @"202 Accepted");
server.wait_task(response.uid()).await; server.wait_task(response.uid()).await.succeeded();
// Make sure the documents are binary quantized // Make sure the documents are binary quantized
let (documents, _code) = index let (documents, _code) = index
@ -193,7 +263,7 @@ async fn try_to_disable_binary_quantization() {
})) }))
.await; .await;
snapshot!(code, @"202 Accepted"); snapshot!(code, @"202 Accepted");
server.wait_task(response.uid()).await; server.wait_task(response.uid()).await.succeeded();
let (response, code) = index let (response, code) = index
.update_settings(json!({ .update_settings(json!({
@ -256,7 +326,7 @@ async fn binary_quantize_clear_documents() {
server.wait_task(response.uid()).await.succeeded(); server.wait_task(response.uid()).await.succeeded();
let (value, _code) = index.clear_all_documents().await; let (value, _code) = index.clear_all_documents().await;
index.wait_task(value.uid()).await; index.wait_task(value.uid()).await.succeeded();
// Make sure the documents DB has been cleared // Make sure the documents DB has been cleared
let (documents, _code) = index let (documents, _code) = index