Skip to content

Added embedding API to C#, JS, Python and Rust SDKs#639

Merged
baijumeswani merged 23 commits intomainfrom
user/rchava/embedding-support
Apr 22, 2026
Merged

Added embedding API to C#, JS, Python and Rust SDKs#639
baijumeswani merged 23 commits intomainfrom
user/rchava/embedding-support

Conversation

@phanindraraja
Copy link
Copy Markdown
Member

@phanindraraja phanindraraja commented Apr 15, 2026

Summary

Adds embedding support to all four Foundry Local SDKs (C#, JavaScript, Python, Rust), enabling text embedding generation through the OpenAIEmbeddingClient via the FoundryLocalCore native interop layer. Supports both single and batch input.

Changes

C# SDK

  • OpenAIEmbeddingClient — Client with GenerateEmbeddingAsync(string) for single input and GenerateEmbeddingsAsync(IEnumerable<string>) for batch.
  • EmbeddingRequestResponseTypes.cs — Request DTO extending Betalgo's EmbeddingCreateRequest with FromUserInput() factory for both single and batch. Response deserialization with null-check and error handling.
  • IModel.GetEmbeddingClientAsync() — New interface method, implemented in Model and ModelVariant.
  • JsonSerializationContext — Registered EmbeddingCreateRequestExtended and EmbeddingCreateResponse for AOT.

JavaScript SDK

  • EmbeddingClient — Client with generateEmbedding(string) and generateEmbeddings(string[]). Shared executeRequest() for both paths.
  • IModel.createEmbeddingClient() — Factory method in interface, Model, and ModelVariant.
  • Exported from index.ts.

Python SDK

  • EmbeddingClient — Client with generate_embedding(str) and generate_embeddings(List[str]). Uses OpenAI SDK types (EmbeddingCreateParams for request, CreateEmbeddingResponse for response). Patches server response to add missing object and usage fields required by the OpenAI SDK type.
  • IModel.get_embedding_client() — Abstract method, implemented in Model and ModelVariant.
  • Exported from openai/__init__.py.

Rust SDK

  • EmbeddingClient — Client with generate_embedding(&str) and generate_embeddings(&[&str]). Uses async_openai::types::embeddings::CreateEmbeddingResponse as return type. Patches server response for missing object and usage fields.
  • Model.create_embedding_client() — Factory method in Model and ModelVariant.
  • Added "embedding-types" feature to async-openai dependency.

Tests

All SDKs include tests for:

  • Basic embedding generation (1024 dimensions, correct response structure)
  • L2 normalization (norm ≈ 1.0, values within [-1, 1])
  • Different inputs produce different embeddings (cosine similarity < 0.99)
  • Same input produces identical embeddings (determinism)
  • Batch embedding (multiple inputs → multiple results with correct indices)
  • Batch results match single-input results
  • Input validation (empty input, empty list)
  • Known golden values (C# only)

Samples

New embeddings sample in each SDK (samples/{cs,js,python,rust}/embeddings/) demonstrating:

  • SDK initialization and model setup
  • Single embedding generation with dimension output
  • Batch embedding generation with multiple inputs

Documentation

  • All four SDK READMEs updated with embeddings feature documentation and usage examples.
  • C# API docs (index.md, imodel.md, model.md, modelvariant.md, openaiembeddingclient.md).
  • JS docs (README.md class index).
  • Rust API docs (docs/api.md with EmbeddingClient, EmbeddingResponse, EmbeddingData reference).
  • Python API reference table updated.

Test plan

  • C# SDK tests pass
  • Python SDK tests pass
  • JS SDK tests pass
  • Rust SDK tests pass
  • All existing chat/audio tests unaffected

Dependencies

This PR depends on the FoundryLocalCore (neutron-server) PR that adds the "embeddings" NativeInterop command, /v1/embeddings endpoint, and batch support:
https://microsoft.visualstudio.com/windows.ai.toolkit/_git/neutron-server/pullrequest/15212502

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
foundry-local Ready Ready Preview, Comment Apr 22, 2026 6:39am

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds OpenAI-compatible embeddings support across the Foundry Local SDKs (C#, JS, Python, Rust) by introducing embedding clients that call the native embeddings interop command, plus tests, samples, and documentation updates.

Changes:

  • Introduces EmbeddingClient/OpenAIEmbeddingClient and model factory methods in Rust/JS/Python/C#.
  • Adds integration/unit tests for embedding generation and batch behavior across SDKs.
  • Adds new embeddings samples and updates SDK READMEs / API docs; updates Rust dependency features for embedding types.

Reviewed changes

Copilot reviewed 54 out of 55 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
sdk/rust/tests/integration/main.rs Registers Rust embedding integration test module.
sdk/rust/tests/integration/embedding_client_test.rs Adds Rust integration coverage for single/batch embeddings + normalization/determinism checks.
sdk/rust/tests/integration/common/mod.rs Adds embedding model alias constant for integration tests.
sdk/rust/src/openai/mod.rs Exposes Rust EmbeddingClient + settings from the OpenAI module.
sdk/rust/src/openai/embedding_client.rs Implements Rust embedding client + settings + response patching for async_openai types.
sdk/rust/src/detail/model_variant.rs Adds create_embedding_client() factory on Rust ModelVariant.
sdk/rust/src/detail/model.rs Adds public create_embedding_client() factory on Rust Model.
sdk/rust/docs/api.md Documents the new Rust embeddings client API.
sdk/rust/README.md Adds Rust README section describing embeddings usage + settings.
sdk/rust/Cargo.toml Enables async-openai embedding types via embedding-types feature.
sdk/python/test/openai/test_embedding_client.py Adds Python embedding tests mirroring C# suite (single/batch/normalization/determinism/validation).
sdk/python/test/conftest.py Adds Python embedding model alias constant for tests.
sdk/python/src/openai/embedding_client.py Implements Python EmbeddingClient + settings + response patching for OpenAI SDK types.
sdk/python/src/openai/init.py Exports Python EmbeddingClient / EmbeddingSettings.
sdk/python/src/imodel.py Adds Python IModel.get_embedding_client() abstract method.
sdk/python/src/detail/model_variant.py Implements Python get_embedding_client() on ModelVariant.
sdk/python/src/detail/model.py Implements Python get_embedding_client() on Model.
sdk/python/README.md Adds Python README section for embeddings usage + settings.
sdk/js/test/testUtils.ts Adds JS embedding model alias constant for tests.
sdk/js/test/openai/embeddingClient.test.ts Adds JS embedding tests for single/batch/normalization/determinism.
sdk/js/src/openai/embeddingClient.ts Implements JS EmbeddingClient + settings + input validation + shared request executor.
sdk/js/src/index.ts Exports JS EmbeddingClient / EmbeddingClientSettings.
sdk/js/src/imodel.ts Adds JS IModel.createEmbeddingClient() factory signature.
sdk/js/src/detail/modelVariant.ts Implements createEmbeddingClient() on JS ModelVariant.
sdk/js/src/detail/model.ts Implements createEmbeddingClient() on JS Model.
sdk/js/docs/README.md Adds embeddings classes to JS docs index.
sdk/js/README.md Adds JS README section for embeddings usage + settings.
sdk/cs/test/FoundryLocal.Tests/EmbeddingClientTests.cs Adds C# embeddings test suite.
sdk/cs/src/OpenAI/EmbeddingRequestResponseTypes.cs Adds C# embedding request DTO helpers + response parsing extensions.
sdk/cs/src/OpenAI/EmbeddingClient.cs Adds C# OpenAIEmbeddingClient using native interop.
sdk/cs/src/IModel.cs Adds C# IModel.GetEmbeddingClientAsync() API.
sdk/cs/src/Detail/ModelVariant.cs Implements C# GetEmbeddingClientAsync() on model variants.
sdk/cs/src/Detail/Model.cs Implements C# GetEmbeddingClientAsync() on models.
sdk/cs/src/Detail/JsonSerializationContext.cs Registers embedding request/response types for source-gen JSON serialization (AOT).
sdk/cs/docs/api/microsoft.ai.foundry.local.openaiembeddingclient.md Adds generated API doc page for C# embedding client.
sdk/cs/docs/api/microsoft.ai.foundry.local.modelvariant.md Documents new C# GetEmbeddingClientAsync() on ModelVariant.
sdk/cs/docs/api/microsoft.ai.foundry.local.model.md Documents new C# GetEmbeddingClientAsync() on Model.
sdk/cs/docs/api/microsoft.ai.foundry.local.imodel.md Documents new C# IModel.GetEmbeddingClientAsync() method.
sdk/cs/docs/api/index.md Adds OpenAIEmbeddingClient to C# docs index.
sdk/cs/README.md Adds C# README section for embeddings usage + settings.
samples/rust/embeddings/src/main.rs Adds Rust embeddings sample (single + batch) with model lifecycle.
samples/rust/embeddings/Cargo.toml Adds Cargo manifest for Rust embeddings sample.
samples/rust/README.md Lists the new Rust embeddings sample.
samples/rust/Cargo.toml Adds embeddings sample to Rust samples workspace.
samples/python/embeddings/src/app.py Adds Python embeddings sample (single + batch) with model lifecycle.
samples/python/embeddings/requirements.txt Adds Python sample requirements including WinML variant on Windows.
samples/python/README.md Lists the new Python embeddings sample.
samples/js/embeddings/package.json Adds JS embeddings sample package manifest.
samples/js/embeddings/app.js Adds JS embeddings sample (single + batch) with model lifecycle.
samples/js/README.md Lists the new JS embeddings sample.
samples/cs/embeddings/Program.cs Adds C# embeddings sample (single + batch) with model lifecycle.
samples/cs/embeddings/Embeddings.csproj Adds C# sample project file with Win/non-Win targeting.
samples/cs/README.md Lists the new C# embeddings sample.
samples/README.md Updates top-level samples README to include embeddings and updated sample counts.
.gitignore Ignores .vscode/ directory.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sdk/cs/test/FoundryLocal.Tests/EmbeddingClientTests.cs
Comment thread sdk/cs/test/FoundryLocal.Tests/EmbeddingClientTests.cs
Comment thread sdk/js/src/openai/embeddingClient.ts
Comment thread sdk/rust/src/openai/embedding_client.rs
Comment thread sdk/js/test/openai/embeddingClient.test.ts Outdated
Comment thread sdk/rust/docs/api.md
Comment thread sdk/cs/src/OpenAI/EmbeddingClient.cs Outdated
Comment thread sdk/cs/README.md Outdated
Copy link
Copy Markdown
Contributor

@prathikr prathikr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main has changes to remove reliance on PATs for fetching neutron-server/test-data-shared, need to merge with main and resolve any conflicts

Comment thread sdk/python/src/openai/embedding_client.py
Comment thread sdk/cs/test/FoundryLocal.Tests/EmbeddingClientTests.cs
Comment thread sdk/cs/test/FoundryLocal.Tests/EmbeddingClientTests.cs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 55 out of 56 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sdk/js/src/openai/embeddingClient.ts
Comment thread sdk/cs/src/OpenAI/EmbeddingClient.cs
Comment thread sdk/cs/test/FoundryLocal.Tests/Utils.cs
Comment thread sdk/cs/test/FoundryLocal.Tests/EmbeddingClientTests.cs
Comment thread sdk/rust/docs/api.md
@baijumeswani baijumeswani merged commit 03fef37 into main Apr 22, 2026
53 of 55 checks passed
@baijumeswani baijumeswani deleted the user/rchava/embedding-support branch April 22, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants