Skip to content
Draft
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
43 changes: 43 additions & 0 deletions packages/embed-llamacpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ find_package(cmake-vcpkg REQUIRED PATHS node_modules/cmake-vcpkg)

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

# Local overlay-port for fabric (turbovec). The overlay at
# `vcpkg/ports/qvac-fabric/` carries the vector-index fabric build until the
# public `tetherto/qvac-registry-vcpkg` qvac-fabric port publishes the same
# turbovec changes. By default the overlay fetches from
# `dev-nid/qvac-fabric-llm.cpp` (turbovec branch) at a pinned commit + SHA512.
#
# 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 +82,49 @@ 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
)
# Fabric branches differ in how they export llama targets. Normalize the
# targets this addon links against, preferring exported namespace targets and
# falling back only for older ports.
if(TARGET llama AND NOT TARGET llama::llama)
add_library(llama::llama ALIAS llama)
endif()
if(NOT TARGET llama::common)
if(TARGET llama::llama-common)
add_library(llama::common ALIAS llama::llama-common)
elseif(TARGET llama-common)
add_library(llama::common ALIAS llama-common)
else()
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::llama")
add_library(llama::common ALIAS llama-common)
endif()
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