-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #668 from jmartisk/issue-667
Avoid trying to retrieve the default ds if a named one should be used
- Loading branch information
Showing
9 changed files
with
145 additions
and
71 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
35 changes: 18 additions & 17 deletions
35
...vector/deployment/src/test/java/io/quarkiverse/langchain4j/pgvector/test/ColumnsTest.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
37 changes: 19 additions & 18 deletions
37
...eployment/src/test/java/io/quarkiverse/langchain4j/pgvector/test/JSONBMultiIndexTest.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 |
---|---|---|
@@ -1,26 +1,27 @@ | ||
package io.quarkiverse.langchain4j.pgvector.test; | ||
|
||
import java.util.Map; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
import io.quarkus.test.junit.TestProfile; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
@QuarkusTest | ||
@TestProfile(JSONBMultiIndexTest.TestProfile.class) | ||
public class JSONBMultiIndexTest extends LangChain4jPgVectorBaseTest { | ||
|
||
public static class TestProfile implements QuarkusTestProfile { | ||
|
||
@Override | ||
public Map<String, String> getConfigOverrides() { | ||
return Map.of( | ||
"quarkus.langchain4j.pgvector.metadata.storage-mode", "COMBINED_JSONB", | ||
"quarkus.langchain4j.pgvector.metadata.column-definitions", "metadata_b JSONB NULL", | ||
"quarkus.langchain4j.pgvector.metadata.indexes", | ||
"(metadata_b->'key'), (metadata_b->'name'), (metadata_b->'age')", | ||
"quarkus.langchain4j.pgvector.metadata.index-type", "GIN"); | ||
} | ||
} | ||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addAsResource(new StringAsset( | ||
"quarkus.langchain4j.pgvector.dimension=384\n" + | ||
"quarkus.langchain4j.pgvector.drop-table-first=true\n" + | ||
"quarkus.class-loading.parent-first-artifacts=ai.djl.huggingface:tokenizers\n" + | ||
"quarkus.log.category.\"io.quarkiverse.langchain4j.pgvector\".level=DEBUG\n\n" + | ||
"quarkus.langchain4j.pgvector.metadata.storage-mode=COMBINED_JSONB\n" + | ||
"quarkus.langchain4j.pgvector.metadata.column-definitions=metadata_b JSONB NULL\n" + | ||
"quarkus.langchain4j.pgvector.metadata.indexes=(metadata_b->'key'), (metadata_b->'name'), (metadata_b->'age')\n" | ||
+ | ||
"quarkus.langchain4j.pgvector.metadata.index-type=GIN"), | ||
"application.properties")); | ||
|
||
} |
33 changes: 17 additions & 16 deletions
33
...pgvector/deployment/src/test/java/io/quarkiverse/langchain4j/pgvector/test/JSONBTest.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 |
---|---|---|
@@ -1,24 +1,25 @@ | ||
package io.quarkiverse.langchain4j.pgvector.test; | ||
|
||
import java.util.Map; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
import io.quarkus.test.junit.TestProfile; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
@QuarkusTest | ||
@TestProfile(JSONBTest.TestProfile.class) | ||
public class JSONBTest extends LangChain4jPgVectorBaseTest { | ||
|
||
public static class TestProfile implements QuarkusTestProfile { | ||
|
||
@Override | ||
public Map<String, String> getConfigOverrides() { | ||
return Map.of( | ||
"quarkus.langchain4j.pgvector.metadata.storage-mode", "COMBINED_JSONB", | ||
"quarkus.langchain4j.pgvector.metadata.column-definitions", "metadata JSONB NULL", | ||
"quarkus.langchain4j.pgvector.metadata.indexes", "metadata"); | ||
} | ||
} | ||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addAsResource(new StringAsset( | ||
"quarkus.langchain4j.pgvector.dimension=384\n" + | ||
"quarkus.langchain4j.pgvector.drop-table-first=true\n" + | ||
"quarkus.class-loading.parent-first-artifacts=ai.djl.huggingface:tokenizers\n" + | ||
"quarkus.log.category.\"io.quarkiverse.langchain4j.pgvector\".level=DEBUG\n\n" + | ||
"quarkus.langchain4j.pgvector.metadata.storage-mode=COMBINED_JSONB\n" + | ||
"quarkus.langchain4j.pgvector.metadata.column-definitions=metadata JSONB NULL\n" + | ||
"quarkus.langchain4j.pgvector.metadata.indexes=metadata"), | ||
"application.properties")); | ||
|
||
} |
19 changes: 17 additions & 2 deletions
19
.../pgvector/deployment/src/test/java/io/quarkiverse/langchain4j/pgvector/test/JSONTest.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 |
---|---|---|
@@ -1,8 +1,23 @@ | ||
package io.quarkiverse.langchain4j.pgvector.test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
@QuarkusTest | ||
public class JSONTest extends LangChain4jPgVectorBaseTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addAsResource(new StringAsset( | ||
"quarkus.langchain4j.pgvector.dimension=384\n" + | ||
"quarkus.langchain4j.pgvector.drop-table-first=true\n" + | ||
"quarkus.class-loading.parent-first-artifacts=ai.djl.huggingface:tokenizers\n" + | ||
"quarkus.log.category.\"io.quarkiverse.langchain4j.pgvector\".level=DEBUG\n\n"), | ||
"application.properties")); | ||
|
||
// Default behavior | ||
} |
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
60 changes: 60 additions & 0 deletions
60
...oyment/src/test/java/io/quarkiverse/langchain4j/pgvector/test/PgVectorDataSourceTest.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,60 @@ | ||
package io.quarkiverse.langchain4j.pgvector.test; | ||
|
||
import java.sql.Connection; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import dev.langchain4j.data.segment.TextSegment; | ||
import dev.langchain4j.store.embedding.EmbeddingStore; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
/** | ||
* Verify use of a non-default postgresql datasource | ||
*/ | ||
public class PgVectorDataSourceTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addAsResource(new StringAsset( | ||
// DevServicesConfigBuilderCustomizer overrides the image-name only | ||
// for the default DS, so in this case we have to override it manually | ||
"quarkus.datasource.embeddings-ds.devservices.image-name=pgvector/pgvector:pg16\n" + | ||
"quarkus.langchain4j.pgvector.datasource=embeddings-ds\n" + | ||
"quarkus.langchain4j.pgvector.dimension=1536\n" + | ||
"quarkus.datasource.embeddings-ds.db-kind=postgresql\n"), | ||
"application.properties")); | ||
|
||
@io.quarkus.agroal.DataSource("embeddings-ds") | ||
DataSource ds; | ||
|
||
@Inject | ||
EmbeddingStore<TextSegment> embeddingStore; | ||
|
||
@Test | ||
public void verifyThatEmbeddingsTableIsCreated() throws SQLException { | ||
// make sure the store is initialized... | ||
embeddingStore.toString(); | ||
try (Connection connection = ds.getConnection()) { | ||
try (Statement statement = connection.createStatement()) { | ||
try (ResultSet rs = statement.executeQuery( | ||
"SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = 'embeddings')")) { | ||
rs.next(); | ||
Assertions.assertTrue(rs.getBoolean(1)); | ||
} | ||
} | ||
} | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
embedding-stores/pgvector/deployment/src/test/resources/application.properties
This file was deleted.
Oops, something went wrong.
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