Repository navigation
Validate required fields in SearchBuilder and CreateCollectionBuilder - #93
Conversation
Throw a QdrantException with a clear message before the REST call when the collection name or the query vector is missing on search, or when the collection name, vector size or distance is missing on create collection, the same way DeleteBuilder does. Fixes quarkiverse#61
gansheer
left a comment
There was a problem hiding this comment.
Hi!
Thanks for the contribution!
On general nitpick on the test. If I understand correctely validation errors now escape AdminResource as HTTP 500. The new client-side QdrantException is the parent of QdrantApiException, and AdminResource.createCollection catches only the subclass, so PUT /admin/collections/foo?vectorSize=0 now returns 500 (unhandled exception) where it used to return a mapped 4xx. The fix belongs in AdminResource even though this PR doesn't touch it, because the regression is caused by it:
} catch (QdrantApiException e) {
return Response.status(e.getStatusCode()).entity(e.getMessage()).build();
} catch (QdrantException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
}An IT asserting PUT with vectorSize=0 W -> 400 would lock the mapping in, nothing in the suite currently exercises the validation path through HTTP.
| } | ||
|
|
||
| @Test | ||
| void searchWithVectorSucceeds() { |
There was a problem hiding this comment.
I see one issue in this test. The PR is not entirely at fault here but if it can be fixed I would appreciate it.
searchWithVectorSucceeds asserts an accident of the suite. .isEmpty() only holds because nothing ever successfully upserts into test_col; it's carried over from the deleted searchWithoutQueryReturnsEmptyResults, where emptiness was the behavior under test. Any future test that seeds test_col breaks this with a misleading "search returned results" failure. Either we assert only what the name promises (assertThat(results).isNotNull()), or make it self-contained:
@Test
void searchWithVectorSucceeds() {
String id = UUID.randomUUID().toString();
client.createCollection("search_test_col").vectorSize(4).distance("Cosine").execute();
try {
client.upsert("search_test_col")
.point(new PointStruct(id, List.of(1.0f, 2.0f, 3.0f, 4.0f), Map.of()))
.execute();
assertThat(client.search("search_test_col").vector(new float[] { 1.0f, 2.0f, 3.0f, 4.0f }).execute())
.extracting(ScoredPoint::getId).contains(id);
} finally {
client.deleteCollection("search_test_col");
}
}WDYT ?
Note the UUID: current Qdrant (verified on 1.19.2) rejects non-UUID string IDs with 400 "value ... is not a valid point ID". I will create a follow up on that.
|
Thanks @gansheer, both points addressed in the latest push.
Could you take another look when you have a moment? |
|
thanks @inamdarmihir for your contribution ! |
What
SearchBuilder.execute()andCreateCollectionBuilder.execute()now throw aQdrantExceptionwith a clear message before the REST call, matchingDeleteBuilder:Why
A missing required field produced a confusing server-side error, or for search a silently empty result. See #61.
Optional fields (
limit, filter, score threshold) and the set of valid distance values are deliberately not validated, so new Qdrant metrics keep working.How was it tested
Added
ErrorHandlingTestcases indeployment, which already coversDeleteBuilder: 3 for search validation, 4 for create-collection validation, plus a happy path for each builder. The search happy path is self-contained (creates its own collection, upserts a point with a UUID id, asserts it is returned).Added
DocumentResourceTest#testCreateCollectionWithInvalidVectorSizeReturnsBadRequestinintegration-tests/default:PUT /admin/collections/{name}?vectorSize=0returns 400. Without theAdminResourcechange below it fails.mvn -pl deployment -am test -Dtest=ErrorHandlingTestgives 25 run, 7 failures. The 7 failures are exactly the missing-field tests.mvn -B -pl runtime,deployment,integration-tests/default -am verifygives BUILD SUCCESS on JDK 21, with 37 tests passing indeploymentand 9 inintegration-tests/default. The formatter and impsort leave no diff.Notes for the reviewer
QdrantExceptionis the parent ofQdrantApiException, so validation errors would have escaped the integration-testAdminResource.createCollectionas HTTP 500. It now mapsQdrantExceptionto 400 after theQdrantApiExceptioncatch. TodayQdrantExceptionis only thrown by these builder validations, so 400 is accurate; if it later wraps non-client errors, that mapping needs revisiting.searchWithoutQueryReturnsEmptyResults, since it pinned the behaviour this PR changes.Fixes #61
Authored by Mihir Inamdar.