{"record":{"id":"986c89b7455247cf","repo":"spring-projects/spring-ai","slug":"search-failed","errorCode":null,"errorMessage":"Search failed!","messagePattern":"Search failed!","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"vector-stores/spring-ai-milvus-store/src/main/java/org/springframework/ai/vectorstore/milvus/MilvusVectorStore.java","lineNumber":405,"sourceCode":"\t\t\t.withFloatVectors(List.of(EmbeddingUtils.toList(embedding)))\n\t\t\t.withVectorFieldName(this.embeddingFieldName);\n\n\t\tif (StringUtils.hasText(nativeFilterExpressions)) {\n\t\t\tsearchParamBuilder.withExpr(nativeFilterExpressions);\n\t\t}\n\n\t\tif (StringUtils.hasText(this.partitionName)) {\n\t\t\tsearchParamBuilder.addPartitionName(this.partitionName);\n\t\t}\n\n\t\tif (StringUtils.hasText(searchParamsJson)) {\n\t\t\tsearchParamBuilder.withParams(searchParamsJson);\n\t\t}\n\n\t\tR<SearchResults> respSearch = this.milvusClient.search(searchParamBuilder.build());\n\n\t\tif (respSearch.getException() != null) {\n\t\t\tthrow new RuntimeException(\"Search failed!\", respSearch.getException());\n\t\t}\n\n\t\tSearchResultsWrapper wrapperSearch = new SearchResultsWrapper(respSearch.getData().getResults());\n\n\t\treturn wrapperSearch.getRowRecords(0)\n\t\t\t.stream()\n\t\t\t.filter(rowRecord -> getResultSimilarity(rowRecord) >= request.getSimilarityThreshold())\n\t\t\t.map(rowRecord -> {\n\t\t\t\tString docId = String.valueOf(rowRecord.get(this.idFieldName));\n\t\t\t\tString content = (String) rowRecord.get(this.contentFieldName);\n\t\t\t\tJsonObject metadata = new JsonObject();\n\t\t\t\ttry {\n\t\t\t\t\tmetadata = (JsonObject) rowRecord.get(this.metadataFieldName);\n\t\t\t\t\tif (metadata != null) {\n\t\t\t\t\t\t// inject the distance into the metadata.\n\t\t\t\t\t\tmetadata.addProperty(DocumentMetadata.DISTANCE.value(), 1 - getResultSimilarity(rowRecord));\n\t\t\t\t\t}\n\t\t\t\t}","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/vector-stores/spring-ai-milvus-store/src/main/java/org/springframework/ai/vectorstore/milvus/MilvusVectorStore.java#L387-L423","documentation":"doSimilaritySearch checks the R<SearchResults> response from the Milvus client and throws a plain RuntimeException(\"Search failed!\") when respSearch.getException() is non-null. The Milvus server rejected or failed the similarity search RPC; the original exception is the cause.","triggerScenarios":"Calling similaritySearch(SearchRequest) when the Milvus search RPC returns an error status: collection not loaded, invalid search params (nprobe/ef), wrong embedding dimension, or connectivity failure.","commonSituations":"Query embedding dimension differs from the collection's index dimension; topK too large; search params JSON invalid; Milvus collection dropped or not loaded after restart.","solutions":["Read the cause exception to get the exact Milvus status/error.","Confirm the query embedding dimension matches the collection's embedding field dimension.","Load the collection (milvusClient.loadCollection) before searching.","Check the search params JSON (e.g. nprobe) is valid for the configured index type.","Verify Milvus server connectivity and collection existence."],"exampleFix":"// before\nSearchRequest request = SearchRequest.builder().query(\"...\").topK(10000).build();\n// after\nSearchRequest request = SearchRequest.builder().query(\"...\").topK(100).build(); // keep topK within server limits","handlingStrategy":"retry","validationCode":"// verify collection is loaded and dimensions match before searching\nString dims = embeddingModel.dimensions(); // must equal the collection's embedding field dimension\n// also confirm collection exists:\nmilvusClient.hasCollection(HasCollectionParam.newBuilder().withCollectionName(collectionName).build());","typeGuard":null,"tryCatchPattern":"try {\n    List<Document> docs = vectorStore.similaritySearch(SearchRequest.builder().query(q).topK(5).build());\n} catch (RuntimeException e) {\n    logger.error(\"Milvus search failed: {}\", e.getCause() != null ? e.getCause().getMessage() : e.getMessage(), e);\n    // optionally retry once after verifying collection load state\n}","preventionTips":["Always load the collection before searching after server restarts.","Match embedding model dimension to the collection index dimension.","Keep topK and search params within server limits for your index type."],"tags":["milvus","vector-store","similarity-search","rpc"],"backgroundTag":"database-query-failed","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}