mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-29 16:45:30 +08:00
add more tests and improve the location of the error
This commit is contained in:
parent
1daaed163a
commit
ce08dc509b
@ -375,18 +375,92 @@ async fn user_provided_embeddings_error() {
|
|||||||
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");
|
||||||
let task = index.wait_task(value.uid()).await;
|
let task = index.wait_task(value.uid()).await;
|
||||||
|
snapshot!(task["status"], @r###""succeeded""###);
|
||||||
|
|
||||||
|
let documents =
|
||||||
|
json!({"id": 0, "name": "kefir", "_vectors": { "manual": { "regenerate": false }}});
|
||||||
|
let (value, code) = index.add_documents(documents, None).await;
|
||||||
|
snapshot!(code, @"202 Accepted");
|
||||||
|
let task = index.wait_task(value.uid()).await;
|
||||||
|
snapshot!(task["status"], @r###""succeeded""###);
|
||||||
|
|
||||||
|
let documents = json!({"id": 0, "name": "kefir", "_vectors": { "manual": { "regenerate": false, "embeddings": [0.1, [0.2, 0.3]] }}});
|
||||||
|
let (value, code) = index.add_documents(documents, None).await;
|
||||||
|
snapshot!(code, @"202 Accepted");
|
||||||
|
let task = index.wait_task(value.uid()).await;
|
||||||
snapshot!(task, @r###"
|
snapshot!(task, @r###"
|
||||||
{
|
{
|
||||||
"uid": 8,
|
"uid": 10,
|
||||||
"indexUid": "doggo",
|
"indexUid": "doggo",
|
||||||
"status": "succeeded",
|
"status": "failed",
|
||||||
"type": "documentAdditionOrUpdate",
|
"type": "documentAdditionOrUpdate",
|
||||||
"canceledBy": null,
|
"canceledBy": null,
|
||||||
"details": {
|
"details": {
|
||||||
"receivedDocuments": 1,
|
"receivedDocuments": 1,
|
||||||
"indexedDocuments": 1
|
"indexedDocuments": 0
|
||||||
|
},
|
||||||
|
"error": {
|
||||||
|
"message": "Bad embedder configuration in the document with id: `\"0\"`. Invalid value type at `.manual.embeddings[1]`: expected a number, but found an array: `[0.2,0.3]`",
|
||||||
|
"code": "invalid_vectors_type",
|
||||||
|
"type": "invalid_request",
|
||||||
|
"link": "https://docs.meilisearch.com/errors#invalid_vectors_type"
|
||||||
|
},
|
||||||
|
"duration": "[duration]",
|
||||||
|
"enqueuedAt": "[date]",
|
||||||
|
"startedAt": "[date]",
|
||||||
|
"finishedAt": "[date]"
|
||||||
|
}
|
||||||
|
"###);
|
||||||
|
|
||||||
|
let documents = json!({"id": 0, "name": "kefir", "_vectors": { "manual": { "regenerate": false, "embeddings": [[0.1, 0.2], 0.3] }}});
|
||||||
|
let (value, code) = index.add_documents(documents, None).await;
|
||||||
|
snapshot!(code, @"202 Accepted");
|
||||||
|
let task = index.wait_task(value.uid()).await;
|
||||||
|
snapshot!(task, @r###"
|
||||||
|
{
|
||||||
|
"uid": 11,
|
||||||
|
"indexUid": "doggo",
|
||||||
|
"status": "failed",
|
||||||
|
"type": "documentAdditionOrUpdate",
|
||||||
|
"canceledBy": null,
|
||||||
|
"details": {
|
||||||
|
"receivedDocuments": 1,
|
||||||
|
"indexedDocuments": 0
|
||||||
|
},
|
||||||
|
"error": {
|
||||||
|
"message": "Bad embedder configuration in the document with id: `\"0\"`. Invalid value type at `.manual.embeddings[1]`: expected an array, but found a number: `0.3`",
|
||||||
|
"code": "invalid_vectors_type",
|
||||||
|
"type": "invalid_request",
|
||||||
|
"link": "https://docs.meilisearch.com/errors#invalid_vectors_type"
|
||||||
|
},
|
||||||
|
"duration": "[duration]",
|
||||||
|
"enqueuedAt": "[date]",
|
||||||
|
"startedAt": "[date]",
|
||||||
|
"finishedAt": "[date]"
|
||||||
|
}
|
||||||
|
"###);
|
||||||
|
|
||||||
|
let documents = json!({"id": 0, "name": "kefir", "_vectors": { "manual": { "regenerate": false, "embeddings": [[0.1, true], 0.3] }}});
|
||||||
|
let (value, code) = index.add_documents(documents, None).await;
|
||||||
|
snapshot!(code, @"202 Accepted");
|
||||||
|
let task = index.wait_task(value.uid()).await;
|
||||||
|
snapshot!(task, @r###"
|
||||||
|
{
|
||||||
|
"uid": 12,
|
||||||
|
"indexUid": "doggo",
|
||||||
|
"status": "failed",
|
||||||
|
"type": "documentAdditionOrUpdate",
|
||||||
|
"canceledBy": null,
|
||||||
|
"details": {
|
||||||
|
"receivedDocuments": 1,
|
||||||
|
"indexedDocuments": 0
|
||||||
|
},
|
||||||
|
"error": {
|
||||||
|
"message": "Bad embedder configuration in the document with id: `\"0\"`. Invalid value type at `.manual.embeddings[0][1]`: expected a number, but found a boolean: `true`",
|
||||||
|
"code": "invalid_vectors_type",
|
||||||
|
"type": "invalid_request",
|
||||||
|
"link": "https://docs.meilisearch.com/errors#invalid_vectors_type"
|
||||||
},
|
},
|
||||||
"error": null,
|
|
||||||
"duration": "[duration]",
|
"duration": "[duration]",
|
||||||
"enqueuedAt": "[date]",
|
"enqueuedAt": "[date]",
|
||||||
"startedAt": "[date]",
|
"startedAt": "[date]",
|
||||||
|
@ -258,7 +258,6 @@ impl<E: DeserializeError> Deserr<E> for VectorOrArrayOfVectors {
|
|||||||
deserr::Value::Null => Ok(VectorOrArrayOfVectors { inner: None }),
|
deserr::Value::Null => Ok(VectorOrArrayOfVectors { inner: None }),
|
||||||
deserr::Value::Sequence(seq) => {
|
deserr::Value::Sequence(seq) => {
|
||||||
let mut iter = seq.into_iter();
|
let mut iter = seq.into_iter();
|
||||||
let location = location.push_index(0);
|
|
||||||
match iter.next().map(|v| v.into_value()) {
|
match iter.next().map(|v| v.into_value()) {
|
||||||
None => {
|
None => {
|
||||||
// With the strange way serde serialize the `Either`, we must send the left part
|
// With the strange way serde serialize the `Either`, we must send the left part
|
||||||
@ -266,10 +265,16 @@ impl<E: DeserializeError> Deserr<E> for VectorOrArrayOfVectors {
|
|||||||
Ok(VectorOrArrayOfVectors { inner: Some(either::Either::Left(Vec::new())) })
|
Ok(VectorOrArrayOfVectors { inner: Some(either::Either::Left(Vec::new())) })
|
||||||
}
|
}
|
||||||
Some(val @ deserr::Value::Sequence(_)) => {
|
Some(val @ deserr::Value::Sequence(_)) => {
|
||||||
let first = Embedding::deserialize_from_value(val, location)?;
|
let first = Embedding::deserialize_from_value(val, location.push_index(0))?;
|
||||||
let mut collect = vec![first];
|
let mut collect = vec![first];
|
||||||
let mut tail = iter
|
let mut tail = iter
|
||||||
.map(|v| Embedding::deserialize_from_value(v.into_value(), location))
|
.enumerate()
|
||||||
|
.map(|(i, v)| {
|
||||||
|
Embedding::deserialize_from_value(
|
||||||
|
v.into_value(),
|
||||||
|
location.push_index(i + 1),
|
||||||
|
)
|
||||||
|
})
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
collect.append(&mut tail);
|
collect.append(&mut tail);
|
||||||
|
|
||||||
@ -280,9 +285,15 @@ impl<E: DeserializeError> Deserr<E> for VectorOrArrayOfVectors {
|
|||||||
| val @ deserr::Value::NegativeInteger(_)
|
| val @ deserr::Value::NegativeInteger(_)
|
||||||
| val @ deserr::Value::Float(_),
|
| val @ deserr::Value::Float(_),
|
||||||
) => {
|
) => {
|
||||||
let first = <f32>::deserialize_from_value(val, location)?;
|
let first = <f32>::deserialize_from_value(val, location.push_index(0))?;
|
||||||
let mut embedding = iter
|
let mut embedding = iter
|
||||||
.map(|v| <f32>::deserialize_from_value(v.into_value(), location))
|
.enumerate()
|
||||||
|
.map(|(i, v)| {
|
||||||
|
<f32>::deserialize_from_value(
|
||||||
|
v.into_value(),
|
||||||
|
location.push_index(i + 1),
|
||||||
|
)
|
||||||
|
})
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
embedding.insert(0, first);
|
embedding.insert(0, first);
|
||||||
Ok(VectorOrArrayOfVectors { inner: Some(either::Either::Right(embedding)) })
|
Ok(VectorOrArrayOfVectors { inner: Some(either::Either::Right(embedding)) })
|
||||||
@ -293,7 +304,7 @@ impl<E: DeserializeError> Deserr<E> for VectorOrArrayOfVectors {
|
|||||||
actual: value,
|
actual: value,
|
||||||
accepted: &[deserr::ValueKind::Sequence, deserr::ValueKind::Float],
|
accepted: &[deserr::ValueKind::Sequence, deserr::ValueKind::Float],
|
||||||
},
|
},
|
||||||
location,
|
location.push_index(0),
|
||||||
))),
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user