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

Run mvn spotless::apply on main branch. #41

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class IVFIndexBuilder extends IndexBuilder<IVFIndexBuilder> {

private int minVectorsPerPartition = -1;

IVFIndexBuilder() { }
IVFIndexBuilder() {}

/**
* Configures the target accuracy.
Expand All @@ -35,9 +35,9 @@ public class IVFIndexBuilder extends IndexBuilder<IVFIndexBuilder> {
* @throws IllegalArgumentException If the target accuracy not between 1 and 100.
*/
public IVFIndexBuilder targetAccuracy(int targetAccuracy) throws IllegalArgumentException {
ensureBetween(targetAccuracy, 0, 100, "targetAccuracy");
this.targetAccuracy = targetAccuracy;
return this;
ensureBetween(targetAccuracy, 0, 100, "targetAccuracy");
this.targetAccuracy = targetAccuracy;
return this;
}

/**
Expand All @@ -47,9 +47,9 @@ public IVFIndexBuilder targetAccuracy(int targetAccuracy) throws IllegalArgument
* @return This builder.
*/
public IVFIndexBuilder degreeOfParallelism(int degreeOfParallelism) {
ensureGreaterThanZero(degreeOfParallelism, "degreeOfParallelism");
this.degreeOfParallelism = degreeOfParallelism;
return this;
ensureGreaterThanZero(degreeOfParallelism, "degreeOfParallelism");
this.degreeOfParallelism = degreeOfParallelism;
return this;
}

/**
Expand All @@ -65,9 +65,9 @@ public IVFIndexBuilder degreeOfParallelism(int degreeOfParallelism) {
* 10000000, or if the vector type is not IVF.
*/
public IVFIndexBuilder neighborPartitions(int neighborPartitions) throws IllegalArgumentException {
ensureBetween(neighborPartitions, 1, 10000000, "neighborPartitions");
this.neighborPartitions = neighborPartitions;
return this;
ensureBetween(neighborPartitions, 1, 10000000, "neighborPartitions");
this.neighborPartitions = neighborPartitions;
return this;
}

/**
Expand All @@ -88,9 +88,9 @@ public IVFIndexBuilder neighborPartitions(int neighborPartitions) throws Illegal
* @throws IllegalArgumentException If the number of samples per partition is lower than 1.
*/
public IVFIndexBuilder samplePerPartition(int samplePerPartition) throws IllegalArgumentException {
ensureBetween(samplePerPartition, 1, Integer.MAX_VALUE, "samplePerPartition");
this.samplePerPartition = samplePerPartition;
return this;
ensureBetween(samplePerPartition, 1, Integer.MAX_VALUE, "samplePerPartition");
this.samplePerPartition = samplePerPartition;
return this;
}

/**
Expand All @@ -108,66 +108,65 @@ public IVFIndexBuilder samplePerPartition(int samplePerPartition) throws Illegal
* than 0.
*/
public IVFIndexBuilder minVectorsPerPartition(int minVectorsPerPartition) throws IllegalArgumentException {
ensureGreaterThanZero(minVectorsPerPartition, "minVectorsPerPartition");
this.minVectorsPerPartition = minVectorsPerPartition;
return this;
ensureGreaterThanZero(minVectorsPerPartition, "minVectorsPerPartition");
this.minVectorsPerPartition = minVectorsPerPartition;
return this;
}


/**
* {@inheritDoc}
*/
@Override
/**
* {@inheritDoc}
*/
@Override
public Index build() {
return new Index(this);
return new Index(this);
}

/**
* @inheritDoc
*/
@Override
String getCreateIndexStatement(EmbeddingTable embeddingTable) {

return "CREATE VECTOR INDEX " +
(createOption == CreateOption.CREATE_IF_NOT_EXISTS ? "IF NOT EXISTS " : "") +
getIndexName(embeddingTable) +
" ON " + embeddingTable.name() + "( " + embeddingTable.embeddingColumn() + " ) " +
" ORGANIZATION NEIGHBOR PARTITIONS " +
" WITH DISTANCE COSINE " +
(targetAccuracy > 0 ? " WITH TARGET ACCURACY " + targetAccuracy + " " : "") +
(degreeOfParallelism >= 0 ? " PARALLEL " + degreeOfParallelism : "") +
getIndexParameters();
}

/**
* {@inheritDoc}
* <p>
* The index name id generated by concatenating "_VECTOR_INDEX" to the embedding table
* name.
* </p>
* @param embeddingTable The embedding table.
* @return The name of the index.
*/
@Override
String getIndexName(EmbeddingTable embeddingTable) {
if (indexName == null) {
indexName = buildIndexName(embeddingTable.name(), "_VECTOR_INDEX");
/**
* @inheritDoc
*/
@Override
String getCreateIndexStatement(EmbeddingTable embeddingTable) {

return "CREATE VECTOR INDEX " + (createOption == CreateOption.CREATE_IF_NOT_EXISTS ? "IF NOT EXISTS " : "")
+ getIndexName(embeddingTable)
+ " ON "
+ embeddingTable.name() + "( " + embeddingTable.embeddingColumn() + " ) "
+ " ORGANIZATION NEIGHBOR PARTITIONS "
+ " WITH DISTANCE COSINE "
+ (targetAccuracy > 0 ? " WITH TARGET ACCURACY " + targetAccuracy + " " : "")
+ (degreeOfParallelism >= 0 ? " PARALLEL " + degreeOfParallelism : "")
+ getIndexParameters();
}
return indexName;
}

/**
* Generates the PARAMETERS clause of the vector index. Implementation depends on the type of vector index.
* @return A string containing the PARAMETERS clause of the index.
*/
String getIndexParameters() {
if (neighborPartitions == -1 && samplePerPartition == -1 && minVectorsPerPartition == -1) {
return " ";

/**
* {@inheritDoc}
* <p>
* The index name id generated by concatenating "_VECTOR_INDEX" to the embedding table
* name.
* </p>
* @param embeddingTable The embedding table.
* @return The name of the index.
*/
@Override
String getIndexName(EmbeddingTable embeddingTable) {
if (indexName == null) {
indexName = buildIndexName(embeddingTable.name(), "_VECTOR_INDEX");
}
return indexName;
}
return "PARAMETERS ( TYPE IVF" +
(neighborPartitions != -1 ? ", NEIGHBOR PARTITIONS " + neighborPartitions + " " : "") +
(samplePerPartition != -1 ? ", SAMPLES_PER_PARTITION " + samplePerPartition + " " : "") +
(minVectorsPerPartition != -1 ? ", MIN_VECTORS_PER_PARTITION " + minVectorsPerPartition + " " : "") + ")";
}
}

/**
* Generates the PARAMETERS clause of the vector index. Implementation depends on the type of vector index.
* @return A string containing the PARAMETERS clause of the index.
*/
String getIndexParameters() {
if (neighborPartitions == -1 && samplePerPartition == -1 && minVectorsPerPartition == -1) {
return " ";
}
return "PARAMETERS ( TYPE IVF"
+ (neighborPartitions != -1 ? ", NEIGHBOR PARTITIONS " + neighborPartitions + " " : "")
+ (samplePerPartition != -1 ? ", SAMPLES_PER_PARTITION " + samplePerPartition + " " : "")
+ (minVectorsPerPartition != -1 ? ", MIN_VECTORS_PER_PARTITION " + minVectorsPerPartition + " " : "")
+ ")";
}
}
Loading
Loading