Skip to content

Commit

Permalink
Fix Neo4jEmbeddingStoreTest error (langchain4j#368)
Browse files Browse the repository at this point in the history
See
https://github.com/langchain4j/langchain4j/actions/runs/7259989386/job/19778223144


Changed to `MATCH (n:%s) RETURN n ORDER BY n.text` to make tests more
deterministic,
since rarely the sorting of "MATCH (n:%s) RETURN n" is not based on the
order of arrival of the `embeddingModel.embed(..)`.
  • Loading branch information
vga91 authored Dec 19, 2023
1 parent b5c90c0 commit 968bb71
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ void should_add_embedding_with_segment() {
assertThat(match.embedding()).isEqualTo(embedding);
assertThat(match.embedded()).isEqualTo(segment);


checkEntitiesCreated(relevant.size(),
iterator -> {
List<String> otherProps = Collections.singletonList(DEFAULT_TEXT_PROP);
Expand Down Expand Up @@ -264,9 +263,9 @@ void should_add_multiple_embeddings() {
@Test
void should_add_multiple_embeddings_with_segments() {

TextSegment firstSegment = TextSegment.from(randomUUID());
TextSegment firstSegment = TextSegment.from("firstText");
Embedding firstEmbedding = embeddingModel.embed(firstSegment.text()).content();
TextSegment secondSegment = TextSegment.from(randomUUID());
TextSegment secondSegment = TextSegment.from("secondText");
Embedding secondEmbedding = embeddingModel.embed(secondSegment.text()).content();

List<String> ids = embeddingStore.addAll(
Expand Down Expand Up @@ -482,7 +481,10 @@ private void checkEntitiesCreated(int expectedSize, Consumer<Iterator<Node>> nod
}

private void checkEntitiesCreated(int expectedSize, String labelName, Consumer<Iterator<Node>> nodeConsumer) {
String query = String.format("MATCH (n:%s) RETURN n", SchemaNames.sanitize(labelName).get());
String query = "MATCH (n:%s) RETURN n ORDER BY n.%s".formatted(
SchemaNames.sanitize(labelName).get(),
DEFAULT_TEXT_PROP
);

List<Node> n = session.run(query)
.list(i -> i.get("n").asNode());
Expand Down

0 comments on commit 968bb71

Please sign in to comment.