forked from langchain4j/langchain4j
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(langchain4j-milvus): MilvusEmbeddingStore supports configure req…
…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.
- Loading branch information
Showing
15 changed files
with
750 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...vus/src/main/java/dev/langchain4j/store/embedding/milvus/parameter/BinFlatIndexParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package dev.langchain4j.store.embedding.milvus.parameter; | ||
|
||
import io.milvus.param.IndexType; | ||
|
||
/** | ||
* for more information, see <a href="https://milvus.io/docs/index.md#BIN_FLAT">Index#BIN_FLAT</a> | ||
*/ | ||
public class BinFlatIndexParam extends IndexParam{ | ||
public BinFlatIndexParam() { | ||
super(IndexType.BIN_FLAT); | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static final class Builder { | ||
public Builder() { | ||
} | ||
|
||
public BinFlatIndexParam build() { | ||
return new BinFlatIndexParam(); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
.../src/main/java/dev/langchain4j/store/embedding/milvus/parameter/BinIvfFlatIndexParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package dev.langchain4j.store.embedding.milvus.parameter; | ||
|
||
import io.milvus.param.IndexType; | ||
|
||
import static dev.langchain4j.internal.ValidationUtils.ensureBetween; | ||
|
||
/** | ||
* for more information, see <a href="https://milvus.io/docs/index.md#BIN_IVF_FLAT">Index#BIN_IVF_FLAT</a> | ||
*/ | ||
public class BinIvfFlatIndexParam extends IndexParam { | ||
|
||
/** | ||
* Number of cluster units, Range: [1, 65536] | ||
*/ | ||
private final Integer nlist; | ||
|
||
public BinIvfFlatIndexParam(Integer nlist) { | ||
super(IndexType.BIN_IVF_FLAT); | ||
this.nlist = nlist; | ||
ensureBetween(nlist, 1, 65536, "nlist must be in range [1,65536]"); | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public Integer getNlist() { | ||
return nlist; | ||
} | ||
|
||
|
||
public static final class Builder { | ||
private Integer nlist; | ||
|
||
public Builder() { | ||
} | ||
|
||
public Builder nlist(Integer nlist) { | ||
this.nlist = nlist; | ||
return this; | ||
} | ||
|
||
|
||
public BinIvfFlatIndexParam build() { | ||
return new BinIvfFlatIndexParam(nlist); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...vus/src/main/java/dev/langchain4j/store/embedding/milvus/parameter/DiskannIndexParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package dev.langchain4j.store.embedding.milvus.parameter; | ||
|
||
import io.milvus.param.IndexType; | ||
|
||
/** | ||
* for more information, see <a href="https://milvus.io/docs/disk_index.md#Index-and-search-settings">Disk Index#DISKANN</a> | ||
*/ | ||
public class DiskannIndexParam extends IndexParam { | ||
public DiskannIndexParam() { | ||
super(IndexType.DISKANN); | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static final class Builder { | ||
public Builder() { | ||
} | ||
|
||
public DiskannIndexParam build() { | ||
return new DiskannIndexParam(); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...milvus/src/main/java/dev/langchain4j/store/embedding/milvus/parameter/FlatIndexParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package dev.langchain4j.store.embedding.milvus.parameter; | ||
|
||
import io.milvus.param.IndexType; | ||
|
||
/** | ||
* empty placeholder class | ||
* for more information, see <a href="https://milvus.io/docs/index.md#FLAT">Index#FLAT</a> | ||
*/ | ||
public class FlatIndexParam extends IndexParam { | ||
public FlatIndexParam() { | ||
super(IndexType.FLAT); | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static final class Builder { | ||
public Builder() { | ||
} | ||
|
||
public FlatIndexParam build() { | ||
return new FlatIndexParam(); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
.../src/main/java/dev/langchain4j/store/embedding/milvus/parameter/GpuIvfFlatIndexParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package dev.langchain4j.store.embedding.milvus.parameter; | ||
|
||
import io.milvus.param.IndexType; | ||
|
||
import static dev.langchain4j.internal.ValidationUtils.ensureBetween; | ||
|
||
/** | ||
* for more information, see <a href="https://milvus.io/docs/index-with-gpu.md#Prepare-index-parameters">GPU Index</a> | ||
* parameter same as <a href="https://milvus.io/docs/index.md#IVF_FLAT">Index#IVF_FLAT</a> | ||
*/ | ||
public class GpuIvfFlatIndexParam extends IndexParam { | ||
/** | ||
* Number of cluster units, Range: [1, 65536] | ||
*/ | ||
private final Integer nlist; | ||
|
||
public GpuIvfFlatIndexParam(Integer nlist) { | ||
super(IndexType.GPU_IVF_FLAT); | ||
ensureBetween(nlist, 1, 65536, "nlist must be in range [1,65536]"); | ||
this.nlist = nlist; | ||
} | ||
|
||
public Integer getNlist() { | ||
return nlist; | ||
} | ||
|
||
public static final class Builder { | ||
private Integer nlist; | ||
|
||
public Builder() { | ||
} | ||
|
||
public Builder nlist(Integer nlist) { | ||
this.nlist = nlist; | ||
return this; | ||
} | ||
|
||
public GpuIvfFlatIndexParam build() { | ||
return new GpuIvfFlatIndexParam(nlist); | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...us/src/main/java/dev/langchain4j/store/embedding/milvus/parameter/GpuIvfPqIndexParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package dev.langchain4j.store.embedding.milvus.parameter; | ||
|
||
import io.milvus.param.IndexType; | ||
|
||
import static dev.langchain4j.internal.ValidationUtils.ensureBetween; | ||
import static dev.langchain4j.internal.ValidationUtils.ensureNotNull; | ||
|
||
/** | ||
* for more information, see <a href="https://milvus.io/docs/index-with-gpu.md#Prepare-index-parameters">GPU Index</a> | ||
* parameter same as <a href="https://milvus.io/docs/index.md#IVF_PQ">Index#IVF_PQ</a> | ||
*/ | ||
public class GpuIvfPqIndexParam extends IndexParam { | ||
|
||
/** | ||
* Number of cluster units, Range: [1, 65536] | ||
*/ | ||
private final Integer nlist; | ||
/** | ||
* Number of factors of product quantization, Range: dim mod m == 0 | ||
*/ | ||
private final Integer m; | ||
/** | ||
* [Optional] Number of bits in which each low-dimensional vector is stored. Range: [1, 16], Default: 8 | ||
*/ | ||
private final Integer nbits; | ||
|
||
public GpuIvfPqIndexParam(Integer nlist, Integer m) { | ||
this(nlist, m, 8); | ||
} | ||
|
||
public GpuIvfPqIndexParam(Integer nlist, Integer m, Integer nbits) { | ||
super(IndexType.GPU_IVF_PQ); | ||
ensureBetween(nlist, 1, 65536, "nlist must be between in range [1,65536]"); | ||
ensureNotNull(m, "m must not be null, value range is dim mod m == 0"); | ||
if (nbits != null) { | ||
ensureBetween(nbits, 1, 16, "nbits must be in rnage [1,16]"); | ||
} | ||
this.nlist = nlist; | ||
this.m = m; | ||
this.nbits = nbits; | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public Integer getNlist() { | ||
return nlist; | ||
} | ||
|
||
public Integer getM() { | ||
return m; | ||
} | ||
|
||
public Integer getNbits() { | ||
return nbits; | ||
} | ||
|
||
public static final class Builder { | ||
private Integer nbits; | ||
private Integer m; | ||
private Integer nlist = 8; | ||
|
||
public Builder() { | ||
} | ||
|
||
public Builder nbits(Integer nbits) { | ||
this.nbits = nbits; | ||
return this; | ||
} | ||
|
||
public Builder m(Integer m) { | ||
this.m = m; | ||
return this; | ||
} | ||
|
||
public Builder nlist(Integer nlist) { | ||
this.nlist = nlist; | ||
return this; | ||
} | ||
|
||
public GpuIvfPqIndexParam build() { | ||
return new GpuIvfPqIndexParam(nlist, m, nbits); | ||
} | ||
} | ||
} |
Oops, something went wrong.