Skip to content

Conversation

@dev-jonghoonpark
Copy link
Contributor

@dev-jonghoonpark dev-jonghoonpark commented Jun 28, 2025

changes

improve schema initialization logic

In the current logic, since createCollection is executed without following it up with createIndex, the following error occurs during describeIndex:

20:36:07.664 [main] ERROR io.milvus.client.AbstractMilvusGrpcClient -- DescribeIndexRequest collectionName:test_vector_store_custom_fields, indexName: failed! Exception:{}
io.milvus.exception.ServerException: index not found[collection=test_vector_store_custom_fields]
	at io.milvus.client.AbstractMilvusGrpcClient.handleResponse(AbstractMilvusGrpcClient.java:399)
	at io.milvus.client.AbstractMilvusGrpcClient.describeIndex(AbstractMilvusGrpcClient.java:1423)
	at io.milvus.client.MilvusServiceClient.lambda$describeIndex$32(MilvusServiceClient.java:611)
	at io.milvus.client.MilvusServiceClient.retry(MilvusServiceClient.java:326)
	at io.milvus.client.MilvusServiceClient.describeIndex(MilvusServiceClient.java:611)
	at org.springframework.ai.vectorstore.milvus.MilvusVectorStore.createCollection(MilvusVectorStore.java:449)

However, it is natural for an index to not exist immediately after createCollection.
Thus, the logic was modified to attempt createIndex right after createCollection.

This prevents unnecessary error logs from being recorded.

current example log: https://github.com/spring-projects/spring-ai/actions/runs/15934060747/job/44949781008#step:7:10851

update deprecated code

addFieldType has been deprecated.
It is recommended to use withSchema instead for adding field types, so the implementation has been updated accordingly.

@sobychacko
Copy link
Contributor

@dev-jonghoonpark, could you verify these changes via a test?

@dev-jonghoonpark dev-jonghoonpark force-pushed the update-milvus-create-collection branch from a7971a7 to 81efe0a Compare July 1, 2025 23:44
@dev-jonghoonpark dev-jonghoonpark force-pushed the update-milvus-create-collection branch from 81efe0a to 1f605cc Compare July 1, 2025 23:46
@dev-jonghoonpark
Copy link
Contributor Author

dev-jonghoonpark commented Jul 1, 2025

@sobychacko

Thank you for the feedback.

I have added test using the fact that no logs are output when the operation is successful.

Before applying the PR, errors occur, so the tests fail.
After applying the PR, no errors occur, so the tests pass.


For reference, these logs are not output by Spring AI but rather by the Milvus client internally. The errors are only logged and not thrown.

Due to this, I adopted a validation method based on checking the logs.

AbstractMilvusGrpcClient.java :

} catch (Exception e) {
    logError("{} failed! Exception:{}", title, e);
    return R.failed(e);
}

@sobychacko
Copy link
Contributor

@dev-jonghoonpark What did you mean by the following?

However, it is natural for an index to not exist immediately after createCollection.

How about a more straightforward approach to fix this issue? For example, what if you add the initial describeIndex call to a try/catch block, and then if it causes an exception and the index data is null, create the index? That way, you can avoid the subsequent index creation call (from if (indexDescriptionResponse.getData() == null) {...}).

Here is what I am thinking.

if (!isDatabaseCollectionExists()) {
			createCollection(this.databaseName, this.collectionName, this.idFieldName, this.isAutoId,
					this.contentFieldName, this.metadataFieldName, this.embeddingFieldName);
		}

             try {

		R<DescribeIndexResponse> indexDescriptionResponse = this.milvusClient
			.describeIndex(DescribeIndexParam.newBuilder()
				.withDatabaseName(this.databaseName)
				.withCollectionName(this.collectionName)
				.build());
              }
              catch (Exception e) {
                     // if the index is null, then create the index.
              }

             //At this point, index must be created. you can add some assert of something similar to verify that. 

What do you think about that?

Also, the LogAppender maybe a bit too much for this test. Why don't you simply assert on the existence of the index and no exception thrown etc?

Thanks!

@dev-jonghoonpark
Copy link
Contributor Author

dev-jonghoonpark commented Jul 2, 2025

@sobychacko

The current schema initialization logic works without any issues.
However, I aimed to improve it by eliminating unnecessary log outputs.

As mentioned in the comments, the logs are generated not by Spring AI but by the internal file AbstractMilvusGrpcClient.java in the Milvus client, and they are output without being thrown.

Therefore, even if describeIndex is wrapped in a try-catch block, unnecessary logs will still be output.

Whether describeIndex method succeeds or fails, an R<DescribeIndexResponse> is returned.
The returned result is then checked to determine whether it contains data or an exception.

public class R<T> {
    private Exception exception;
    private Integer status;
    private T data;

@dev-jonghoonpark
Copy link
Contributor Author

dev-jonghoonpark commented Jul 2, 2025

What did you mean by the following?

However, it is natural for an index to not exist immediately after createCollection.

A collection does not have an index immediately after it is created.

Therefore, after calling

createCollection(this.databaseName, this.collectionName, this.idFieldName, this.isAutoId,

I added

createIndex(this.databaseName, this.collectionName, this.embeddingFieldName, this.indexType,

to create the index.

@sobychacko sobychacko modified the milestones: 1.1x, 1.1.x Jul 2, 2025
@sobychacko sobychacko merged commit 5c9891c into spring-projects:main Jul 2, 2025
2 checks passed
spring-builds pushed a commit that referenced this pull request Jul 2, 2025
…lvus vectorstore (#3705)

Fixes #3705

Signed-off-by: jonghoon park <[email protected]>
(cherry picked from commit 5c9891c)
scionaltera pushed a commit to scionaltera/spring-ai that referenced this pull request Sep 3, 2025
…lvus vectorstore (spring-projects#3705)

Fixes spring-projects#3705

Auto-cherry-pick to 1.0.x

Signed-off-by: jonghoon park <[email protected]>
chedim pushed a commit to couchbaselabs/spring-ai that referenced this pull request Sep 19, 2025
…lvus vectorstore (spring-projects#3705)

Fixes spring-projects#3705

Auto-cherry-pick to 1.0.x

Signed-off-by: jonghoon park <[email protected]>
Willam2004 pushed a commit to Willam2004/spring-ai that referenced this pull request Oct 11, 2025
…lvus vectorstore (spring-projects#3705)

Fixes spring-projects#3705

Auto-cherry-pick to 1.0.x

Signed-off-by: jonghoon park <[email protected]>
Signed-off-by: 家娃 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants