Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] langchain4j-milvus throws exception when creating a specified index type that requires some index argument #860

Open
Glarme opened this issue Mar 29, 2024 · 0 comments · May be fixed by #931
Labels
bug Something isn't working P3 Medium priority

Comments

@Glarme
Copy link
Contributor

Glarme commented Mar 29, 2024

Describe the bug

Throws exception when automatically creating a specified index type that requires some index argument

The reason is that MilvusEmbeddingStore does not support the configuration for additional parameters extraParam when it supports custom index types

For example, an IVF_FLAT index requires the parameter nlist, otherwise the following exception will be thrown when the index is creating

nlist out of range: [1, 65536]

Log and Stack trace

17:12:04.198 [main] ERROR io.milvus.client.AbstractMilvusGrpcClient - CreateIndexRequest collectionName:demo, fieldName:vector failed, error code: 65535, reason: nlist out of range: [1, 65536]
17:12:04.200 [main] ERROR io.milvus.client.AbstractMilvusGrpcClient - CreateIndexRequest collectionName:demo, fieldName:vector failed! Exception:{}
    io.milvus.exception.ServerException: nlist out of range: [1, 65536]
    at io.milvus.client.AbstractMilvusGrpcClient.handleResponse(AbstractMilvusGrpcClient.java:347)
    at io.milvus.client.AbstractMilvusGrpcClient.createIndex(AbstractMilvusGrpcClient.java:1207)
    at io.milvus.client.MilvusServiceClient.lambda$createIndex$26(MilvusServiceClient.java:487)
    at io.milvus.client.MilvusServiceClient$$Lambda$9/21201513.call(Unknown Source)
    at io.milvus.client.MilvusServiceClient.retry(MilvusServiceClient.java:285)
    at io.milvus.client.MilvusServiceClient.createIndex(MilvusServiceClient.java:487)
    at dev.langchain4j.store.embedding.milvus.CollectionOperationsExecutor.createIndex(CollectionOperationsExecutor.java:93)
    at dev.langchain4j.store.embedding.milvus.MilvusEmbeddingStore.(MilvusEmbeddingStore.java:91)
    at dev.langchain4j.store.embedding.milvus.MilvusEmbeddingStore$Builder.build(MilvusEmbeddingStore.java:329)
    at MilvusTest.main(MilvusTest.java:18)
Exception in thread "main" dev.langchain4j.store.embedding.milvus.RequestToMilvusFailedException: Request to Milvus DB failed. Response status:'65535'.
    at dev.langchain4j.store.embedding.milvus.CollectionOperationsExecutor.checkResponseNotFailed(CollectionOperationsExecutor.java:132)
    at dev.langchain4j.store.embedding.milvus.CollectionOperationsExecutor.createIndex(CollectionOperationsExecutor.java:94)
    at dev.langchain4j.store.embedding.milvus.MilvusEmbeddingStore.(MilvusEmbeddingStore.java:91)
    at dev.langchain4j.store.embedding.milvus.MilvusEmbeddingStore$Builder.build(MilvusEmbeddingStore.java:329)
    at MilvusTest.main(MilvusTest.java:18)
Caused by: io.milvus.exception.ServerException: nlist out of range: [1, 65536]
    at io.milvus.client.AbstractMilvusGrpcClient.handleResponse(AbstractMilvusGrpcClient.java:347)
    at io.milvus.client.AbstractMilvusGrpcClient.createIndex(AbstractMilvusGrpcClient.java:1207)
    at io.milvus.client.MilvusServiceClient.lambda$createIndex$26(MilvusServiceClient.java:487)
    at io.milvus.client.MilvusServiceClient$$Lambda$9/21201513.call(Unknown Source)
    at io.milvus.client.MilvusServiceClient.retry(MilvusServiceClient.java:285)
    at io.milvus.client.MilvusServiceClient.createIndex(MilvusServiceClient.java:487)
    at dev.langchain4j.store.embedding.milvus.CollectionOperationsExecutor.createIndex(CollectionOperationsExecutor.java:93)
    ... 3 more

To Reproduce

public class MilvusTest {

    public static void main(String[] args) {
        EmbeddingStore<TextSegment> embeddingStore = MilvusEmbeddingStore.builder()
                .host("localhost")
                .collectionName("demo")
                .port(19530)
                .dimension(768)
                .indexType(IndexType.IVF_FLAT)
                .build();

    }
}

Expected behavior

Support users to configure the additional parameter extraParam and others that I haven't listed yet

For example, I create the index directly using the milvus client, which supports parameters such as extraParam and syncMode

    private void _createIndex(String collectionName) {
    CreateIndexParam createIndexParam = CreateIndexParam.newBuilder()
            .withCollectionName(collectionName)
            .withFieldName(MilvusConstant.VECTOR_FIELD)
            .withIndexType(IndexType.IVF_FLAT)
            .withMetricType(MetricType.IP)
            //  the recommended value of nlist is 4 × sqrt(n), where n is the total number of entities in a segment.
            .withExtraParam("{\"nlist\":16384}")
            .withSyncMode(Boolean.FALSE)
            .build();
    R<RpcStatus> response = client.createIndex(createIndexParam);
    checkResponse(response);
    logger.info("create index success:{}", collectionName);
}

Please complete the following information:

  • LangChain4j version: 0.2.8
  • LLM(s) used: none
  • Java version: 8
  • Spring Boot version (if applicable):

Additional context

@Glarme Glarme added the bug Something isn't working label Mar 29, 2024
@langchain4j langchain4j added the P3 Medium priority label Apr 9, 2024
Glarme added a commit to Rnrt/langchain4j that referenced this issue Apr 12, 2024
…uired index parameters

Fix: [langchain4j#860](langchain4j#860)

Added support for configure common custom index parameters

BREAKING CHANGE: The constructor of MilvusEmbeddingStore now require a parameter of type IndexParam.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P3 Medium priority
Projects
None yet
2 participants