Skip to content

Commit

Permalink
Added test that checks that store creation throws an exception if the…
Browse files Browse the repository at this point in the history
… index name is invalid. Also added javadoc describing the other tests.
  • Loading branch information
fmeheust committed Jan 6, 2025
1 parent 191cea1 commit c51565d
Showing 1 changed file with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static dev.langchain4j.store.embedding.oracle.CommonTestOperations.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

import java.sql.*;
import java.util.stream.Stream;
Expand All @@ -11,12 +13,18 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;

/**
* Tests which verify all possible configurations of {@link OracleEmbeddingStore.Builder#vectorIndex(CreateOption)}
*/
public class VectorIndexIT {

/**
* Verifies that the index is being create or not depending on the {@link CreateOption}
* @param createOption the CreateOption
* @throws SQLException throws an exception if an unexpected error occurs.
*/
@ParameterizedTest
@EnumSource(CreateOption.class)
public void testCreateOption(CreateOption createOption) throws SQLException {
Expand All @@ -33,6 +41,15 @@ public void testCreateOption(CreateOption createOption) throws SQLException {
}
}

/**
* Verifies that all IVF index arguments are being correcty set on the index.
* @param targetAccuracy the target accuracy
* @param degreeOfParallelism the drgree of parallelism
* @param neighborPartitions the number of neighbor partitions
* @param samplePerPartition the number of samples per partition
* @param minVectorsPerPartition the nminimus number of vectors per partition
* @throws Exception throws an exception if an unexpected error occurs.
*/
@ParameterizedTest
@MethodSource("createIndexArguments")
public void testCreateIndexOnStoreCreation(
Expand Down Expand Up @@ -92,6 +109,11 @@ public void testCreateIndexOnStoreCreation(
}
}

/**
* Verifies that it is possible to create a store with both a JSON index and
* a IVF index. That the vectors are created and the search works.
* @throws SQLException throws an exception if an unexpected error occurs.
*/
@Test
public void testMetadataKeyAndVectorIndex() throws SQLException {
try {
Expand Down Expand Up @@ -128,6 +150,11 @@ public void testMetadataKeyAndVectorIndex() throws SQLException {
}
}

/**
* Verifies that it is possible to create a store with a JSON index and that
* the search works.
* @throws SQLException throws an exception if an unexpected error occurs.
*/
@Test
public void testMetadataKeysIndex() throws SQLException {
try {
Expand Down Expand Up @@ -155,6 +182,59 @@ public void testMetadataKeysIndex() throws SQLException {
}
}

/**
* This tests verifies that creating the EmbeddingStore will fail if the
* index name is invalid (reserved word, unquoted and starting not starting
* by an alphabetic character, too long).
* @param indexName the name of the index
* @throws Exception if an exception other than the expected exception occurs.
*/
@ParameterizedTest
@ValueSource(
strings = {
"CREATE",
"012sdf",
"azertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiopazertyuiop"
})
public void InvalidIndexNameTest(String indexName) throws Exception {
try {
OracleEmbeddingStore.builder()
.dataSource(CommonTestOperations.getDataSource())
.embeddingTable(EmbeddingTable.builder()
.createOption(CreateOption.CREATE_OR_REPLACE)
.name(TABLE_NAME)
.build())
.index(Index.ivfIndexBuilder()
.name(indexName)
.createOption(CreateOption.CREATE_OR_REPLACE)
.build())
.build();
fail("Previous statement should throw a runtime exception");
} catch (RuntimeException runtimeException) {
assertThat(runtimeException.getCause().getClass()).isSameAs(SQLSyntaxErrorException.class);
} finally {
dropTable(TABLE_NAME);
}
try {
OracleEmbeddingStore.builder()
.dataSource(CommonTestOperations.getDataSource())
.embeddingTable(EmbeddingTable.builder()
.createOption(CreateOption.CREATE_OR_REPLACE)
.name(TABLE_NAME)
.build())
.index(Index.jsonIndexBuilder()
.name(indexName)
.createOption(CreateOption.CREATE_OR_REPLACE)
.build())
.build();
fail("Previous statement should throw a runtime exception");
} catch (RuntimeException runtimeException) {
assertThat(runtimeException.getCause().getClass()).isSameAs(SQLSyntaxErrorException.class);
} finally {
dropTable(TABLE_NAME);
}
}

/**
* Queries the USER_INDEXES view to verify that an index has been created or not. This method verifies that the
* index is of the VECTOR type, and that it has the name specified in the JavaDoc of {@link OracleEmbeddingStore}:
Expand Down

0 comments on commit c51565d

Please sign in to comment.