Conversation
Add `svs_index_load()` and `svs_index_save()` API implementation for static Vamana index
Done: - [x] Create dynamic index with specified block size (default block size should be supported) - [x] Initialized with a dataset and labels list - [x] Add labeled vectors to a dynamic index - [x] Remove vectors by labels - [x] Check if a label exists - [x] Compute distance for label - [x] Get vector by label - [x] Consolidate/compact dynamic index - [x] Implement Save/Load
Adds `svs_index_get_num_threads` / `svs_index_set_num_threads` to the C API, enabling dynamic inspection and resizing of the search threadpool after index construction. ### ThreadPoolBuilder - Added `get_threads_num()` — delegates to the custom pool's `size()` op when `kind == CUSTOM`, otherwise returns the stored count - Added `resize(n)` — updates stored thread count; throws `std::invalid_argument` for `n == 0`, `SINGLE_THREAD`, or `CUSTOM` kinds (surfaced as `SVS_ERROR_INVALID_ARGUMENT` through `wrap_exceptions`) ### Index wrappers (`index.hpp`) - `Index` stores a `ThreadPoolBuilder`; `get_num_threads()` is pure-virtual — implemented in `IndexVamana` and `DynamicIndexVamana` by delegating to the wrapped `svs::Vamana` / `svs::DynamicVamana` instance, so the value reflects actual runtime state - `set_num_threads(n)` calls `pool_builder.resize(n)` then rebuilds and installs the threadpool via `set_threadpool()` ### C API (`svs_c.cpp` / `svs_c.h`) - Both entry points validate `index->impl` non-null before dereferencing (consistent with existing handle-check pattern) - Public header documents supported kinds and expected error codes for unsupported configurations
Resolve cmake version compatibility issue caused by using DOWNLOAD_EXTRACT_TIMESTAMP which is introduced in v.3.24 This PR fixes #317
…306) This pull request introduces a comprehensive C API test suite for the SVS project, leveraging the Catch2 testing framework. It adds new test files covering all major C API functionalities, integrates automated test building and execution into the CMake build system, and improves error handling and testability for dynamic index operations. **C API Test Infrastructure and Test Coverage:** * Added a new directory of C API tests using Catch2, with individual test files for error handling, algorithm configuration, storage, search parameters, index building, and dynamic index operations. **Dynamic Index Error Handling:** * Refactored `svs_index_dynamic_delete_points` to improve error handling.
- Introduced `svs_id_filter_interface` to define filtering operations. - Implemented `svs_index_search_topK` to support an optional ID filter for search operations. - Updated existing search functions to use the new filtered search capabilities. - Added a new source file `filtered_search.hpp` containing the logic for filtered top-K search. - Modified existing samples and tests to demonstrate and validate the new filtering functionality. - Marked the previous `svs_index_search` function as deprecated, directing users to use `svs_index_search_topK` instead.
…n) (#354) ## Summary Exposes memory accounting in the **C API** for the Valkey-search integration: - `svs_index_get_memory_usage(index, size_t* out_bytes, err)` — total allocated bytes. - `svs_index_get_memory_breakdown(index, svs_memory_breakdown_t* out, err)` — `{graph_bytes, data_bytes, metadata_bytes}` component split. ~~- `svs_index_element_size(index, size_t* out_bytes, err)` — bytes per stored vector.~~ (keep at data level) All follow the existing C API conventions (out-param + `svs_error_h`, `wrap_exceptions`), matching the Phase-A design in the memory-accounting contract (intel-innersource #333). ## Layers - **C API** (`bindings/c`): the three functions + `svs_memory_breakdown_t` in `svs_c.h`; interface virtuals + concrete overrides in `src/index.hpp`; impls in `src/svs_c.cpp`. - **Core / orchestrator**: brings in `get_memory_breakdown()` (`MemoryBreakdown` struct + capacity-based `svs::data::detail::dataset_allocated_bytes` helper) on `VamanaIndex` / `MutableVamanaIndex` and through the orchestrator, plus an `element_size()` accessor parallel to `dimensions()`. This mirrors the approved public PR #345 so the C API can build and test standalone; once #345 lands on `dev/c-api`, this reduces to just the C API layer. ## Tests `bindings/c/tests/c_api_index.cpp` (static) and `c_api_dynamic_index.cpp` (dynamic): usage > 0, breakdown total == usage, `graph_bytes`/`data_bytes` > 0 (metadata > 0 for dynamic), `element_size == sizeof(float) * dimensions`, and null-arg handling. Both test cases pass (84 / 166 assertions). Related: builds on #345; memory-accounting contract in intel-innersource #333 / #326.
#360 reopened directly to C API branch --------- Co-authored-by: Rafik Saliev <rafik.f.saliev@intel.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Is there a difference between scope of these "samples" vs. "examples" in repo root? I'd say it'd be more aligned with the rest of the repo to move bindings/c/samples to examples/c
There was a problem hiding this comment.
Thank you for the note.
As far as bindings/c is not referenced in the root CMakeLists.txt, I would do following steps:
- Add
bindings/cto the root CMake configuration (controlled by optionSVS_BUILD_C_API) - Move
binding/c/samplestoexamples/c - Modify
examples/CMakeListstoadd_subdirectory("c")ifSVS_BUILD_C_APIisON(orif(TARGET svs_c_api)) - Modify/update CI workflow and scripts to use root CMake directory for C API building
These changes can be made in this PR, or later upon merge - @ethanglaser, your opinion?
There was a problem hiding this comment.
I think it can be done in this PR easily enough, unless there was a reason we avoided doing this. It would align with runtime bindings and the remainder of the repo which would be preferable
There was a problem hiding this comment.
It would align with runtime bindings and the remainder of the repo which would be preferable
Unfortunately, there is no examples for runtime bindings and no reference to runtime bindings from the root CMakeLists.txt. It seems C API samples/examples cannot be aligned with
There was a problem hiding this comment.
I've moved bindings/c/samples to examples in the last commit.
**Important note:** > **This API refactoring breaks compatibility with existing client code** Refactor API for better consitency, stability, extensibility. - Updated ThreadPoolBuilder to ensure custom threadpool pointers are validated and initialized correctly. - Enhanced error handling in parallel_for method to catch exceptions and rethrow them appropriately. - Modified IDFilterAdapter to check for null operations and validate filter rates during initialization. - Adjusted test cases to reflect changes in function signatures and ensure proper error handling. - Introduced new utility functions for initializing search results and memory breakdown structures. - Updated sequential threadpool implementation to return a boolean indicating success - All public headers moved to `include/svs/c/`, and installation paths updated to match, replacing the old `c_api` directory. - Added generated version header `svs_c_version.h` with version macros, configured and installed via CMake. - Refactored `svs_search_result_t` structure now allows user to pre-allocate result buffers. - Added a detailed `README.md` for the C API, including build instructions, usage, and sample code.
|
Thanks for the ping, Rafik — this is a big, well-structured surface and the sub-PR history made it much easier to follow. I reviewed the whole branch against Splitting my feedback into three comments: this one is the set I'd want resolved before merge, then one on naming (needs a decision now rather than after release), then non-blocking cleanups and open questions. 1. Drop the four
|
Naming consistency — worth deciding now, not after releaseSeparating this from the defect list because it's a compatibility question rather than a bug, and because #363 already broke client compatibility once — that makes this the cheap moment to settle it.
The good news is that the conforming form already dominates the header: eight functions are
The One thing to fix either way: the design document's own example table at
— nine lines after stating the rule that puts Happy to defer the renames to a follow-up if you'd rather not churn the samples and tests in this PR — but in that case I'd want the follow-up issue opened before merge, since the cost only goes up once there are external callers. |
ahuber21
left a comment
There was a problem hiding this comment.
Please find my feedback in previous comments.
Non-blocking: doc drift, cleanups, and open questionsNone of these need to hold the merge, but a few are cheap and the first two are questions only you can answer. QuestionsThe C++ runtime binding changes look deliberate but undeclared.
Your own 4-step CMake plan is 1/4 done. From the thread on 2026-08-18 you proposed:
#367 delivered step 2. Steps 1, 3 and 4 are outstanding, and I take your point that runtime bindings aren't referenced from root either — but Ethan's "I think it can be done in this PR easily enough" wasn't withdrawn, so it's worth closing the loop explicitly. Concretely, the visible consequence today is that Relatedly: Documentation drift
|
Scalable Vector Search C API bindings.
This pull request introduces a new C API binding for the project, providing C language access to the core Scalable Vector Search (SVS) functionality. The changes add a complete build system for the C API, define the public C API headers, and include a sample program to demonstrate usage. The most important changes are grouped below:
C API Design Document
bindings/SVS_C_API_Design.mddocument which describes the design proposal for the Scalable Vector Search (SVS) C API including: architecture overview, core components design, naming conventions, usage rules, draft API reference, etc.C API Implementation and Build System:
bindings/cdirectory with aCMakeLists.txtto build the shared librarysvs_c_api, set up installation rules, and link dependencies such as OpenMP and the core SVS library.CMakeLists.txtto include the new C API bindings in the build process.c_apiConfig.cmake.in) for downstream projects to find and use the C API library.C API Public Headers:
svs_c.handsvs_c_config.hinbindings/c/include/svs/c_api/, defining the C API's types, enums, opaque handles, and functions for error handling, algorithm configuration, storage configuration, index building, searching, and result management. [1] [2]Samples and Demonstration:
samplesdirectory with aCMakeLists.txtto build a simple example (c_api_simple) demonstrating how to use the new C API.