|
6 | 6 | using GraphRag.Config.Errors; |
7 | 7 | using GraphRag.Config.Models; |
8 | 8 | using GraphRag.Llm.Config; |
| 9 | +using GraphRag.Llm.Types; |
| 10 | +using GraphRag.Vectors; |
9 | 11 |
|
10 | 12 | namespace GraphRag.Tests.Unit.Config; |
11 | 13 |
|
@@ -133,4 +135,57 @@ public void Workflows_CanBeSet() |
133 | 135 |
|
134 | 136 | config.Workflows.Should().BeEquivalentTo(workflows); |
135 | 137 | } |
| 138 | + |
| 139 | + [Fact] |
| 140 | + public void SyncVectorStoreDimensions_UpdatesVectorStoreAndSchema_ForConfiguredEmbeddingModel() |
| 141 | + { |
| 142 | + var config = new GraphRagConfig |
| 143 | + { |
| 144 | + EmbedText = new EmbedTextConfig { EmbeddingModelId = "embed-model" }, |
| 145 | + VectorStore = new VectorStoreConfig |
| 146 | + { |
| 147 | + Type = "azure_ai_search", |
| 148 | + VectorSize = 3072, |
| 149 | + IndexSchema = new IndexSchema { IndexName = "entities", VectorSize = 3072 }, |
| 150 | + }, |
| 151 | + }; |
| 152 | + var response = new LlmEmbeddingResponse([[1.0f, 2.0f, 3.0f]]); |
| 153 | + |
| 154 | + var result = config.SyncVectorStoreDimensions("embed-model", response); |
| 155 | + |
| 156 | + result.Should().NotBeSameAs(config); |
| 157 | + result.VectorStore.VectorSize.Should().Be(3); |
| 158 | + result.VectorStore.IndexSchema.Should().NotBeNull(); |
| 159 | + result.VectorStore.IndexSchema!.VectorSize.Should().Be(3); |
| 160 | + config.VectorStore.VectorSize.Should().Be(3072); |
| 161 | + config.VectorStore.IndexSchema!.VectorSize.Should().Be(3072); |
| 162 | + } |
| 163 | + |
| 164 | + [Fact] |
| 165 | + public void SyncVectorStoreDimensions_ReturnsSameConfig_WhenEmbeddingModelDoesNotMatch() |
| 166 | + { |
| 167 | + var config = new GraphRagConfig |
| 168 | + { |
| 169 | + EmbedText = new EmbedTextConfig { EmbeddingModelId = "embed-model" }, |
| 170 | + }; |
| 171 | + var response = new LlmEmbeddingResponse([[1.0f, 2.0f, 3.0f]]); |
| 172 | + |
| 173 | + var result = config.SyncVectorStoreDimensions("different-model", response); |
| 174 | + |
| 175 | + result.Should().BeSameAs(config); |
| 176 | + } |
| 177 | + |
| 178 | + [Fact] |
| 179 | + public void SyncVectorStoreDimensions_ReturnsSameConfig_WhenResponseIsEmpty() |
| 180 | + { |
| 181 | + var config = new GraphRagConfig |
| 182 | + { |
| 183 | + EmbedText = new EmbedTextConfig { EmbeddingModelId = "embed-model" }, |
| 184 | + }; |
| 185 | + var response = new LlmEmbeddingResponse([]); |
| 186 | + |
| 187 | + var result = config.SyncVectorStoreDimensions("embed-model", response); |
| 188 | + |
| 189 | + result.Should().BeSameAs(config); |
| 190 | + } |
136 | 191 | } |
0 commit comments