mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-27 08:41:00 +00:00
Add a complex value test
This commit is contained in:
@ -30,6 +30,7 @@ pub async fn init_fragments_index() -> (Server<Owned>, String, crate::common::Va
|
|||||||
("dustin", [-0.5, 0.5, 0.0]),
|
("dustin", [-0.5, 0.5, 0.0]),
|
||||||
("bulldog", [0.0, 0.0, 1.0]),
|
("bulldog", [0.0, 0.0, 1.0]),
|
||||||
("labrador", [0.0, 0.0, -1.0]),
|
("labrador", [0.0, 0.0, -1.0]),
|
||||||
|
("{", [-9999.0, -9999.0, -9999.0]), // That wouldn't be nice
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect();
|
.collect();
|
||||||
@ -110,8 +111,6 @@ pub async fn init_fragments_index() -> (Server<Owned>, String, crate::common::Va
|
|||||||
|
|
||||||
// TODO: document fragment replaced
|
// TODO: document fragment replaced
|
||||||
|
|
||||||
// TODO: complex value
|
|
||||||
|
|
||||||
// TODO: swapping fragments
|
// TODO: swapping fragments
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
@ -1364,3 +1363,186 @@ async fn multiple_embedders() {
|
|||||||
snapshot!(code, @"200 OK");
|
snapshot!(code, @"200 OK");
|
||||||
snapshot!(json_string!(documents), @r"");
|
snapshot!(json_string!(documents), @r"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn complex_fragment() {
|
||||||
|
let (server, uid, mut settings) = init_fragments_index().await;
|
||||||
|
let index = server.index(uid);
|
||||||
|
|
||||||
|
settings["embedders"]["rest"]["indexingFragments"].as_object_mut().unwrap().insert(
|
||||||
|
String::from("complex"),
|
||||||
|
serde_json::json!({
|
||||||
|
"value": {
|
||||||
|
"breed": "{{ doc.breed }}",
|
||||||
|
"breeds": [
|
||||||
|
"{{ doc.breed }}",
|
||||||
|
{
|
||||||
|
"breed": "{{ doc.breed }}",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
let (response, code) = index.update_settings(settings).await;
|
||||||
|
snapshot!(code, @"202 Accepted");
|
||||||
|
let task = server.wait_task(response.uid()).await;
|
||||||
|
snapshot!(task, @r#"
|
||||||
|
{
|
||||||
|
"uid": "[uid]",
|
||||||
|
"batchUid": "[batch_uid]",
|
||||||
|
"indexUid": "[uuid]",
|
||||||
|
"status": "succeeded",
|
||||||
|
"type": "settingsUpdate",
|
||||||
|
"canceledBy": null,
|
||||||
|
"details": {
|
||||||
|
"embedders": {
|
||||||
|
"rest": {
|
||||||
|
"source": "rest",
|
||||||
|
"dimensions": 3,
|
||||||
|
"url": "[url]",
|
||||||
|
"indexingFragments": {
|
||||||
|
"basic": {
|
||||||
|
"value": "{{ doc.name }} is a dog"
|
||||||
|
},
|
||||||
|
"complex": {
|
||||||
|
"value": {
|
||||||
|
"breed": "{{ doc.breed }}",
|
||||||
|
"breeds": [
|
||||||
|
"{{ doc.breed }}",
|
||||||
|
{
|
||||||
|
"breed": "{{ doc.breed }}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"withBreed": {
|
||||||
|
"value": "{{ doc.name }} is a {{ doc.breed }}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"searchFragments": {
|
||||||
|
"justBreed": {
|
||||||
|
"value": "It's a {{ media.breed }}"
|
||||||
|
},
|
||||||
|
"justName": {
|
||||||
|
"value": "{{ media.name }} is a dog"
|
||||||
|
},
|
||||||
|
"query": {
|
||||||
|
"value": "Some pre-prompt for query {{ q }}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"request": "{{fragment}}",
|
||||||
|
"response": {
|
||||||
|
"data": "{{embedding}}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"error": null,
|
||||||
|
"duration": "[duration]",
|
||||||
|
"enqueuedAt": "[date]",
|
||||||
|
"startedAt": "[date]",
|
||||||
|
"finishedAt": "[date]"
|
||||||
|
}
|
||||||
|
"#);
|
||||||
|
|
||||||
|
let (documents, code) = index
|
||||||
|
.get_all_documents(GetAllDocumentsOptions { retrieve_vectors: true, ..Default::default() })
|
||||||
|
.await;
|
||||||
|
snapshot!(code, @"200 OK");
|
||||||
|
snapshot!(json_string!(documents), @r#"
|
||||||
|
{
|
||||||
|
"results": [
|
||||||
|
{
|
||||||
|
"id": 0,
|
||||||
|
"name": "kefir",
|
||||||
|
"_vectors": {
|
||||||
|
"rest": {
|
||||||
|
"embeddings": [
|
||||||
|
[
|
||||||
|
0.5,
|
||||||
|
-0.5,
|
||||||
|
0.0
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"regenerate": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "echo",
|
||||||
|
"_vectors": {
|
||||||
|
"rest": {
|
||||||
|
"embeddings": [
|
||||||
|
[
|
||||||
|
1.0,
|
||||||
|
1.0,
|
||||||
|
1.0
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"regenerate": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "intel",
|
||||||
|
"breed": "labrador",
|
||||||
|
"_vectors": {
|
||||||
|
"rest": {
|
||||||
|
"embeddings": [
|
||||||
|
[
|
||||||
|
1.0,
|
||||||
|
1.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
1.0,
|
||||||
|
1.0,
|
||||||
|
-1.0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
-1.0
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"regenerate": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"name": "dustin",
|
||||||
|
"breed": "bulldog",
|
||||||
|
"_vectors": {
|
||||||
|
"rest": {
|
||||||
|
"embeddings": [
|
||||||
|
[
|
||||||
|
-0.5,
|
||||||
|
0.5,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
-0.5,
|
||||||
|
0.5,
|
||||||
|
1.0
|
||||||
|
],
|
||||||
|
[
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
1.0
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"regenerate": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"offset": 0,
|
||||||
|
"limit": 20,
|
||||||
|
"total": 4
|
||||||
|
}
|
||||||
|
"#);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user