Added embedding API to C#, JS, Python and Rust SDKs#639
Open
phanindraraja wants to merge 21 commits intomainfrom
Open
Added embedding API to C#, JS, Python and Rust SDKs#639phanindraraja wants to merge 21 commits intomainfrom
phanindraraja wants to merge 21 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Added null checks Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* updated js sdk * updated python sdk * updated rust sdk * Updated embedding model test aliases * Updated ordering on readme --------- Co-authored-by: Raja Phanindra Chava <rchava@microsoft.com>
…s as input (#3) Co-authored-by: Raja Phanindra Chava <rchava@microsoft.com>
d394dfa to
013d790
Compare
Contributor
There was a problem hiding this comment.
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/OpenAIEmbeddingClientand 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds embedding support to all four Foundry Local SDKs (C#, JavaScript, Python, Rust), enabling text embedding generation through the
OpenAIEmbeddingClientvia the FoundryLocalCore native interop layer. Supports both single and batch input.Changes
C# SDK
OpenAIEmbeddingClient— Client withGenerateEmbeddingAsync(string)for single input andGenerateEmbeddingsAsync(IEnumerable<string>)for batch. Configurable viaEmbeddingSettings(Dimensions,EncodingFormat).EmbeddingRequestResponseTypes.cs— Request DTO extending Betalgo'sEmbeddingCreateRequestwithFromUserInput()factory for both single and batch. Response deserialization with null-check and error handling.IModel.GetEmbeddingClientAsync()— New interface method, implemented inModelandModelVariant.JsonSerializationContext— RegisteredEmbeddingCreateRequestExtendedandEmbeddingCreateResponsefor AOT.JavaScript SDK
EmbeddingClient— Client withgenerateEmbedding(string)andgenerateEmbeddings(string[]). Settings withencodingFormatvalidation. SharedexecuteRequest()for both paths.IModel.createEmbeddingClient()— Factory method in interface,Model, andModelVariant.index.ts.Python SDK
EmbeddingClient— Client withgenerate_embedding(str)andgenerate_embeddings(List[str]). Uses OpenAI SDK types (EmbeddingCreateParamsfor request,CreateEmbeddingResponsefor response). Settings withencoding_formatvalidation via_serialize(). Patches server response to add missingobjectandusagefields required by the OpenAI SDK type.IModel.get_embedding_client()— Abstract method, implemented inModelandModelVariant.openai/__init__.py.Rust SDK
EmbeddingClient— Client withgenerate_embedding(&str)andgenerate_embeddings(&[&str]). Usesasync_openai::types::embeddings::CreateEmbeddingResponseas return type. Patches server response for missingobjectandusagefields. Settings withencoding_formatvalidation. Builder pattern fordimensions()andencoding_format().Model.create_embedding_client()— Factory method inModelandModelVariant."embedding-types"feature toasync-openaidependency.Tests
All SDKs include tests for:
Samples
New
embeddingssample in each SDK (samples/{cs,js,python,rust}/embeddings/) demonstrating:Documentation
index.md,imodel.md,model.md,modelvariant.md,openaiembeddingclient.md).README.mdclass index).docs/api.mdwithEmbeddingClient,EmbeddingResponse,EmbeddingDatareference).Test plan
Dependencies
This PR depends on the FoundryLocalCore (neutron-server) PR that adds the
"embeddings"NativeInterop command,/v1/embeddingsendpoint, and batch support:https://microsoft.visualstudio.com/windows.ai.toolkit/_git/neutron-server/pullrequest/15212502