-
Notifications
You must be signed in to change notification settings - Fork 321
Description
This is not bug report but a simple note for building on Ubuntu system, in case someone else needs to do this in the future.
My setup environment is a ubuntu 20.04 machine.
first, install uv;
then:
git clone https://github.com/yichuan-w/LEANN.git leann
cd leann
git submodule update --init --recursive
next: sudo apt-get install libomp-dev libboost-all-dev protobuf-compiler libmkl-full-dev libaio-dev libzmq3-dev
for 20.04, Build libabsl-dev from Source:
git clone https://github.com/abseil/abseil-cpp.git
cd abseil-cpp
mkdir build && cd build
cmake ..
make
sudo make install
if error occurs like Please set CMAKE_INSTALL_PREFIX to install Abseil in your source or build tree directly.
the cmake command should be cmake .. -DCMAKE_INSTALL_PREFIX=../install
You may also encounter issues related to protobuf:
sudo apt-get remove --purge protobuf-compiler libprotobuf-dev # prevent conflict
mkdir protobuf
cd protobuf/
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.20.3/protobuf-cpp-3.20.3.tar.gz
tar -xzf protobuf-cpp-3.20.3.tar.gz
cd protobuf-3.20.3/
./configure
make -j 20
sudo make install
sudo ldconfig
Install the IntelMKL:
go to https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-download.html?operatingsystem=linux&linux-install=apt
I chose the apt method. you can choose whichever you feel most comfortable with, but in the end, you should do:
sudo apt install intel-oneapi-mkl
sudo apt install intel-oneapi-mkl-devel
Next,
export MKLROOT=/opt/intel/oneapi/mkl/latest
According to osqp/osqp#726,
instead of source $MKLROOT/bin/mklvars.sh
, you should do source $MKLROOT/env/vars.sh
Then, this is not enough: go to https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-link-line-advisor.html, put in necessary values related to your system:
you will see two extra lines of code you need to insert to your command line:
so you will do:
export CXXFLAGS="-DMKL_ILP64 -m64 -I${MKLROOT}/include"
export LDFLAGS="-m64 -L${MKLROOT}/lib -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl"
Next would be the installation part:
# you may want to use a newer gcc that you built yourself
export CC=/opt/gcc-12.4.0/bin/gcc
export CXX=/opt/gcc-12.4.0/bin/g++
# in the leann folder
uv venv
source .venv/bin/activate
# upgrade CMAKE
uv pip install "cmake>=3.29"
uv pip install -e packages/leann -e packages/leann-core -e packages/leann-backend-hnsw -e packages/leann-backend-diskann
Theoretically this should work. If some building error, you may want to clean uv cache with uv cache clean
and adjust then try your luck again.
When you later want to use the leann to digest:
source .venv/bin/activate # this is the uv created one; then go to your destination of leann's subsequent action
export MKLROOT=/opt/intel/oneapi/mkl/latest
source $MKLROOT/env/vars.sh # you still need these two lines in order for MKL link to be correct
leann build whatever-name --docs ./src --embedding-mode sentence-transformers --embedding-model all-MiniLM-L6-v2 --force --backend hnsw --graph-degree 32 --complexity 64
# or a more modern model:
leann build your-desired-project --docs ./src --embedding-mode sentence-transformers --embedding-model Qwen/Qwen3-Embedding-0.6B --force --backend hnsw --graph-degree 32 --complexity 64
In order to use mcp properly, modified json black is like this:
"leann-server": {
"type": "stdio",
"command": "bash",
"args": [
"-c",
"export MKLROOT=/opt/intel/oneapi/mkl/latest && source $MKLROOT/env/vars.sh && source ~/Software/leann/.venv/bin/activate && exec leann_mcp \"$@\"",
"bash"
],
"env": {}
}