Added embedding API to C++ SDK#668
Open
phanindraraja wants to merge 7 commits intomainfrom
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an OpenAI-compatible embeddings client to the C++ SDK and aligns surrounding SDK/sample code to support embedding usage consistently across languages.
Changes:
- Introduces
OpenAIEmbeddingClient(C++), including JSON parsing for embedding responses and CMake integration. - Adds C++ unit tests + disabled E2E coverage for embeddings; updates the C++ sample to demonstrate single and batch embeddings.
- Minor cleanups/alignments in Rust/Python/C# embedding clients/tests/docs and updates samples to use the newer embedding alias and to download/register execution providers before running.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/rust/src/openai/embedding_client.rs | Simplifies/clarifies response “patching” before deserializing into async_openai types. |
| sdk/rust/docs/api.md | Removes outdated TOC entry for an embedding response type. |
| sdk/python/src/openai/embedding_client.py | Simplifies empty-input check (if not inputs). |
| sdk/cs/test/FoundryLocal.Tests/Utils.cs | Removes the model-config max_length patch helper (no longer used). |
| sdk/cs/test/FoundryLocal.Tests/EmbeddingClientTests.cs | Removes max_length patch usage; minor variable rename/cleanup. |
| sdk/cs/src/OpenAI/EmbeddingClient.cs | Avoids multiple enumeration by materializing inputs once and validating the list. |
| sdk/cpp/test/e2e_test.cpp | Adds disabled E2E test for downloading/loading/unloading and generating embeddings (single + batch). |
| sdk/cpp/test/client_test.cpp | Adds unit tests validating request format, response parsing, and input/core-error handling for embeddings. |
| sdk/cpp/src/parser.h | Adds from_json parsers for embedding response structs. |
| sdk/cpp/src/openai_embedding_client.cpp | Implements the C++ embeddings client over the native embeddings command. |
| sdk/cpp/sample/main.cpp | Adds a runnable embeddings example (single + batch). |
| sdk/cpp/include/openai/openai_embedding_client.h | New public C++ header exposing embedding client + response types. |
| sdk/cpp/include/model.h | Grants embedding client access to IModel::CoreAccess (friend + forward decl). |
| sdk/cpp/include/foundry_local.h | Exposes embeddings client via umbrella header include. |
| sdk/cpp/CMakeLists.txt | Enables /EHsc on MSVC and adds the new embeddings source file to the static library. |
| samples/rust/embeddings/src/main.rs | Updates embedding alias and adds EP discovery + download/register with progress output. |
| samples/python/embeddings/src/app.py | Updates embedding alias and adds EP discovery + download/register with progress output. |
| samples/js/embeddings/app.js | Updates embedding alias and adds EP discovery + download/register with progress output. |
| samples/cs/embeddings/Program.cs | Updates embedding alias and adds EP discovery + download/register with progress output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1130a6f to
43ba738
Compare
43ba738 to
13f297c
Compare
13f297c to
23950d3
Compare
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 the C++ SDK. Also picks up optimizations across the other four SDKs and aligns all five embedding samples to a consistent initialization sequence.
Changes
C++ SDK — new embedding client
Follows the existing chat/audio client pattern: public
OpenAIEmbeddingClientwithGenerateEmbedding(single) andGenerateEmbeddings(batch), same empty- and whitespace-input rejection as the other SDKs, response parsed into strongly-typedEmbeddingCreateResponse/EmbeddingObject/EmbeddingUsagestructs via nlohmann/json. Plumbing (umbrella header,IModelfriend, parser overloads, CMake source entry) mirrorsOpenAIChatClientone-to-one.DISABLED_DownloadLoadChatUnload.GenerateEmbeddingsexample wired intomain(); manager initialization now uses aConfigurationobject so samples can pass core-level settings such asAzureCatalogFilter./EHscenabled globally sowil's exception-based APIs thatcore.hrelies on resolve against the current vcpkg WIL version.Optimizations
IEnumerable<string>in the batch method once instead of enumerating it three times (Any, per-item validation, and the request builder).genai_config.jsonmutation helper that left test-data-shared dirty across runs.len(inputs) == 0check (already covered bynot inputs)..as_object_mut().map(|m| ...)pattern that discarded its return value with the idiomaticif let Some(obj) = ...plusentry("object").or_insert_with(...).EmbeddingResponseTOC entry that pointed at a section that was never generated.Sample alignment across all five SDKs
All embedding samples now run the same seven-step sequence: create manager → discover EPs (prints the table) → download and register EPs → get catalog → get model → download model → load model. The embedding samples previously skipped the EP-discovery step that chat samples show; this brings them into alignment. Model alias is now
qwen3-embedding-0.6beverywhere.Testing
ctest --preset x64-debug.--gtest_also_run_disabled_tests.