fix the thread safety issue in InMemoryEmbeddingStore. (#351): making sure it deserializes into thread safe list
This commit is contained in:
parent
f1575a9a65
commit
42d5ef9c9e
|
@ -67,7 +67,7 @@ public class InMemoryEmbeddingStore<Embedded> implements EmbeddingStore<Embedded
|
|||
}
|
||||
}
|
||||
|
||||
private final List<Entry<Embedded>> entries = new CopyOnWriteArrayList<>();
|
||||
final CopyOnWriteArrayList<Entry<Embedded>> entries = new CopyOnWriteArrayList<>();
|
||||
|
||||
@Override
|
||||
public String add(Embedding embedding) {
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.junit.jupiter.api.io.TempDir;
|
|||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import static dev.langchain4j.internal.Utils.randomUUID;
|
||||
import static java.util.Arrays.asList;
|
||||
|
@ -233,6 +234,7 @@ class InMemoryEmbeddingStoreTest {
|
|||
InMemoryEmbeddingStore<TextSegment> deserializedEmbeddingStore = InMemoryEmbeddingStore.fromJson(json);
|
||||
|
||||
assertThat(deserializedEmbeddingStore).isEqualTo(originalEmbeddingStore);
|
||||
assertThat(deserializedEmbeddingStore.entries).isInstanceOf(CopyOnWriteArrayList.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -245,6 +247,7 @@ class InMemoryEmbeddingStoreTest {
|
|||
InMemoryEmbeddingStore<TextSegment> deserializedEmbeddingStore = InMemoryEmbeddingStore.fromFile(filePath);
|
||||
|
||||
assertThat(deserializedEmbeddingStore).isEqualTo(originalEmbeddingStore);
|
||||
assertThat(deserializedEmbeddingStore.entries).isInstanceOf(CopyOnWriteArrayList.class);
|
||||
}
|
||||
|
||||
private InMemoryEmbeddingStore<TextSegment> createEmbeddingStore() {
|
||||
|
|
Loading…
Reference in New Issue