-
Notifications
You must be signed in to change notification settings - Fork 0
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
Get and delete embeddings space #20
Changes from all commits
5c6c6ae
0e9f87b
02b0ff6
c235ce0
c7d93ba
ff73e83
a4d2520
b0037b9
0575bbe
f540ff5
934773a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,100 @@ | ||
package com.theagilemonkeys.ellmental.embeddingsspace; | ||
|
||
import com.theagilemonkeys.ellmental.core.schema.Embedding; | ||
import com.theagilemonkeys.ellmental.embeddingsgeneration.EmbeddingsGenerationModel; | ||
import com.theagilemonkeys.ellmental.embeddingsstore.EmbeddingsStore; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.*; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class EmbeddingsSpaceComponentTest { | ||
|
||
// TODO: Use mockito to Mock these | ||
// @Spy | ||
// private final EmbeddingsGenerationModel model; | ||
// @Spy | ||
// private final EmbeddingsStore store; | ||
// @Inject | ||
// private final EmbeddingsSpaceComponent embeddingsSpaceComponent; | ||
@Mock | ||
private EmbeddingsGenerationModel embeddingsGenerationModel; | ||
@Mock | ||
private EmbeddingsStore embeddingsStore; | ||
@InjectMocks | ||
private EmbeddingsSpaceComponent embeddingsSpaceComponent; | ||
@Captor | ||
private ArgumentCaptor<String> sampleTextCaptor; | ||
Comment on lines
+20
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
private final String sampleText = "sample text"; | ||
private final UUID embeddingId = UUID.randomUUID(); | ||
private final Embedding embeddingMock = new Embedding(embeddingId, List.of(1.0, 2.0, 3.0), null); | ||
|
||
@Test | ||
public void testSaveEmbedding() { | ||
when(embeddingsGenerationModel.generateEmbedding(sampleText)).thenReturn(embeddingMock); | ||
|
||
embeddingsSpaceComponent.save(sampleText); | ||
|
||
verify(embeddingsGenerationModel).generateEmbedding(sampleTextCaptor.capture()); | ||
String capturedSampleText = sampleTextCaptor.getValue(); | ||
assertEquals(sampleText, capturedSampleText); | ||
|
||
verify(embeddingsStore).store(embeddingMock); | ||
|
||
verifyNoMoreInteractions(embeddingsGenerationModel, embeddingsStore); | ||
} | ||
|
||
@Test | ||
public void testMostSimilarEmbeddings() { | ||
int limit = 1; | ||
Embedding similarEmbeddingMock = new Embedding(UUID.randomUUID(), List.of(4.0, 5.0, 6.0), null); | ||
|
||
when(embeddingsStore.similaritySearch(embeddingMock, limit)).thenReturn(List.of(similarEmbeddingMock)); | ||
|
||
List<Embedding> embeddings = embeddingsSpaceComponent.mostSimilarEmbeddings(embeddingMock, limit); | ||
|
||
assertEquals(embeddings.get(0), similarEmbeddingMock); | ||
|
||
verifyNoMoreInteractions(embeddingsGenerationModel, embeddingsStore); | ||
} | ||
juanjoman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Test | ||
public void testMostSimilarEmbeddingsWhenUsingString() { | ||
int limit = 1; | ||
Embedding similarEmbeddingMock = new Embedding(UUID.randomUUID(), List.of(4.0, 5.0, 6.0), null); | ||
|
||
when(embeddingsGenerationModel.generateEmbedding(sampleText)).thenReturn(embeddingMock); | ||
when(embeddingsStore.similaritySearch(embeddingMock, limit)).thenReturn(List.of(similarEmbeddingMock)); | ||
|
||
List<Embedding> embeddings = embeddingsSpaceComponent.mostSimilarEmbeddings(sampleText, limit); | ||
|
||
assertEquals(embeddings.get(0), similarEmbeddingMock); | ||
|
||
verify(embeddingsGenerationModel).generateEmbedding(sampleTextCaptor.capture()); | ||
String capturedSampleText = sampleTextCaptor.getValue(); | ||
assertEquals(sampleText, capturedSampleText); | ||
|
||
verifyNoMoreInteractions(embeddingsGenerationModel, embeddingsStore); | ||
} | ||
|
||
@Test | ||
public void testGetEmbedding() { | ||
when(embeddingsStore.get(embeddingId)).thenReturn(embeddingMock); | ||
|
||
Embedding embedding = embeddingsSpaceComponent.get(embeddingId); | ||
|
||
assertEquals(embeddingMock, embedding); | ||
|
||
verifyNoMoreInteractions(embeddingsGenerationModel, embeddingsStore); | ||
} | ||
|
||
@Test | ||
public void todo() { | ||
assertTrue(true); | ||
public void testDeleteEmbedding() { | ||
embeddingsSpaceComponent.delete(embeddingId); | ||
|
||
verify(embeddingsStore).delete(embeddingId); | ||
|
||
verifyNoMoreInteractions(embeddingsGenerationModel, embeddingsStore); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.theagilemonkeys.ellmental.embeddingsstore.pinecone; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
@Data | ||
public class DeleteVectorSchema { | ||
private final List<UUID> ids; | ||
private boolean deleteAll; | ||
private String namespace; | ||
private Map<String, String> filterMetadata; | ||
} | ||
Comment on lines
+9
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ooh I just checked and they are almost the same. In this case @DaTa includes @requiredargsconstructor, which creates a constructor only for |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.theagilemonkeys.ellmental.embeddingsstore.pinecone; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
public class FetchVectorResponseSchema { | ||
private final List<Vector> vectors; | ||
private final String namespace; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.theagilemonkeys.ellmental.embeddingsstore.pinecone; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public class FetchVectorSchema { | ||
private final List<UUID> ids; | ||
private String namespace; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.theagilemonkeys.ellmental.embeddingsstore.pinecone; | ||
|
||
import java.util.List; | ||
|
||
public class SparseValues { | ||
public List<Integer> indices; | ||
public List<Integer> values; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😲