Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 44 additions & 8 deletions Google.GenAI.E2E.Tests/EmbedContent/EmbedContentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public void TestInit() {
new Client(apiKey: apiKey, vertexAI: false, httpOptions: geminiClientHttpOptions);

// Specific setup for this test class
modelName = "text-embedding-004";
multimodalModelName = "gemini-embedding-2-exp-11-2025";
modelName = "gemini-embedding-001";
multimodalModelName = "gemini-embedding-2-preview";
}

[TestMethod]
Expand All @@ -84,7 +84,7 @@ public async Task EmbedContentSimpleTextVertexTest() {
new Content { Parts = new List<Part> { new Part { Text = "What is your name?" } } }
};
var vertexResponse = await vertexClient.Models.EmbedContentAsync(
model: modelName, contents: contents, config: null);
model: modelName, contents: contents, config: new EmbedContentConfig { OutputDimensionality = 10 });

Assert.IsNotNull(vertexResponse.Embeddings);
}
Expand All @@ -95,23 +95,23 @@ public async Task EmbedContentSimpleTextGeminiTest() {
new Content { Parts = new List<Part> { new Part { Text = "What is your name?" } } }
};
var geminiResponse = await geminiClient.Models.EmbedContentAsync(
model: modelName, contents: contents, config: null);
model: modelName, contents: contents, config: new EmbedContentConfig { OutputDimensionality = 10 });

Assert.IsNotNull(geminiResponse.Embeddings);
}

[TestMethod]
public async Task EmbedContentSingleStringVertexTest() {
var vertexResponse = await vertexClient.Models.EmbedContentAsync(
model: modelName, contents: "What is your name?", config: null);
model: modelName, contents: "What is your name?", config: new EmbedContentConfig { OutputDimensionality = 10 });

Assert.IsNotNull(vertexResponse.Embeddings);
}

[TestMethod]
public async Task EmbedContentSingleStringGeminiTest() {
var geminiResponse = await geminiClient.Models.EmbedContentAsync(
model: modelName, contents: "What is your name?", config: null);
model: modelName, contents: "What is your name?", config: new EmbedContentConfig { OutputDimensionality = 10 });

Assert.IsNotNull(geminiResponse.Embeddings);
}
Expand Down Expand Up @@ -231,7 +231,7 @@ public async Task EmbedContentNewApiTextOnlyVertexTest()
new Content { Parts = new List<Part> { new Part { Text = "What is your name?" } } }
};
var config = new EmbedContentConfig {
OutputDimensionality = 100,
OutputDimensionality = 10,
};
var vertexResponse = await vertexClient.Models.EmbedContentAsync(
model: multimodalModelName, contents: contents, config: config);
Expand All @@ -247,7 +247,7 @@ public async Task EmbedContentNewApiMaasVertexTest()
new Content { Parts = new List<Part> { new Part { Text = "What is your name?" } } }
};
var config = new EmbedContentConfig {
OutputDimensionality = 100,
OutputDimensionality = 10,
};
var vertexResponse = await vertexClient.Models.EmbedContentAsync(
model: "publishers/intfloat/models/multilingual-e5-large-instruct-maas", contents: contents, config: config);
Expand Down Expand Up @@ -299,4 +299,40 @@ public async Task EmbedContentNewApiListOfContentsVertexTest()

Assert.IsTrue(exception.Message.Contains("The embedContent API for this model only supports one content at a time."));
}

[TestMethod]
public async Task EmbedContentInlinePdfDocumentOcrVertexTest()
{
byte[] fileBytes = await System.IO.File.ReadAllBytesAsync("TestAssets/story.pdf");
var contents = new List<Content> {
new Content { Parts = new List<Part> { Part.FromBytes(fileBytes, "application/pdf") } }
};
var config = new EmbedContentConfig {
OutputDimensionality = 10,
DocumentOcr = true
};
var vertexResponse = await vertexClient.Models.EmbedContentAsync(
model: multimodalModelName, contents: contents, config: config);

Assert.IsNotNull(vertexResponse);
Assert.IsNotNull(vertexResponse.Embeddings);
}

[TestMethod]
public async Task EmbedContentInlineVideoAudioTrackExtractionVertexTest()
{
byte[] fileBytes = await System.IO.File.ReadAllBytesAsync("TestAssets/animal.mp4");
var contents = new List<Content> {
new Content { Parts = new List<Part> { Part.FromBytes(fileBytes, "video/mp4") } }
};
var config = new EmbedContentConfig {
OutputDimensionality = 10,
AudioTrackExtraction = true
};
var vertexResponse = await vertexClient.Models.EmbedContentAsync(
model: multimodalModelName, contents: contents, config: config);

Assert.IsNotNull(vertexResponse);
Assert.IsNotNull(vertexResponse.Embeddings);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

using Google.GenAI;
using Google.GenAI.Types;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using TestServerSdk;

[TestClass]
public class GenerateContentSimpleTestCustomClient {
private static TestServerProcess? _server;
private Client vertexClient;
private Client geminiClient;
private string modelName;
public TestContext TestContext { get; set; }

[ClassInitialize]
public static void ClassInit(TestContext _) {
_server = TestServer.StartTestServer();
}

[ClassCleanup]
public static void ClassCleanup() {
TestServer.StopTestServer(_server);
}

[TestInitialize]
public void TestInit() {
// Test server specific setup.
if (_server == null) {
throw new InvalidOperationException("Test server is not initialized.");
}
var geminiClientHttpOptions = new HttpOptions {
Headers = new Dictionary<string, string> { { "Test-Name",
$"{GetType().Name}.{TestContext.TestName}" } },
BaseUrl = "http://localhost:1453"
};
var vertexClientHttpOptions = new HttpOptions {
Headers = new Dictionary<string, string> { { "Test-Name",
$"{GetType().Name}.{TestContext.TestName}" } },
BaseUrl = "http://localhost:1454"
};

// Common setup for both clients.
string project = System.Environment.GetEnvironmentVariable("GOOGLE_CLOUD_PROJECT");
string location =
System.Environment.GetEnvironmentVariable("GOOGLE_CLOUD_LOCATION") ?? "us-central1";
string apiKey = System.Environment.GetEnvironmentVariable("GOOGLE_API_KEY");
vertexClient = new Client(project: project, location: location, vertexAI: true,
credential: TestServer.GetCredentialForTestMode(),
httpOptions: vertexClientHttpOptions,
clientOptions: new ClientOptions {
HttpClientFactory = () => new HttpClient(new HttpClientHandler()) {
Timeout = TimeSpan.FromMinutes(5)
}
});
geminiClient =
new Client(apiKey: apiKey, vertexAI: false, httpOptions: geminiClientHttpOptions,
clientOptions: new ClientOptions {
HttpClientFactory = () => new HttpClient(new HttpClientHandler()) {
Timeout = TimeSpan.FromMinutes(5)
}
});

// Specific setup for this test class
modelName = "gemini-2.5-flash";
}

[TestMethod]
public async Task GenerateContentSimpleTextVertexTest() {
var vertexResponse = await vertexClient.Models.GenerateContentAsync(
model: modelName, contents: "What is the capital of France?");

Assert.IsNotNull(vertexResponse.Candidates);
StringAssert.Contains(vertexResponse.Text, "Paris");
}

[TestMethod]
public async Task GenerateContentSimpleTextGeminiTest() {
var geminiResponse = await geminiClient.Models.GenerateContentAsync(
model: modelName, contents: "What is the capital of France?");

Assert.IsNotNull(geminiResponse.Candidates);
StringAssert.Contains(geminiResponse.Text, "Paris");
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
{
"request": {
"method": "POST",
"url": "/v1beta/models/text-embedding-004:batchEmbedContents",
"request": "POST /v1beta/models/text-embedding-004:batchEmbedContents HTTP/1.1",
"url": "/v1beta/models/gemini-embedding-001:batchEmbedContents",
"request": "POST /v1beta/models/gemini-embedding-001:batchEmbedContents HTTP/1.1",
"headers": {
"Content-Length": "347",
"Content-Length": "351",
"Content-Type": "application/json; charset=utf-8",
"Test-Name": "EmbedContentTest.EmbedContentMultiTextGeminiTest"
},
Expand All @@ -22,7 +22,7 @@
}
]
},
"model": "models/text-embedding-004",
"model": "models/gemini-embedding-001",
"outputDimensionality": 10,
"taskType": "RETRIEVAL_DOCUMENT",
"title": "test_title"
Expand All @@ -35,7 +35,7 @@
}
]
},
"model": "models/text-embedding-004",
"model": "models/gemini-embedding-001",
"outputDimensionality": 10,
"taskType": "RETRIEVAL_DOCUMENT",
"title": "test_title"
Expand All @@ -48,14 +48,14 @@
"port": 443,
"protocol": "https"
},
"shaSum": "50128cd8a28c44e38af1b0551cc25ebf7c7af1c59953d49db45899a450dbb1bc",
"shaSum": "2da9e795ef60e639f9f070fea9a6736bd1be0d0358809e2b5510e4c63466fa48",
"response": {
"statusCode": 200,
"headers": {
"Content-Type": "application/json; charset=UTF-8",
"Date": "Tue, 09 Dec 2025 00:42:46 GMT",
"Date": "Thu, 09 Apr 2026 18:58:31 GMT",
"Server": "scaffolding on HTTPServer2",
"Server-Timing": "gfet4t7; dur=179",
"Server-Timing": "gfet4t7; dur=150",
"Vary": "Origin, X-Origin, Referer",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "SAMEORIGIN",
Expand All @@ -66,33 +66,34 @@
"embeddings": [
{
"values": [
0.0062209684,
-0.00016352482,
-0.04497254,
-0.024360893,
0.024183987,
0.027219841,
0.036644667,
0.028461628,
-0.04021491,
0.03328241
-0.03950208,
0.0007256423,
0.036894154,
-0.06420937,
0.007837503,
0.0070161745,
-0.013046161,
0.0040008393,
0.019140515,
-0.0029148892
]
},
{
"values": [
-0.02997993,
-0.031975683,
-0.041643385,
-0.01656822,
0.031309083,
0.025444405,
0.0028291983,
0.05965454,
-0.014440891,
0.024713816
-0.037093285,
0.010633466,
0.022869334,
-0.066629514,
-0.0067563136,
0.012390815,
-0.0096923895,
-0.0016614407,
-0.0002718712,
-0.010780795
]
}
]
],
"tokenCount": "10"
}
]
}
Expand Down
Loading
Loading