zvec 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +20 -10
- data/ext/CMakeLists.txt +127 -91
- data/ext/build/macos-debug/CMakeCache.txt +7 -1
- data/lib/zvec/collection.rb +5 -5
- data/lib/zvec/doc.rb +5 -1
- data/lib/zvec/version.rb +3 -1
- data/lib/zvec.rb +18 -7
- metadata +9 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d6f88eba541a4d535d54a2b8b43f0852ddfaa3c2b58ff41885ba51ae405c8428
|
|
4
|
+
data.tar.gz: 0d383b42d8961c566f47f8763cdcdb19788b627e5a41087e10779080d5969d97
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 520389cf9f9394f982e367de3e08ad731c5b188b60efe4c863937742c823384dc05541e890f95d267bcd710dc4263300061978d546856148fd8f4ab1e29c661f
|
|
7
|
+
data.tar.gz: '08866c1988ec0ed47a040ac9be95b4d15098f31dec925da3e25e62beffb3b828ae51c55ccb7aedd31a2ca7a08b84a537eb10299cf976ecc9045590a722906f33'
|
data/README.md
CHANGED
|
@@ -29,36 +29,46 @@
|
|
|
29
29
|
Ruby bindings for Alibaba's [zvec](https://github.com/alibaba/zvec) C++ vector database library. Store, index, and query high-dimensional vectors alongside scalar metadata — all from Ruby. The native extension uses [Rice](https://github.com/ruby-rice/rice) (v4.11) for C++/Ruby interop and CMake for building. The zvec C++ source is included as a git submodule.
|
|
30
30
|
|
|
31
31
|
> [!CAUTION]
|
|
32
|
-
>
|
|
32
|
+
> Without the Homebrew formula, `gem install zvec` compiles the entire zvec C++ dependency tree from source (~10 minutes). Pre-building with Homebrew reduces this to ~10 seconds. The source build may not work on all platforms.
|
|
33
33
|
|
|
34
34
|
## Prerequisites
|
|
35
35
|
|
|
36
36
|
- Ruby >= 3.2.0
|
|
37
37
|
- CMake >= 3.26
|
|
38
38
|
- A C++17 compiler (Clang or GCC)
|
|
39
|
-
- ICU4C: `brew install icu4c@78` (macOS
|
|
39
|
+
- ICU4C: `brew install icu4c@78` (macOS)
|
|
40
40
|
|
|
41
41
|
## Installation
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
### Recommended: Pre-build with Homebrew (fast)
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
Pre-building the zvec C++ library avoids a lengthy source compilation during gem install:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
brew tap madbomber/zvec https://github.com/MadBomber/zvec-ruby.git
|
|
49
|
+
brew install madbomber/zvec/zvec
|
|
50
|
+
gem install zvec # ~10 seconds
|
|
47
51
|
```
|
|
48
52
|
|
|
49
|
-
|
|
53
|
+
### Alternative: Build from source (slow)
|
|
54
|
+
|
|
55
|
+
Without Homebrew, the gem fetches and compiles the full C++ dependency tree (~10 minutes):
|
|
50
56
|
|
|
51
57
|
```bash
|
|
52
|
-
|
|
53
|
-
cd ext && cmake --preset macos-release && cmake --build build/macos-release && cd ..
|
|
58
|
+
gem install zvec
|
|
54
59
|
```
|
|
55
60
|
|
|
56
|
-
|
|
61
|
+
### Development (from source checkout)
|
|
57
62
|
|
|
58
63
|
```bash
|
|
59
|
-
|
|
64
|
+
git clone --recurse-submodules https://github.com/MadBomber/zvec-ruby.git
|
|
65
|
+
cd zvec-ruby
|
|
66
|
+
bundle install
|
|
67
|
+
cd ext && cmake --preset macos-release && cmake --build build/macos-release && cd ..
|
|
60
68
|
```
|
|
61
69
|
|
|
70
|
+
For debug builds use the `macos-debug` preset instead.
|
|
71
|
+
|
|
62
72
|
## Quick Start
|
|
63
73
|
|
|
64
74
|
```ruby
|
data/ext/CMakeLists.txt
CHANGED
|
@@ -34,79 +34,105 @@ FetchContent_MakeAvailable(rice)
|
|
|
34
34
|
list(PREPEND CMAKE_MODULE_PATH "${rice_SOURCE_DIR}")
|
|
35
35
|
find_package(Ruby REQUIRED COMPONENTS Development)
|
|
36
36
|
|
|
37
|
-
#
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
# ---
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
# ============================================================================
|
|
38
|
+
# Three-tier zvec resolution:
|
|
39
|
+
# 1. Pre-installed library (e.g., brew install zvec) — fast path
|
|
40
|
+
# 2. Local git submodule at vendor/zvec — development path
|
|
41
|
+
# 3. FetchContent from GitHub — fallback for gem install without Homebrew
|
|
42
|
+
# ============================================================================
|
|
43
|
+
|
|
44
|
+
# --- Strategy 1: Find pre-installed zvec (e.g., from Homebrew) ---
|
|
45
|
+
find_library(ZVEC_LIBRARY zvec
|
|
46
|
+
HINTS /opt/homebrew/opt/zvec/lib
|
|
47
|
+
/usr/local/opt/zvec/lib
|
|
48
|
+
ENV ZVEC_DIR
|
|
49
|
+
)
|
|
50
|
+
find_path(ZVEC_INCLUDE_DIR zvec/db/collection.h
|
|
51
|
+
HINTS /opt/homebrew/opt/zvec/include
|
|
52
|
+
/usr/local/opt/zvec/include
|
|
53
|
+
ENV ZVEC_DIR
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
if(ZVEC_LIBRARY AND ZVEC_INCLUDE_DIR)
|
|
57
|
+
message(STATUS "Found pre-installed zvec: ${ZVEC_LIBRARY}")
|
|
58
|
+
message(STATUS " includes: ${ZVEC_INCLUDE_DIR}")
|
|
59
|
+
set(ZVEC_PREBUILT TRUE)
|
|
51
60
|
else()
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
set(ZVEC_PREBUILT FALSE)
|
|
62
|
+
|
|
63
|
+
# Disable parts of zvec we don't need (must be set before add_subdirectory)
|
|
64
|
+
set(BUILD_PYTHON_BINDINGS OFF CACHE BOOL "" FORCE)
|
|
65
|
+
set(BUILD_TOOLS OFF CACHE BOOL "" FORCE)
|
|
66
|
+
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
|
|
67
|
+
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
|
|
68
|
+
set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
|
|
69
|
+
|
|
70
|
+
# --- Strategy 2: Local submodule (development) ---
|
|
71
|
+
set(_ZVEC_LOCAL "${CMAKE_CURRENT_SOURCE_DIR}/../vendor/zvec")
|
|
72
|
+
|
|
73
|
+
if(EXISTS "${_ZVEC_LOCAL}/CMakeLists.txt")
|
|
74
|
+
message(STATUS "Using local zvec from ${_ZVEC_LOCAL}")
|
|
75
|
+
set(ZVEC_ROOT "${_ZVEC_LOCAL}")
|
|
76
|
+
else()
|
|
77
|
+
# --- Strategy 3: FetchContent from GitHub ---
|
|
78
|
+
message(STATUS "vendor/zvec not found — fetching from GitHub")
|
|
79
|
+
FetchContent_Declare(
|
|
80
|
+
zvec_src
|
|
81
|
+
GIT_REPOSITORY https://github.com/alibaba/zvec.git
|
|
82
|
+
GIT_TAG 232803611ea91abc96904a92c878c4c67ddf73e6
|
|
83
|
+
GIT_SHALLOW FALSE
|
|
84
|
+
GIT_SUBMODULES_RECURSE TRUE
|
|
85
|
+
)
|
|
86
|
+
FetchContent_GetProperties(zvec_src)
|
|
87
|
+
if(NOT zvec_src_POPULATED)
|
|
88
|
+
FetchContent_Populate(zvec_src)
|
|
89
|
+
endif()
|
|
90
|
+
set(ZVEC_ROOT "${zvec_src_SOURCE_DIR}")
|
|
91
|
+
|
|
92
|
+
# zvec's subdirectory CMakeLists expect cmake/ relative to CMAKE_SOURCE_DIR
|
|
93
|
+
# (in development, ext/cmake is a symlink to ../vendor/zvec/cmake)
|
|
94
|
+
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake/bazel.cmake")
|
|
95
|
+
file(COPY "${ZVEC_ROOT}/cmake/" DESTINATION "${CMAKE_SOURCE_DIR}/cmake/")
|
|
96
|
+
endif()
|
|
64
97
|
endif()
|
|
65
|
-
set(ZVEC_ROOT "${zvec_src_SOURCE_DIR}")
|
|
66
98
|
|
|
67
|
-
# zvec
|
|
68
|
-
|
|
69
|
-
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake/bazel.cmake")
|
|
70
|
-
file(COPY "${ZVEC_ROOT}/cmake/" DESTINATION "${CMAKE_SOURCE_DIR}/cmake/")
|
|
71
|
-
endif()
|
|
72
|
-
endif()
|
|
99
|
+
# zvec uses PROJECT_ROOT_DIR internally
|
|
100
|
+
set(PROJECT_ROOT_DIR "${ZVEC_ROOT}" CACHE PATH "" FORCE)
|
|
73
101
|
|
|
74
|
-
#
|
|
75
|
-
|
|
102
|
+
# Forward CMAKE_PREFIX_PATH to Arrow's ExternalProject_Add via CMAKE_CACHE_ARGS
|
|
103
|
+
# (Arrow's CONFIGURE_COMMAND interpolates ${CMAKE_CACHE_ARGS} but it's unset by default)
|
|
104
|
+
if(CMAKE_PREFIX_PATH)
|
|
105
|
+
set(CMAKE_CACHE_ARGS "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}")
|
|
106
|
+
endif()
|
|
76
107
|
|
|
77
|
-
#
|
|
78
|
-
#
|
|
79
|
-
|
|
80
|
-
set(
|
|
81
|
-
|
|
108
|
+
# --- Fix antlr4 CMakeLists.txt for CMake 4.x compatibility ---
|
|
109
|
+
# zvec's own patch (antlr4.patch) runs first via apply_patch_once(), but it doesn't
|
|
110
|
+
# fix the OLD policies that CMake 4.x removed. We apply additional fixups here.
|
|
111
|
+
set(_antlr4_cmake "${ZVEC_ROOT}/thirdparty/antlr/antlr4/runtime/Cpp/CMakeLists.txt")
|
|
112
|
+
set(_antlr4_cmake4_mark "${ZVEC_ROOT}/thirdparty/antlr/antlr4/.cmake4_compat_patched")
|
|
113
|
+
if(NOT EXISTS "${_antlr4_cmake4_mark}" AND EXISTS "${_antlr4_cmake}")
|
|
114
|
+
file(READ "${_antlr4_cmake}" _antlr4_content)
|
|
115
|
+
# Fix cmake_minimum_required to 3.5
|
|
116
|
+
string(REPLACE "cmake_minimum_required (VERSION 2.8)" "cmake_minimum_required (VERSION 3.5)" _antlr4_content "${_antlr4_content}")
|
|
117
|
+
# Remove OLD policy settings (CMake 4.x removed these)
|
|
118
|
+
string(REPLACE " CMAKE_POLICY(SET CMP0054 OLD)\n CMAKE_POLICY(SET CMP0045 OLD)\n CMAKE_POLICY(SET CMP0042 OLD)\n" "" _antlr4_content "${_antlr4_content}")
|
|
119
|
+
string(REPLACE " CMAKE_POLICY(SET CMP0059 OLD)\n CMAKE_POLICY(SET CMP0054 OLD)\n" "" _antlr4_content "${_antlr4_content}")
|
|
120
|
+
# Fix old-style endif() with arguments
|
|
121
|
+
string(REPLACE "endif(NOT CMAKE_BUILD_TYPE)" "endif()" _antlr4_content "${_antlr4_content}")
|
|
122
|
+
string(REPLACE "endif(NOT WITH_DEMO)" "endif()" _antlr4_content "${_antlr4_content}")
|
|
123
|
+
string(REPLACE "endif(WITH_DEMO)" "endif()" _antlr4_content "${_antlr4_content}")
|
|
124
|
+
string(REPLACE "endif(WIN32)" "endif()" _antlr4_content "${_antlr4_content}")
|
|
125
|
+
string(REPLACE "if(NOT ANTLR4_CMAKE_DIR)" "if(NOT DEFINED ANTLR4_CMAKE_DIR OR NOT ANTLR4_CMAKE_DIR)" _antlr4_content "${_antlr4_content}")
|
|
126
|
+
string(REPLACE "endif(NOT ANTLR4_CMAKE_DIR)" "endif()" _antlr4_content "${_antlr4_content}")
|
|
127
|
+
string(REPLACE "endif(ANTLR4_INSTALL)" "endif()" _antlr4_content "${_antlr4_content}")
|
|
128
|
+
file(WRITE "${_antlr4_cmake}" "${_antlr4_content}")
|
|
129
|
+
file(WRITE "${_antlr4_cmake4_mark}" "patched")
|
|
130
|
+
message(STATUS "Applied CMake 4.x compatibility fixes to antlr4")
|
|
131
|
+
endif()
|
|
82
132
|
|
|
83
|
-
|
|
84
|
-
# zvec's own patch (antlr4.patch) runs first via apply_patch_once(), but it doesn't
|
|
85
|
-
# fix the OLD policies that CMake 4.x removed. We apply additional fixups here.
|
|
86
|
-
set(_antlr4_cmake "${ZVEC_ROOT}/thirdparty/antlr/antlr4/runtime/Cpp/CMakeLists.txt")
|
|
87
|
-
set(_antlr4_cmake4_mark "${ZVEC_ROOT}/thirdparty/antlr/antlr4/.cmake4_compat_patched")
|
|
88
|
-
if(NOT EXISTS "${_antlr4_cmake4_mark}" AND EXISTS "${_antlr4_cmake}")
|
|
89
|
-
file(READ "${_antlr4_cmake}" _antlr4_content)
|
|
90
|
-
# Fix cmake_minimum_required to 3.5
|
|
91
|
-
string(REPLACE "cmake_minimum_required (VERSION 2.8)" "cmake_minimum_required (VERSION 3.5)" _antlr4_content "${_antlr4_content}")
|
|
92
|
-
# Remove OLD policy settings (CMake 4.x removed these)
|
|
93
|
-
string(REPLACE " CMAKE_POLICY(SET CMP0054 OLD)\n CMAKE_POLICY(SET CMP0045 OLD)\n CMAKE_POLICY(SET CMP0042 OLD)\n" "" _antlr4_content "${_antlr4_content}")
|
|
94
|
-
string(REPLACE " CMAKE_POLICY(SET CMP0059 OLD)\n CMAKE_POLICY(SET CMP0054 OLD)\n" "" _antlr4_content "${_antlr4_content}")
|
|
95
|
-
# Fix old-style endif() with arguments
|
|
96
|
-
string(REPLACE "endif(NOT CMAKE_BUILD_TYPE)" "endif()" _antlr4_content "${_antlr4_content}")
|
|
97
|
-
string(REPLACE "endif(NOT WITH_DEMO)" "endif()" _antlr4_content "${_antlr4_content}")
|
|
98
|
-
string(REPLACE "endif(WITH_DEMO)" "endif()" _antlr4_content "${_antlr4_content}")
|
|
99
|
-
string(REPLACE "endif(WIN32)" "endif()" _antlr4_content "${_antlr4_content}")
|
|
100
|
-
string(REPLACE "if(NOT ANTLR4_CMAKE_DIR)" "if(NOT DEFINED ANTLR4_CMAKE_DIR OR NOT ANTLR4_CMAKE_DIR)" _antlr4_content "${_antlr4_content}")
|
|
101
|
-
string(REPLACE "endif(NOT ANTLR4_CMAKE_DIR)" "endif()" _antlr4_content "${_antlr4_content}")
|
|
102
|
-
string(REPLACE "endif(ANTLR4_INSTALL)" "endif()" _antlr4_content "${_antlr4_content}")
|
|
103
|
-
file(WRITE "${_antlr4_cmake}" "${_antlr4_content}")
|
|
104
|
-
file(WRITE "${_antlr4_cmake4_mark}" "patched")
|
|
105
|
-
message(STATUS "Applied CMake 4.x compatibility fixes to antlr4")
|
|
133
|
+
add_subdirectory("${ZVEC_ROOT}" "${CMAKE_CURRENT_BINARY_DIR}/zvec" EXCLUDE_FROM_ALL)
|
|
106
134
|
endif()
|
|
107
135
|
|
|
108
|
-
add_subdirectory("${ZVEC_ROOT}" "${CMAKE_CURRENT_BINARY_DIR}/zvec" EXCLUDE_FROM_ALL)
|
|
109
|
-
|
|
110
136
|
# --- Ruby extension module ---
|
|
111
137
|
add_library(zvec_ext MODULE
|
|
112
138
|
zvec/zvec_ext.cpp
|
|
@@ -119,38 +145,48 @@ add_library(zvec_ext MODULE
|
|
|
119
145
|
zvec/zvec_config.cpp
|
|
120
146
|
)
|
|
121
147
|
|
|
122
|
-
target_include_directories(zvec_ext PRIVATE
|
|
123
|
-
"${rice_SOURCE_DIR}/include"
|
|
124
|
-
"${ZVEC_ROOT}/src/include"
|
|
125
|
-
"${ZVEC_ROOT}/src"
|
|
126
|
-
)
|
|
127
|
-
|
|
128
148
|
# Link Rice (header-only) and Ruby
|
|
129
149
|
target_link_libraries(zvec_ext PRIVATE Rice::Rice)
|
|
130
150
|
target_link_libraries(zvec_ext PRIVATE Ruby::Module)
|
|
131
151
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
152
|
+
if(ZVEC_PREBUILT)
|
|
153
|
+
# --- Fast path: link against pre-installed fat static archive ---
|
|
154
|
+
target_include_directories(zvec_ext PRIVATE
|
|
155
|
+
"${rice_SOURCE_DIR}/include"
|
|
156
|
+
"${ZVEC_INCLUDE_DIR}"
|
|
157
|
+
)
|
|
158
|
+
target_link_libraries(zvec_ext PRIVATE -Wl,-force_load,${ZVEC_LIBRARY})
|
|
159
|
+
else()
|
|
160
|
+
# --- Source build: link against individual zvec targets ---
|
|
161
|
+
target_include_directories(zvec_ext PRIVATE
|
|
162
|
+
"${rice_SOURCE_DIR}/include"
|
|
163
|
+
"${ZVEC_ROOT}/src/include"
|
|
164
|
+
"${ZVEC_ROOT}/src"
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
# Algorithm libraries that need force-loading for self-registration
|
|
168
|
+
set(ZVEC_ALGO_LIBS
|
|
169
|
+
core_knn_flat_static
|
|
170
|
+
core_knn_flat_sparse_static
|
|
171
|
+
core_knn_hnsw_static
|
|
172
|
+
core_knn_hnsw_sparse_static
|
|
173
|
+
core_knn_ivf_static
|
|
174
|
+
core_knn_cluster_static
|
|
175
|
+
core_mix_reducer_static
|
|
176
|
+
core_metric_static
|
|
177
|
+
core_utility_static
|
|
178
|
+
core_quantizer_static
|
|
179
|
+
)
|
|
145
180
|
|
|
146
|
-
# Explicit dependency so EXCLUDE_FROM_ALL targets get built
|
|
147
|
-
add_dependencies(zvec_ext ${ZVEC_ALGO_LIBS} zvec_db)
|
|
181
|
+
# Explicit dependency so EXCLUDE_FROM_ALL targets get built
|
|
182
|
+
add_dependencies(zvec_ext ${ZVEC_ALGO_LIBS} zvec_db)
|
|
148
183
|
|
|
149
|
-
# Force-link zvec algorithm libraries (macOS) — required for self-registering algorithms
|
|
150
|
-
foreach(lib ${ZVEC_ALGO_LIBS})
|
|
151
|
-
|
|
152
|
-
endforeach()
|
|
153
|
-
target_link_libraries(zvec_ext PRIVATE zvec_db)
|
|
184
|
+
# Force-link zvec algorithm libraries (macOS) — required for self-registering algorithms
|
|
185
|
+
foreach(lib ${ZVEC_ALGO_LIBS})
|
|
186
|
+
target_link_libraries(zvec_ext PRIVATE -Wl,-force_load,$<TARGET_FILE:${lib}>)
|
|
187
|
+
endforeach()
|
|
188
|
+
target_link_libraries(zvec_ext PRIVATE zvec_db)
|
|
189
|
+
endif()
|
|
154
190
|
|
|
155
191
|
# Output directory: use CMAKE_LIBRARY_OUTPUT_DIRECTORY if set by RubyGems,
|
|
156
192
|
# otherwise default to the local lib/ directory (development builds)
|
|
@@ -22,7 +22,7 @@ BENCHMARK_ENABLE_INSTALL:BOOL=OFF
|
|
|
22
22
|
BENCHMARK_ENABLE_TESTING:BOOL=OFF
|
|
23
23
|
|
|
24
24
|
//the time we first built rocksdb
|
|
25
|
-
BUILD_DATE:STRING=2026-02-27
|
|
25
|
+
BUILD_DATE:STRING=2026-02-27 07:18:37
|
|
26
26
|
|
|
27
27
|
//Builds the googlemock subproject
|
|
28
28
|
BUILD_GMOCK:BOOL=ON
|
|
@@ -819,6 +819,12 @@ ZLIB_LIBRARY_DEBUG:FILEPATH=ZLIB_LIBRARY_DEBUG-NOTFOUND
|
|
|
819
819
|
//Path to a library.
|
|
820
820
|
ZLIB_LIBRARY_RELEASE:FILEPATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libz.tbd
|
|
821
821
|
|
|
822
|
+
//Path to a file.
|
|
823
|
+
ZVEC_INCLUDE_DIR:PATH=ZVEC_INCLUDE_DIR-NOTFOUND
|
|
824
|
+
|
|
825
|
+
//Path to a library.
|
|
826
|
+
ZVEC_LIBRARY:FILEPATH=ZVEC_LIBRARY-NOTFOUND
|
|
827
|
+
|
|
822
828
|
//Ruby extensions extension
|
|
823
829
|
_Ruby_DLEXT:STRING=bundle
|
|
824
830
|
|
data/lib/zvec/collection.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Zvec
|
|
2
4
|
module CollectionConvenience
|
|
3
5
|
# Convenience: build a VectorQuery and execute it
|
|
@@ -22,10 +24,8 @@ module Zvec
|
|
|
22
24
|
# Block-form open: yields the collection and flushes on block exit
|
|
23
25
|
def self.open_collection(path, options: nil)
|
|
24
26
|
col = Collection.open(path, options)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
col.flush
|
|
29
|
-
end
|
|
27
|
+
yield col
|
|
28
|
+
ensure
|
|
29
|
+
col&.flush
|
|
30
30
|
end
|
|
31
31
|
end
|
data/lib/zvec/doc.rb
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Zvec
|
|
2
4
|
class Doc
|
|
3
|
-
# Convert doc fields to a Ruby Hash
|
|
5
|
+
# Convert doc fields to a Ruby Hash. The schema parameter is required because
|
|
6
|
+
# the C++ layer stores fields as type-erased values — the FieldSchema's data_type
|
|
7
|
+
# selects the correct deserialization path (get_field dispatches on it).
|
|
4
8
|
def to_h(schema)
|
|
5
9
|
result = {"pk" => pk, "score" => score}
|
|
6
10
|
field_names.each do |name|
|
data/lib/zvec/version.rb
CHANGED
data/lib/zvec.rb
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative "zvec/version"
|
|
2
4
|
require "zvec_ext"
|
|
3
5
|
require_relative "zvec/collection"
|
|
4
6
|
require_relative "zvec/doc"
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
module Zvec
|
|
9
|
+
# Rice wraps shared_ptr<Collection> as Std::SharedPtr<zvec::Collection>,
|
|
10
|
+
# a proxy class that delegates C++ methods via method_missing. Ruby
|
|
11
|
+
# convenience methods must be included into this wrapper class, not
|
|
12
|
+
# Zvec::Collection itself. We cannot use const_get because the wrapper
|
|
13
|
+
# class name contains C++ mangled type parameters (e.g. angle brackets).
|
|
14
|
+
def self.patch_shared_ptr_wrapper!
|
|
15
|
+
ObjectSpace.each_object(Class) do |klass|
|
|
16
|
+
if klass.name&.start_with?("Std::SharedPtr") && klass.name&.include?("Collection")
|
|
17
|
+
klass.include(Zvec::CollectionConvenience)
|
|
18
|
+
return klass
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
nil
|
|
13
22
|
end
|
|
14
23
|
end
|
|
24
|
+
|
|
25
|
+
Zvec.patch_shared_ptr_wrapper!
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zvec
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dewayne VanHoozer
|
|
@@ -38539,6 +38539,12 @@ metadata:
|
|
|
38539
38539
|
homepage_uri: https://github.com/MadBomber/zvec
|
|
38540
38540
|
source_code_uri: https://github.com/MadBomber/zvec
|
|
38541
38541
|
changelog_uri: https://github.com/MadBomber/zvec/blob/main/CHANGELOG.md
|
|
38542
|
+
post_install_message: |
|
|
38543
|
+
zvec installed successfully!
|
|
38544
|
+
|
|
38545
|
+
Tip: For faster future installs, pre-build the C++ library with Homebrew:
|
|
38546
|
+
brew tap madbomber/zvec https://github.com/MadBomber/zvec-ruby.git
|
|
38547
|
+
brew install madbomber/zvec/zvec
|
|
38542
38548
|
rdoc_options: []
|
|
38543
38549
|
require_paths:
|
|
38544
38550
|
- lib
|
|
@@ -38546,14 +38552,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
38546
38552
|
requirements:
|
|
38547
38553
|
- - ">="
|
|
38548
38554
|
- !ruby/object:Gem::Version
|
|
38549
|
-
version:
|
|
38555
|
+
version: '4.0'
|
|
38550
38556
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38551
38557
|
requirements:
|
|
38552
38558
|
- - ">="
|
|
38553
38559
|
- !ruby/object:Gem::Version
|
|
38554
38560
|
version: '0'
|
|
38555
38561
|
requirements: []
|
|
38556
|
-
rubygems_version: 4.0.
|
|
38562
|
+
rubygems_version: 4.0.7
|
|
38557
38563
|
specification_version: 4
|
|
38558
38564
|
summary: EXPERIMENTAL - DO NOT INSTALL - Ruby bindings for Alibaba zvec vector database
|
|
38559
38565
|
test_files: []
|