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

Remove deprecated EmbeddingStore.findRelevant API #121

Merged
merged 1 commit into from
Mar 21, 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 @@ -15,6 +15,7 @@
import dev.langchain4j.rag.content.retriever.azure.search.AzureAiSearchQueryType;
import dev.langchain4j.rag.query.Query;
import dev.langchain4j.store.embedding.EmbeddingMatch;
import dev.langchain4j.store.embedding.EmbeddingSearchRequest;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.azure.search.AzureAiSearchEmbeddingStore;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -237,8 +238,12 @@ void should_provide_ai_search_embedding_store() {
embeddingStore.add(embedding, textSegment);
}

Embedding relevantEmbedding = embeddingModel.embed("fruit").content();
List<EmbeddingMatch<TextSegment>> relevant = embeddingStore.findRelevant(relevantEmbedding, 3);
EmbeddingSearchRequest searchRequest = EmbeddingSearchRequest.builder()
.queryEmbedding(embeddingModel.embed("fruit").content())
.maxResults(3)
.build();

List<EmbeddingMatch<TextSegment>> relevant = embeddingStore.search(searchRequest).matches();
assertThat(relevant).hasSize(3);
// TODO uncomment after https://github.com/langchain4j/langchain4j/issues/1617 is closed
// assertThat(relevant.get(0).embedding()).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ void should_provide_embedding_store_without_embedding_model() {

awaitUntilPersisted(context);

List<EmbeddingMatch<TextSegment>> relevant = embeddingStore.findRelevant(embedding, 10);
EmbeddingSearchRequest searchRequest = EmbeddingSearchRequest.builder()
.queryEmbedding(embedding)
.maxResults(10)
.build();
List<EmbeddingMatch<TextSegment>> relevant = embeddingStore.search(searchRequest).matches();
assertThat(relevant).hasSize(1);

EmbeddingMatch<TextSegment> match = relevant.get(0);
Expand Down Expand Up @@ -90,23 +94,15 @@ void should_provide_embedding_store_with_embedding_model() {

awaitUntilPersisted(context);

List<EmbeddingMatch<TextSegment>> relevant = embeddingStore.findRelevant(embedding, 10);
assertThat(relevant).hasSize(1);

EmbeddingMatch<TextSegment> match = relevant.get(0);
assertThat(match.score()).isCloseTo(1, withPercentage(1));
assertThat(match.embeddingId()).isEqualTo(id);
assertThat(match.embedding()).isEqualTo(embedding);
assertThat(match.embedded()).isEqualTo(segment);

// New API
EmbeddingSearchResult<TextSegment> searchResult = embeddingStore.search(EmbeddingSearchRequest.builder()
EmbeddingSearchRequest searchRequest = EmbeddingSearchRequest.builder()
.queryEmbedding(embedding)
.maxResults(10)
.build());
.build();

List<EmbeddingMatch<TextSegment>> matches = embeddingStore.search(searchRequest).matches();
assertThat(matches).hasSize(1);

assertThat(searchResult.matches()).hasSize(1);
match = searchResult.matches().get(0);
EmbeddingMatch<TextSegment> match = matches.get(0);
assertThat(match.score()).isCloseTo(1, withPercentage(1));
assertThat(match.embeddingId()).isEqualTo(id);
assertThat(match.embedding()).isEqualTo(embedding);
Expand Down
Loading