Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions packages/embed-llamacpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ find_package(cmake-vcpkg REQUIRED PATHS node_modules/cmake-vcpkg)

set(VCPKG_OVERLAY_TRIPLETS "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/triplets;${VCPKG_OVERLAY_TRIPLETS}")

# Local overlay-port for fabric (turbovec POC). The overlay at
# `vcpkg/ports/qvac-fabric/` carries the POC fabric build because the public
# `tetherto/qvac-registry-vcpkg` qvac-fabric port has no 8828.x line yet and
# this manifest pins `>=8828.1.0`. By default the overlay fetches from
# `dev-nid/qvac-fabric-llm.cpp` (poc/turbovec-embed branch) at a pinned
# commit + SHA512. Drop this overlay once the registry publishes 8828.x.
#
# Local-iteration override: set `QVAC_FABRIC_LOCAL_PATH=/path/to/fabric` to
# build from a working tree instead. In that mode, run
# `./scripts/sync-fabric-overlay.sh` after each edit to bump the
# portfile-tracked source hash (vcpkg derives ABI from portfile contents,
# not from the source it copies in). `./scripts/rebuild-fabric.sh` chains
# sync + generate + build + install for the inner-loop case.
set(VCPKG_OVERLAY_PORTS "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/ports;${VCPKG_OVERLAY_PORTS}")

project(embed-llamacpp C CXX)

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
Expand Down Expand Up @@ -68,20 +83,46 @@ target_sources(
${embed-llamacpp}
PRIVATE
${PROJECT_SOURCE_DIR}/addon/src/js-interface/binding.cpp
${PROJECT_SOURCE_DIR}/addon/src/js-interface/vector-index-binding.cpp
${PROJECT_SOURCE_DIR}/addon/src/model-interface/utils.cpp
${PROJECT_SOURCE_DIR}/addon/src/model-interface/AsyncWeightsLoader.cpp
${PROJECT_SOURCE_DIR}/addon/src/model-interface/BackendSelection.cpp
${PROJECT_SOURCE_DIR}/addon/src/model-interface/logging.cpp
${PROJECT_SOURCE_DIR}/addon/src/model-interface/LlamaLazyInitializeBackend.cpp
${PROJECT_SOURCE_DIR}/addon/src/model-interface/ModelMetadata.cpp
${PROJECT_SOURCE_DIR}/addon/src/model-interface/BertModel.cpp
${PROJECT_SOURCE_DIR}/addon/src/model-interface/VectorIndex.cpp
)
target_include_directories(
${embed-llamacpp}
PRIVATE
${QVAC_LIB_INFERENCE_ADDON_CPP_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/addon/src
)
# Some fabric branches (HEAD-ish) only export the `llama` target without
# namespacing and without exporting the `llama-common` helper lib at all.
# The `temp-8828` branch exports the full `llama::*` namespace incl.
# `llama::common`. Add a shim only when the expected targets are missing.
if(TARGET llama AND NOT TARGET llama::llama)
add_library(llama::llama ALIAS llama)
endif()
if(NOT TARGET llama::common)
if(NOT TARGET llama-common)
find_library(LLAMA_COMMON_LIB
NAMES llama-common
REQUIRED
HINTS ${LLAMA_LIB_DIR}
NO_CMAKE_FIND_ROOT_PATH)
add_library(llama-common UNKNOWN IMPORTED)
set_target_properties(llama-common
PROPERTIES
IMPORTED_LOCATION "${LLAMA_COMMON_LIB}"
INTERFACE_INCLUDE_DIRECTORIES "${LLAMA_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "llama")
endif()
add_library(llama::common ALIAS llama-common)
endif()

target_link_libraries(
${embed-llamacpp}
PRIVATE
Expand Down
42 changes: 42 additions & 0 deletions packages/embed-llamacpp/addon/src/addon/VectorIndexErrors.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once
//
// Maps fabric vector-index C error codes to JS-throwable messages. Mirrors
// the layout of `BertErrors.hpp` but for the ANN index path. Kept in its own
// header so the binding can include it without dragging in any BertModel /
// LlamaLazyInitializeBackend symbols (lifecycle isolation requirement of
// the POC).

#include <ggml-vector-index.h>

#include <string>

namespace qvac_lib_infer_llamacpp_embed::vector_index_errors {

constexpr const char* ADDON_ID = "IdMapIndex";

inline std::string toString(int code) {
switch (code) {
case GGML_VEC_INDEX_OK:
return "OK";
case GGML_VEC_INDEX_E_INVALID_DIM:
return "InvalidDim";
case GGML_VEC_INDEX_E_INVALID_ARG:
return "InvalidArgument";
case GGML_VEC_INDEX_E_DUPLICATE:
return "DuplicateId";
case GGML_VEC_INDEX_E_IO:
return "IOError";
case GGML_VEC_INDEX_E_BAD_MAGIC:
return "BadMagic";
case GGML_VEC_INDEX_E_BAD_VERSION:
return "BadVersion";
case GGML_VEC_INDEX_E_OOM:
return "OutOfMemory";
case GGML_VEC_INDEX_E_INTERNAL:
return "InternalError";
default:
return "UnknownError";
}
}

} // namespace qvac_lib_infer_llamacpp_embed::vector_index_errors
11 changes: 11 additions & 0 deletions packages/embed-llamacpp/addon/src/js-interface/binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

#include "../addon/AddonJs.hpp"

// Forward declaration for the IdMapIndex (vector-index) binding registrar.
// The implementation lives in `vector-index-binding.cpp` and is deliberately
// kept in its own TU so it has no symbol dependency on BertModel /
// LlamaLazyInitializeBackend — required for the POC's lifecycle-isolation
// invariant (constructing IdMapIndex must not boot fabric's LLM backend).
namespace qvac_lib_inference_addon_embed::vector_index {
void registerBindings(js_env_t* env, js_value_t* exports);
}

js_value_t*
qvacLibInferLlamacppEmbedExports(js_env_t* env, js_value_t* exports) {

Expand Down Expand Up @@ -30,6 +39,8 @@ qvacLibInferLlamacppEmbedExports(js_env_t* env, js_value_t* exports) {
#undef V
// NOLINTEND(cppcoreguidelines-macro-usage)

qvac_lib_inference_addon_embed::vector_index::registerBindings(env, exports);

return exports;
}

Expand Down
Loading
Loading