Skip to content

Commit

Permalink
fixing IT
Browse files Browse the repository at this point in the history
  • Loading branch information
langchain4j committed May 24, 2024
1 parent e57f246 commit a661050
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import dev.langchain4j.store.embedding.EmbeddingMatch;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.azure.search.AzureAiSearchEmbeddingStore;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
Expand Down Expand Up @@ -48,10 +49,20 @@ class AutoConfigIT {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(AutoConfig.class));

@AfterEach
void afterEach() {
searchIndexClient.deleteIndex(DEFAULT_INDEX_NAME);
try {
Thread.sleep(10_000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

@Test
void should_provide_ai_search_retriever() {

searchIndexClient.deleteIndex(DEFAULT_INDEX_NAME);
// TODO extract in separate tests

contextRunner
.withPropertyValues(
Expand Down Expand Up @@ -148,8 +159,6 @@ void should_provide_ai_search_retriever() {
@EnabledIfEnvironmentVariable(named = "AZURE_SEARCH_RERANKER_AVAILABLE", matches = "true")
void should_provide_ai_search_retriever_with_reranking() {

searchIndexClient.deleteIndex(DEFAULT_INDEX_NAME);

String content = "house";
Query query = Query.from(content);

Expand Down Expand Up @@ -178,8 +187,6 @@ void should_provide_ai_search_retriever_with_reranking() {
@Test
void should_provide_ai_search_embedding_store() {

searchIndexClient.deleteIndex(DEFAULT_INDEX_NAME);

contextRunner
.withPropertyValues(
Properties.PREFIX + ".embedding-store.api-key=" + AZURE_SEARCH_KEY,
Expand All @@ -200,16 +207,12 @@ void should_provide_ai_search_embedding_store() {
String content6 = "chess";
List<String> contents = asList(content1, content2, content3, content4, content5, content6);

Thread.sleep(3000);

for (String content : contents) {
TextSegment textSegment = TextSegment.from(content);
Embedding embedding = embeddingModel.embed(content).content();
embeddingStore.add(embedding, textSegment);
}

Thread.sleep(3000);

Embedding relevantEmbedding = embeddingModel.embed("fruit").content();
List<EmbeddingMatch<TextSegment>> relevant = embeddingStore.findRelevant(relevantEmbedding, 3);
assertThat(relevant).hasSize(3);
Expand Down

0 comments on commit a661050

Please sign in to comment.