From c51565df37f7823d3f5c010bf2e8ad347582bf09 Mon Sep 17 00:00:00 2001 From: Fernanda Meheust Date: Mon, 6 Jan 2025 15:19:38 +0100 Subject: [PATCH] Added test that checks that store creation throws an exception if the index name is invalid. Also added javadoc describing the other tests. --- .../store/embedding/oracle/VectorIndexIT.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/langchain4j-oracle/src/test/java/dev/langchain4j/store/embedding/oracle/VectorIndexIT.java b/langchain4j-oracle/src/test/java/dev/langchain4j/store/embedding/oracle/VectorIndexIT.java index 78bde10dabd..67521aa3f68 100644 --- a/langchain4j-oracle/src/test/java/dev/langchain4j/store/embedding/oracle/VectorIndexIT.java +++ b/langchain4j-oracle/src/test/java/dev/langchain4j/store/embedding/oracle/VectorIndexIT.java @@ -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; @@ -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 { @@ -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( @@ -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 { @@ -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 { @@ -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}: