[codex] add ordvec C ABI crate#101
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Code Review
This pull request introduces a C FFI wrapper crate (ordvec-ffi) for the ordvec library, enabling index loading, metadata retrieval, and search capabilities from C/C++ environments, alongside adding a search_subset method to the Bitmap index. The review feedback highlights critical safety issues in the FFI code where raw pointers pointing to potentially uninitialized memory are dereferenced to create Rust references, which is immediate Undefined Behavior; using ptr::addr_of! and ptr::write is recommended instead. Additionally, the feedback suggests handling the absence of a C compiler gracefully in smoke tests to prevent unnecessary test failures in environments without cc.
419bbde to
d3b94f5
Compare
Review Summary by QodoAdd ordvec C ABI v1 crate with RankQuant and Bitmap search support WalkthroughsDescription• Add ordvec-ffi workspace crate with C ABI v1 bindings • Expose synchronous search for RankQuant and Bitmap indexes • Implement exact struct-size validation and panic containment • Add C/C++ header smoke tests and Bitmap::search_subset core method Diagramflowchart LR
Core["Core ordvec<br/>RankQuant/Bitmap"]
FFI["ordvec-ffi crate<br/>C ABI v1"]
Header["Generated ordvec.h<br/>C/C++ compatible"]
Tests["Header smoke tests<br/>C11/C++17"]
Core -->|wraps| FFI
FFI -->|generates| Header
Header -->|validated by| Tests
FFI -->|adds| Subset["Bitmap::search_subset"]
File Changes1. ordvec-ffi/src/lib.rs
|
Code Review by Qodo
1. C11 smoke test panics
|
There was a problem hiding this comment.
Pull request overview
Introduces a new ordvec-ffi workspace crate that exposes a stable C ABI (v1) for loading and searching .tvrq RankQuant and .tvbm Bitmap indexes, with a committed cbindgen-generated ordvec.h, status/version/init scaffolding, thread-local error details, exact struct-size validation, caller-owned hit buffers, optional stats, and panic containment. To support subset search through the C ABI on Bitmap indexes, the core crate also gains a public Bitmap::search_subset built on top of the existing body_overlap_scores_subset.
Changes:
- Add
ordvec-fficrate withcdylib/staticlib/rliboutputs, ABI v1 C surface (load/info/free + synchronous single-query search for RankQuant and Bitmap), thread-local last-error, panic catching, and exact struct-size validation; commitcbindgen.tomland generatedinclude/ordvec.hwith C/C++ static size assertions. - Add C11 and C++17 header smoke tests plus extensive Rust-side unit tests covering load/info/search happy paths and a broad matrix of validation failures.
- Add
Bitmap::search_subsetin core, returning top-k for a caller-supplied (possibly unsorted/duplicated) candidate set with deterministic(score desc, row asc)tie-breaking; wireordvec-ffiinto the workspace.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| Cargo.toml | Adds ordvec-ffi to workspace members (default-members unchanged, so root CI doesn't cover it). |
| Cargo.lock | Lockfile entry for the new crate. |
| ordvec-ffi/Cargo.toml | New unpublished crate with rlib/cdylib/staticlib, depends only on the core crate. |
| ordvec-ffi/cbindgen.toml | cbindgen config: C language, cpp_compat, excludes internal Rust types, appends static size asserts. |
| ordvec-ffi/include/ordvec.h | Committed generated header with ABI v1 types, status/kind constants, and static size assertions outside the include guard. |
| ordvec-ffi/src/lib.rs | Full FFI implementation: opaque handle, status codes, struct-size checks, candidate validation, panic-safe boundary, search dispatch + stats, extensive unit tests. |
| ordvec-ffi/tests/header_smoke.rs | Compiles ordvec.h as C11 (hard-failure if cc missing) and C++17 (silently skipped if c++ missing). |
| src/bitmap.rs | Adds Bitmap::search_subset (single query, caller-supplied candidate IDs, deterministic top-k) used by the FFI subset path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d3b94f5 to
2760c18
Compare
Signed-off-by: Nelson Spence <nelson@projectnavi.ai>
2760c18 to
a678e27
Compare
|
Addressed the remaining bot findings for this PR:
Validation run locally: |
Summary
ordvec-ffiworkspace crate withcdylib/staticliboutputs and a committed cbindgen-generated C header.tvrqRankQuant and.tvbmBitmapBitmap::search_subsetValidation
cargo fmt --all --checkcbindgen ordvec-ffi --config ordvec-ffi/cbindgen.toml --output ordvec-ffi/include/ordvec.h --verifycargo testcargo test -p ordvec-fficargo clippy --all-targets -- -D warningscargo clippy -p ordvec-ffi --all-targets -- -D warningscargo build -p ordvec-ffiGOCACHE=/tmp/go-build go test -count=1 ./...andGOCACHE=/tmp/go-build go test -race -count=1 ./...fromordvec-goStack base:
main. Next PR in stack:codex/c-api-docs.