|
1 | 1 | package vectorstore |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
4 | 5 | "context" |
5 | 6 | "testing" |
6 | 7 |
|
7 | 8 | "github.com/stretchr/testify/assert" |
| 9 | + "github.com/stretchr/testify/require" |
8 | 10 |
|
9 | 11 | "github.com/hupe1980/golc/schema" |
10 | 12 | ) |
@@ -52,6 +54,31 @@ func TestInMemory(t *testing.T) { |
52 | 54 | assert.Equal(t, expectedDocuments[i].PageContent, doc.PageContent) |
53 | 55 | } |
54 | 56 | }) |
| 57 | + |
| 58 | + t.Run("SaveAndLoad", func(t *testing.T) { |
| 59 | + originalData := []InMemoryItem{ |
| 60 | + {Content: "item1", Vector: []float32{1.0, 2.0, 3.0}, Metadata: map[string]any{"key1": "value1"}}, |
| 61 | + {Content: "item2", Vector: []float32{4.0, 5.0, 6.0}, Metadata: map[string]any{"key2": "value2"}}, |
| 62 | + } |
| 63 | + |
| 64 | + // Create an InMemory instance with the original data |
| 65 | + vsOriginal := &InMemory{data: originalData} |
| 66 | + |
| 67 | + // Serialize the original data |
| 68 | + var buf bytes.Buffer |
| 69 | + err := vsOriginal.Save(&buf) |
| 70 | + require.NoError(t, err, "Failed to save data") |
| 71 | + |
| 72 | + // Create a new InMemory instance |
| 73 | + vsLoaded := &InMemory{} |
| 74 | + |
| 75 | + // Load the serialized data |
| 76 | + err = vsLoaded.Load(&buf) |
| 77 | + require.NoError(t, err, "Failed to load data") |
| 78 | + |
| 79 | + // Check if the loaded data matches the original data |
| 80 | + assert.Equal(t, originalData, vsLoaded.data, "Loaded data does not match original data") |
| 81 | + }) |
55 | 82 | } |
56 | 83 |
|
57 | 84 | // mockEmbedder implements the schema.Embedder interface for testing purposes. |
|
0 commit comments