Skip to content

Commit

Permalink
Return complete error for sparse vector validation (qdrant#5536)
Browse files Browse the repository at this point in the history
* Return complete error for sparse vector validation

* remove unecessary path

* update test to show new value
  • Loading branch information
agourlay authored and timvisee committed Dec 9, 2024
1 parent 362a721 commit 83cd887
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
11 changes: 5 additions & 6 deletions lib/api/src/conversions/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,11 @@ impl TryFrom<grpc::Vector> for VectorInternal {
// sparse vector
if let Some(indices) = vector.indices {
return Ok(VectorInternal::Sparse(
sparse::common::sparse_vector::SparseVector::new(indices.data, vector.data)
.map_err(|e| {
Status::invalid_argument(format!(
"Sparse indices does not match sparse vector conditions: {e}"
))
})?,
SparseVector::new(indices.data, vector.data).map_err(|e| {
Status::invalid_argument(format!(
"Sparse indices does not match sparse vector conditions: {e}"
))
})?,
));
}

Expand Down
14 changes: 8 additions & 6 deletions lib/api/src/grpc/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1709,8 +1709,10 @@ pub fn into_named_vector_struct(
Some(indices) => NamedVectorStruct::Sparse(NamedSparseVector {
name: vector_name
.ok_or_else(|| Status::invalid_argument("Sparse vector must have a name"))?,
vector: SparseVector::new(indices.data, vector).map_err(|_| {
Status::invalid_argument("Sparse indices does not match sparse vector conditions")
vector: SparseVector::new(indices.data, vector).map_err(|e| {
Status::invalid_argument(format!(
"Sparse indices does not match sparse vector conditions: {e}"
))
})?,
}),
None => {
Expand Down Expand Up @@ -1957,10 +1959,10 @@ impl TryFrom<SearchPointGroups> for rest::SearchGroupsRequestInternal {

if let Some(sparse_indices) = &search_points.sparse_indices {
validate_sparse_vector_impl(&sparse_indices.data, &search_points.vector).map_err(
|_| {
Status::invalid_argument(
"Sparse indices does not match sparse vector conditions",
)
|e| {
Status::invalid_argument(format!(
"Sparse indices does not match sparse vector conditions: {e}"
))
},
)?;
}
Expand Down
10 changes: 6 additions & 4 deletions lib/collection/src/operations/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,8 +932,10 @@ impl TryFrom<api::grpc::qdrant::SearchPoints> for CoreSearchRequest {
} = value;

if let Some(sparse_indices) = &sparse_indices {
validate_sparse_vector_impl(&sparse_indices.data, &vector).map_err(|_| {
Status::invalid_argument("Sparse indices does not match sparse vector conditions")
validate_sparse_vector_impl(&sparse_indices.data, &vector).map_err(|e| {
Status::invalid_argument(format!(
"Sparse indices does not match sparse vector conditions: {e}"
))
})?;
}

Expand Down Expand Up @@ -1265,9 +1267,9 @@ impl TryFrom<api::grpc::qdrant::VectorExample> for RecommendExample {
match vector.indices {
Some(indices) => {
validate_sparse_vector_impl(&indices.data, &vector.data).map_err(
|_| {
|e| {
Status::invalid_argument(
"Sparse indices does not match sparse vector conditions",
format!("Sparse indices does not match sparse vector conditions: {e}"),
)
},
)?;
Expand Down
2 changes: 1 addition & 1 deletion tests/basic_sparse_grpc_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ response=$(
"limit": 3
}' $QDRANT_HOST qdrant.Points/Search 2>&1
)
if [[ $response != *"Sparse indices does not match sparse vector conditions"* ]]; then
if [[ $response != *"Sparse indices does not match sparse vector conditions: values: Validation error: must be the same length as indices [{}]"* ]]; then
echo Unexpected response, expected validation error: $response
exit 1
fi
Expand Down

0 comments on commit 83cd887

Please sign in to comment.