Added embedding API to C#, JS, Python and Rust SDKs#581
Added embedding API to C#, JS, Python and Rust SDKs#581phanindraraja wants to merge 12 commits intomicrosoft:mainfrom
Conversation
|
Someone is attempting to deploy a commit to the MSFT-AIP Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
Adds an embeddings capability to the Foundry Local C# SDK, aligning it with the existing OpenAI-compatible chat and audio clients and exposing it through the model abstraction.
Changes:
- Introduces
OpenAIEmbeddingClientwith request/response serialization helpers and JSON source-gen registrations. - Exposes embeddings via
IModel.GetEmbeddingClientAsync()and implements it onModel/ModelVariantwith loaded-model enforcement. - Adds test coverage plus README/API docs updates for the new embeddings surface.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/cs/src/OpenAI/EmbeddingClient.cs | Adds OpenAIEmbeddingClient and the public embeddings API surface. |
| sdk/cs/src/OpenAI/EmbeddingRequestResponseTypes.cs | Adds embeddings request DTO + response parsing/serialization helpers. |
| sdk/cs/src/IModel.cs | Adds GetEmbeddingClientAsync to the public model interface. |
| sdk/cs/src/Detail/Model.cs | Wires GetEmbeddingClientAsync through to the selected variant. |
| sdk/cs/src/Detail/ModelVariant.cs | Implements GetEmbeddingClientAsync with “must be loaded” validation. |
| sdk/cs/src/Detail/JsonSerializationContext.cs | Registers embeddings request/response types for STJ source generation. |
| sdk/cs/test/FoundryLocal.Tests/EmbeddingClientTests.cs | Adds embeddings integration tests (basic, normalization, determinism, known values). |
| sdk/cs/README.md | Documents embeddings feature and shows usage + settings. |
| sdk/cs/docs/api/microsoft.ai.foundry.local.openaiembeddingclient.md | Adds generated API docs for OpenAIEmbeddingClient. |
| sdk/cs/docs/api/microsoft.ai.foundry.local.imodel.md | Updates generated API docs for IModel with embeddings accessor. |
| sdk/cs/docs/api/microsoft.ai.foundry.local.model.md | Updates generated API docs for Model with embeddings accessor. |
| sdk/cs/docs/api/microsoft.ai.foundry.local.modelvariant.md | Updates generated API docs for ModelVariant with embeddings accessor. |
| sdk/cs/docs/api/index.md | Adds OpenAIEmbeddingClient to the API docs index. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
213a854 to
e9d887d
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cbba093 to
2789034
Compare
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>
2ddc1a2 to
23d58e4
Compare
…s as input (#3) Co-authored-by: Raja Phanindra Chava <rchava@microsoft.com>
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:
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