Skip to content

Added embedding API to C++ SDK#668

Open
phanindraraja wants to merge 7 commits intomainfrom
user/rchava/embedding-support-cpp-sdk
Open

Added embedding API to C++ SDK#668
phanindraraja wants to merge 7 commits intomainfrom
user/rchava/embedding-support-cpp-sdk

Conversation

@phanindraraja
Copy link
Copy Markdown
Member

@phanindraraja phanindraraja commented Apr 23, 2026

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 OpenAIEmbeddingClient with GenerateEmbedding (single) and GenerateEmbeddings (batch), same empty- and whitespace-input rejection as the other SDKs, response parsed into strongly-typed EmbeddingCreateResponse / EmbeddingObject / EmbeddingUsage structs via nlohmann/json. Plumbing (umbrella header, IModel friend, parser overloads, CMake source entry) mirrors OpenAIChatClient one-to-one.

  • Tests: 13 unit tests (mocked core, no DLL needed) and one DISABLED_ E2E test matching the shape of DISABLED_DownloadLoadChatUnload.
  • Sample: new GenerateEmbeddings example wired into main(); manager initialization now uses a Configuration object so samples can pass core-level settings such as AzureCatalogFilter.
  • Build: /EHsc enabled globally so wil's exception-based APIs that core.h relies on resolve against the current vcpkg WIL version.

Optimizations

  • C# SDK — materialize the lazy IEnumerable<string> in the batch method once instead of enumerating it three times (Any, per-item validation, and the request builder).
  • C# tests — fix a shadowed local in the class setup that could easily mask the static field; remove an in-place genai_config.json mutation helper that left test-data-shared dirty across runs.
  • Python SDK — drop the redundant len(inputs) == 0 check (already covered by not inputs).
  • Rust SDK — replace the .as_object_mut().map(|m| ...) pattern that discarded its return value with the idiomatic if let Some(obj) = ... plus entry("object").or_insert_with(...).
  • Rust docs — drop a stale EmbeddingResponse TOC 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.6b everywhere.

Testing

  • C++ unit tests: 13/13 pass under ctest --preset x64-debug.
  • C++ E2E: runs locally with the Core DLL staged alongside the test binary and --gtest_also_run_disabled_tests.
  • All other SDK integration surfaces are unchanged from the user's perspective.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 23, 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 27, 2026 3:30pm

Request Review

@phanindraraja phanindraraja changed the title Add embedding support for cpp SDK Added embedding API to C++ SDK Apr 23, 2026
@phanindraraja phanindraraja marked this pull request as ready for review April 23, 2026 19:42
Copilot AI review requested due to automatic review settings April 23, 2026 19:42
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 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.

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.

2 participants