Skip to content
Open
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
40 changes: 26 additions & 14 deletions examples/cpp/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,28 @@ project(svs_shared_library_example
LANGUAGES CXX
)

# Other AVX versions can be found at https://github.com/intel/ScalableVectorSearch/releases.
set(SVS_URL "https://github.com/intel/ScalableVectorSearch/releases/download/v0.0.9/svs-shared-library-0.0.9.tar.gz")

include(FetchContent)
FetchContent_Declare(
svs
URL "${SVS_URL}"
)
FetchContent_MakeAvailable(svs)

list(APPEND CMAKE_PREFIX_PATH "${svs_SOURCE_DIR}")
find_package(svs REQUIRED)
find_library(SVS_SHARED svs_shared_library)
# Try to find SVS from system/conda/pip installation first
find_package(svs QUIET)

if(NOT svs_FOUND)
# If sourcing from pip/conda, the following steps are not necessary, simplifying workflow
# If not found, download tarball from GitHub release and follow steps to fetch and find
set(SVS_URL "https://github.com/intel/ScalableVectorSearch/releases/download/v0.0.9/svs-shared-library-0.0.9.tar.gz")

message(STATUS "SVS not found in system, downloading from: ${SVS_URL}")

include(FetchContent)
FetchContent_Declare(
svs
URL "${SVS_URL}"
)
FetchContent_MakeAvailable(svs)

list(APPEND CMAKE_PREFIX_PATH "${svs_SOURCE_DIR}")
find_package(svs REQUIRED)
else()
message(STATUS "Found SVS: ${svs_DIR}")
endif()

set(SVS_CXX_STANDARD 20)
SET(CMAKE_CXX_FLAGS "-O3 -DNDEBUG -std=gnu++20 -march=native -mtune=native -Werror -Wall -Wextra -Wpedantic" )
Expand All @@ -41,7 +50,10 @@ set(DATA_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../../data/test_dataset")
function(create_example_executable exe file)
add_executable(${exe} ${file})
target_compile_definitions(${exe} PRIVATE SVS_DATA_DIR="${DATA_DIRECTORY}")
target_link_libraries(${exe} PUBLIC ${SVS_SHARED} svs::svs)
target_link_libraries(${exe} PUBLIC
svs::svs_shared_library
svs::svs
)
endfunction()

create_example_executable(shared shared.cpp)
Expand Down
43 changes: 40 additions & 3 deletions examples/cpp/shared/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,54 @@
~ limitations under the License.
-->

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:
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:
- [example_vamana_with_compression.cpp](./example_vamana_with_compression.cpp): Demonstrates building, searching, saving, and reloading an index with a LeanVec-compressed dataset.
- [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.
- [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.

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:
See [CMakeLists.txt](./CMakeLists.txt) for details on linking to the SVS shared library.

## Running the examples

The CMakeLists.txt is set up to detail usage of all options (tarball, pip, conda), and will prioritize utilization in the following order:

1. **System/Conda/Pip installation** - If SVS is installed in a standard location that CMake can find
2. **GitHub Release download** - If not found, it will download the tarball from GitHub

### Option 1: Using libsvs in a conda environment

Install the `libsvs` package:
```bash
conda install -c https://software.repos.intel.com/python/conda libsvs

mkdir build
cd build
CC=gcc-11 CXX=g++-11 cmake ../
make -j
./example_vamana_with_compression_dynamic
```

### Option 2: Using pip-installed libsvs

Install the `libsvs` package (currently only available from GitHub releases) and ensure CMake can find it by setting `CMAKE_PREFIX_PATH`:
```bash
pip install https://github.com/intel/ScalableVectorSearch/releases/download/v1.0.0-dev/libsvs-0.0.10+NIGHTLY20251023.184-py3-none-any.whl

mkdir build
cd build
# Note that pip packages require setting CMAKE_PREFIX_PATH to find the library, conda handles this automatically
CC=gcc-11 CXX=g++-11 cmake -DCMAKE_PREFIX_PATH=$(python -c "import libsvs; print(libsvs.get_cmake_prefix_path())") ..
make -j
./example_vamana_with_compression_dynamic
```

### Option 3: Using shared library tarball

If `libsvs` is not installed, CMake will download the tarball (see [CMakeLists.txt](./CMakeLists.txt) for the necessary steps here):
```bash
mkdir build
cd build
CC=gcc-11 CXX=g++-11 cmake ../
make -j
./shared
./example_vamana_with_compression_dynamic
```
Loading