feat(vectordb)Migrate vectordb engine to abi3 packaging#897
Merged
Conversation
chore: remove pybind11 remnants after abi3 migration fix: scope linux abi3 wheel smoke test to engine loader
|
Failed to generate code suggestions for PR |
qin-ctx
approved these changes
Mar 23, 2026
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.
PR 标题
Migrate vectordb engine to abi3 packaging
变更摘要
这个 PR 将 vectordb 原生引擎从
pybind11绑定迁移到基于 CPython Stable ABI 的abi3打包模式,并通过一层轻量的 Python 适配层保持 Python 侧 API 的可用性和整体使用方式稳定。这次改动的核心目标有三个:
abi3wheel 产线,供 3.10+ 复用。pybind11依赖。背景与动机
此前的 vectordb engine 打包方式依赖
pybind11,并且生成的是与具体 CPython 版本绑定的扩展二进制。这会带来几个问题:pybind11,扩大了构建依赖和 CI 维护面。迁移到
abi3后,可以在保留 C++ 引擎实现的前提下,把 wheel 分发从“跟着 Python 小版本走”变成“跟着 Stable ABI 走”。变更范围
本 PR 包含:
abi3C API 后端替换原有 vectordb 的pybind11Python 绑定实现。*.abi3.so/*.pyd形式输出和打包。cp310这一条 stable-ABI 基线。pybind11源码、依赖和工作流引用。本 PR 不包含:
设计方案
1. 整体运行时架构
迁移后的运行时可以拆成四层:
src/abi3_engine_backend.cpp使用 CPython limited API 暴露原生引擎能力,并通过
_ENGINE_BACKEND_API = "abi3-v1"标记 backend 协议版本。openviking/storage/vectordb/engine/_python_api.py在 Python 层重建
IndexEngine、PersistStore、VolatileStore、请求对象、结果对象和BytesRow包装。openviking/storage/vectordb/engine/__init__.py延续现有 variant 选择逻辑,负责加载正确的 backend 二进制,并在 legacy 导出模式和
abi3-v1导出模式之间切换。src/abi3_x86_caps.cpp独立承担 x86 CPU 能力探测,供 loader 在运行时自动选择
sse3、avx2、avx512后端。这样拆分后,C++ backend 只负责提供稳定、收敛的底层能力,Python API 兼容问题交给 Python 层适配。
2. Python API 兼容策略
本次迁移的关键设计是:不再让 C++ 直接导出复杂 Python 对象,而是改为暴露一套更窄、更稳定的 backend 协议,再由 Python 层重建对外 API。
具体做法:
_new_index_engine、_index_engine_search、_store_exec_op、_new_schema、_new_bytes_row等函数。openviking/storage/vectordb/engine/_python_api.py负责把这些原语重新封装成外部已有的 Python 类和结果对象。openviking/storage/vectordb/engine/__init__.py在发现 backend 暴露_ENGINE_BACKEND_API == "abi3-v1"时,调用build_abi3_exports(),并把重建后的符号注入模块命名空间。这样做的收益是:
pybind11风格的对象导出。openviking.storage.vectordb.engine。abi3-v1这种显式版本做增量兼容。3. 原生 backend 设计
新的 C++ backend 直接基于 CPython limited API 实现,核心点如下:
src/abi3_engine_backend.cpp和src/abi3_x86_caps.cpp都显式定义了Py_LIMITED_API=0x030A0000。OV_PY_MODULE_NAME生成不同的PyInit_<module>入口,使同一套实现可以产出_native、_x86_sse3、_x86_avx2、_x86_avx512等模块。PyEval_SaveThread/PyEval_RestoreThread包裹,释放 GIL。pybind11的对象绑定模式。这使 backend 更贴近 stable ABI 分发模型,也让模块初始化和导出边界更清晰。
4. backend 选择与加载行为
这次迁移刻意保持了原有 loader 的行为模型,降低运行时回归风险:
avx512 -> avx2 -> sse3。_native。OV_ENGINE_VARIANT仍然支持显式覆盖,但现在会同时校验“wheel 中是否打包了该 variant”以及“当前 CPU 是否支持该 variant”。importlib.machinery.EXTENSION_SUFFIXES中带abi3的后缀,再回退到常规 import。因此,运行时策略基本不变,变化主要在 backend 的装载方式和产物命名方式上。
5. 构建与打包设计
构建和打包链路的关键调整如下:
setup.py中的 engine extension 被标记为py_limited_api=True。bdist_wheel在 finalize 阶段设置py_limited_api = "cp310",把cp310作为 stable ABI wheel 的基线标签。setup.py和pyproject.toml的 package data 从storage/vectordb/engine/*.so调整为storage/vectordb/engine/*.abi3.so。abi3engine 二进制,避免陈旧产物混入 wheel。OV_PY_EXT_SUFFIX和OV_PY_OUTPUT_DIR传给 CMake,确保 CMake 生成的模块文件名和 wheel 预期严格对齐。这部分设计的目标是确保“构建系统、wheel 文件名、运行时加载逻辑”三者一致,不再混用旧的
.so语义。6. CI 与发布策略调整
CI / release 侧的策略也一起收敛:
.github/workflows/_build.yml和.github/workflows/release.yml的默认python_json都改成["3.10"]。pybind11。abi3扩展”。这个调整的核心思路是:既然 engine wheel 进入 stable ABI 分发模式,那么 release 默认矩阵就不应该继续按每个 CPython 小版本平铺。
关键代码整理
新增文件
src/abi3_engine_backend.cpp新的 stable-ABI backend,覆盖 engine、store、schema、bytes-row 等原生能力导出。
openviking/storage/vectordb/engine/_python_api.py新的 Python 兼容层,用于在 backend 原语之上重建对外 API。
src/abi3_x86_caps.cpp从旧的 CPU capability probe 演进而来,并改造成 limited API 扩展。
tests/misc/test_abi3_packaging_config.py覆盖 abi3 打包配置、workflow 默认值、
pybind11移除、limited API 预期等回归点。删除文件
src/pybind11_interface.cppsrc/py_accessors.hsrc/cpu_feature_probe.cpp重点更新文件
openviking/storage/vectordb/engine/__init__.py增强 loader,使其既能识别 abi3 backend,又能将 abi3 backend 桥接回 Python 命名空间。
setup.py切换到 limited-ABI wheel 配置,并处理旧产物清理。
src/CMakeLists.txt调整 variant backend 目标生成逻辑,统一产出 limited-API 模块。
.github/workflows/_build.yml与.github/workflows/release.yml默认 Python 矩阵收敛,构建依赖移除
pybind11。兼容性说明
openviking.storage.vectordb.engine。pybind11时代遗留但不再需要的导出被移除,例如FetchDataResult。风险与关注点
abi3-v1现在成为 C++ 与 Python 之间的关键协议边界,后续 backend 变更必须同步维护_python_api.py。pybind11屏蔽细节,因此需要更明确的回归测试保护。后续建议
cp310-abi3wheel 在多个受支持 CPython 版本下都能安装和加载。abi3-v1backend 协议单独文档化,降低后续维护成本。.pyd产物命名与加载的独立检查。验证结果
已执行:
结果:
10 passedReviewer 建议阅读顺序
src/abi3_engine_backend.cppopenviking/storage/vectordb/engine/_python_api.pyopenviking/storage/vectordb/engine/__init__.pysetup.pysrc/CMakeLists.txttests/misc/test_abi3_packaging_config.pytests/misc/test_vectordb_engine_loader.py