Implementation:Microsoft Semantic kernel HuggingFace Embeddings TestData
| Knowledge Sources | |
|---|---|
| Domains | HuggingFace, Embeddings, Unit_Testing, Test_Data, Feature_Extraction |
| Last Updated | 2026-02-11 00:00 GMT |
Overview
Concrete mock HuggingFace feature extraction embeddings API response JSON file used in unit tests, provided by the Connectors.HuggingFace.UnitTests project.
Description
embeddings_test_response_feature_extraction.json is a test fixture file containing a mock response from the HuggingFace Inference API for the feature extraction (embeddings) task. At 1028 lines, the file consists of a JSON array of arrays, where each inner array contains floating-point numbers representing an embedding vector. This format matches the HuggingFace feature extraction API response schema, which returns raw nested arrays without additional metadata wrappers (unlike the Google or MistralAI APIs that include envelope objects with id, object, or embeddings keys).
The embedding values are typical normalized float32 numbers (e.g., 0.04324166476726532, -0.02454185113310814) representing dense vector representations from transformer-based models.
This file is consumed by both HuggingFaceEmbeddingGeneratorTests and HuggingFaceEmbeddingGenerationTests test classes to validate the connector's ability to parse the feature extraction response format.
Usage
This file is loaded at test time through the HuggingFaceTestHelper.GetTestResponse() helper method, which reads from the ./TestData/ directory. Developers working on the HuggingFace embeddings connector would use this file when writing new unit tests or when the HuggingFace API response format for feature extraction changes.
Code Reference
Source Location
- Repository: Microsoft_Semantic_kernel
- File: dotnet/src/Connectors/Connectors.HuggingFace.UnitTests/TestData/embeddings_test_response_feature_extraction.json
- Lines: 1-1028
Signature
[
[
0.04324166476726532,
-0.02454185113310814,
-0.05429352819919586,
-0.01362373773008585,
0.010928897187113762,
-0.06823252886533737,
-0.007544773165136576,
0.023533517494797707,
0.019373835995793343,
0.01081706304103136,
0.029424330219626427,
-0.0005595402326434851,
0.026138367131352425,
0.006832693703472614,
-0.033758070319890976,
-0.016160812228918076,
-0.01652434468269348,
-0.021642858162522316,
-0.01686505414545536,
-0.00933303777128458
]
]
Import
// Via the HuggingFaceTestHelper utility class:
using SemanticKernel.Connectors.HuggingFace.UnitTests;
// In test methods:
string responseJson = HuggingFaceTestHelper.GetTestResponse("embeddings_test_response_feature_extraction.json");
// HuggingFaceTestHelper implementation:
internal static string GetTestResponse(string fileName)
{
return File.ReadAllText($"./TestData/{fileName}");
}
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| N/A (static file) | JSON file | N/A | This is a static test fixture; it has no runtime inputs |
Outputs
| Name | Type | Description |
|---|---|---|
| (root) | float[][] | Nested array of embedding vectors; outer array has one element per input text, inner array has float components |
| [i][j] | float | Individual embedding vector component at position j for input text i |
Usage Examples
Loading in HuggingFace Embedding Tests
using System.Net.Http;
using Xunit;
public class HuggingFaceEmbeddingGenerationTests
{
[Fact]
public async Task ItReturnsEmbeddingsCorrectly()
{
// Arrange
this._messageHandlerStub.ResponseToReturn.Content =
new StringContent(
HuggingFaceTestHelper.GetTestResponse(
"embeddings_test_response_feature_extraction.json"));
// Act
var embeddings = await this._embeddingGeneration
.GenerateEmbeddingsAsync(new List<string> { "test input" });
// Assert
Assert.NotNull(embeddings);
Assert.Single(embeddings); // One input -> one embedding vector
}
}
Related Pages
- Environment:Microsoft_Semantic_kernel_DotNet_SDK_Environment
- Microsoft_Semantic_kernel_HuggingFace_TextGeneration_TestData -- Mock HuggingFace text generation response in the same test project
- Microsoft_Semantic_kernel_Google_Embeddings_TestData -- Mock Google AI embeddings data (different JSON schema)
- Microsoft_Semantic_kernel_MistralAI_Embeddings_TestData -- Mock MistralAI embeddings data (different JSON schema)