Skip to content

Commit b9d717b

Browse files
committed
Update shared example to support pip/conda lib
1 parent b3558f0 commit b9d717b

File tree

2 files changed

+66
-17
lines changed

2 files changed

+66
-17
lines changed

examples/cpp/shared/CMakeLists.txt

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,28 @@ project(svs_shared_library_example
1818
LANGUAGES CXX
1919
)
2020

21-
# Other AVX versions can be found at https://github.com/intel/ScalableVectorSearch/releases.
22-
set(SVS_URL "https://github.com/intel/ScalableVectorSearch/releases/download/v0.0.9/svs-shared-library-0.0.9.tar.gz")
23-
24-
include(FetchContent)
25-
FetchContent_Declare(
26-
svs
27-
URL "${SVS_URL}"
28-
)
29-
FetchContent_MakeAvailable(svs)
30-
31-
list(APPEND CMAKE_PREFIX_PATH "${svs_SOURCE_DIR}")
32-
find_package(svs REQUIRED)
33-
find_library(SVS_SHARED svs_shared_library)
21+
# Try to find SVS from system/conda/pip installation first
22+
find_package(svs QUIET)
23+
24+
if(NOT svs_FOUND)
25+
# If sourcing from pip/conda, the following steps are not necessary, simplifying workflow
26+
# If not found, download tarball from GitHub release and follow steps to fetch and find
27+
set(SVS_URL "https://github.com/intel/ScalableVectorSearch/releases/download/v0.0.9/svs-shared-library-0.0.9.tar.gz")
28+
29+
message(STATUS "SVS not found in system, downloading from: ${SVS_URL}")
30+
31+
include(FetchContent)
32+
FetchContent_Declare(
33+
svs
34+
URL "${SVS_URL}"
35+
)
36+
FetchContent_MakeAvailable(svs)
37+
38+
list(APPEND CMAKE_PREFIX_PATH "${svs_SOURCE_DIR}")
39+
find_package(svs REQUIRED)
40+
else()
41+
message(STATUS "Found SVS: ${svs_DIR}")
42+
endif()
3443

3544
set(SVS_CXX_STANDARD 20)
3645
SET(CMAKE_CXX_FLAGS "-O3 -DNDEBUG -std=gnu++20 -march=native -mtune=native -Werror -Wall -Wextra -Wpedantic" )
@@ -41,7 +50,10 @@ set(DATA_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../../data/test_dataset")
4150
function(create_example_executable exe file)
4251
add_executable(${exe} ${file})
4352
target_compile_definitions(${exe} PRIVATE SVS_DATA_DIR="${DATA_DIRECTORY}")
44-
target_link_libraries(${exe} PUBLIC ${SVS_SHARED} svs::svs)
53+
target_link_libraries(${exe} PUBLIC
54+
svs::svs_shared_library
55+
svs::svs
56+
)
4557
endfunction()
4658

4759
create_example_executable(shared shared.cpp)

examples/cpp/shared/README.md

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,54 @@
1414
~ limitations under the License.
1515
-->
1616

17-
These examples utilize LVQ and LeanVec interfaces which are available when linking to a SVS shared/static library, which are published with [releases](https://github.com/intel/ScalableVectorSearch/releases). Note that these examples will _not_ run after building the open source codebase without the shared/static library. These examples include:
17+
These examples utilize LVQ and LeanVec interfaces which are available when linking to a SVS shared/static library, which are published with [releases](https://github.com/intel/ScalableVectorSearch/releases), as a tarball, pip wheel, or conda package. Note that these examples will _not_ run after building the open source codebase without the shared/static library. These examples include:
1818
- [example_vamana_with_compression.cpp](./example_vamana_with_compression.cpp): Demonstrates building, searching, saving, and reloading an index with a LeanVec-compressed dataset.
1919
- [example_vamana_with_compression_lvq.cpp](./example_vamana_with_compression_lvq.cpp): Demonstrates building, searching, saving, and reloading an index with a LVQ-compressed dataset.
2020
- [example_vamana_with_compression_dynamic.cpp](./example_vamana_with_compression_dynamic.cpp): Demonstrates building, searching, saving, and reloading a dynamic index (allows vector insertions and deletions over time) with a LeanVec-compressed dataset.
2121

22-
See [CMakeLists.txt](./CMakeLists.txt) for details on linking to the SVS shared library and follow the commands below to compile and use the SVS shared library to run shared.cpp example:
22+
See [CMakeLists.txt](./CMakeLists.txt) for details on linking to the SVS shared library.
2323

24+
## Running the examples
25+
26+
The CMakeLists.txt is set up to detail usage of all options (tarball, pip, conda), and will prioritize utilization in the following order:
27+
28+
1. **System/Conda/Pip installation** - If SVS is installed in a standard location that CMake can find
29+
2. **GitHub Release download** - If not found, it will download the tarball from GitHub
30+
31+
### Option 1: Using libsvs in a conda environment
32+
33+
Install the `libsvs` package (currently only available from GitHub releases):
34+
```bash
35+
conda install https://github.com/intel/ScalableVectorSearch/releases/download/v1.0.0-dev/libsvs-0.0.10-gc4e106f_0.conda
36+
37+
mkdir build
38+
cd build
39+
CC=gcc-11 CXX=g++-11 cmake ../
40+
make -j
41+
./example_vamana_with_compression_dynamic
2442
```
43+
44+
### Option 2: Using pip-installed libsvs
45+
46+
Install the `libsvs` package (currently only available from GitHub releases) and ensure CMake can find it by setting `CMAKE_PREFIX_PATH`:
47+
```bash
48+
pip install https://github.com/intel/ScalableVectorSearch/releases/download/v1.0.0-dev/libsvs-0.0.10+NIGHTLY20251023.184-py3-none-any.whl
49+
50+
mkdir build
51+
cd build
52+
# Note that pip packages require setting CMAKE_PREFIX_PATH to find the library, conda handles this automatically
53+
CC=gcc-11 CXX=g++-11 cmake -DCMAKE_PREFIX_PATH=$(python -c "import libsvs; print(libsvs.get_cmake_prefix_path())") ..
54+
make -j
55+
./example_vamana_with_compression_dynamic
56+
```
57+
58+
### Option 2: Using shared library tarball
59+
60+
If `libsvs` is not installed, CMake will download the tarball (see [CMakeLists.txt](./CMakeLists.txt) for the necessary steps here):
61+
```bash
2562
mkdir build
2663
cd build
2764
CC=gcc-11 CXX=g++-11 cmake ../
2865
make -j
29-
./shared
66+
./example_vamana_with_compression_dynamic
3067
```

0 commit comments

Comments
 (0)