|
| 1 | +:sectnums: |
| 2 | +:sectnumlevels: 5 |
| 3 | + |
| 4 | += VectorChord |
| 5 | + |
| 6 | +== Overview |
| 7 | +VectorChord is a high-performance, scalable vector search extension for PostgreSQL, considered the successor to pgvecto.rs. It is specifically designed to handle large-scale vector data, capable of efficiently storing and retrieving high-dimensional vectors with limited hardware resources, significantly reducing the storage and computational costs of vector search. |
| 8 | + |
| 9 | +The extension demonstrates exceptional performance, with query speeds up to 5 times faster than pgvector and support for vectors up to 60,000 dimensions. Through innovative RaBitQ compression technology and IVF indexing, VectorChord achieves significant improvements in disk storage efficiency, claiming to store 400,000 vectors for just $1, with cost efficiency far exceeding similar services. |
| 10 | + |
| 11 | +VectorChord is fully compatible with pgvector's data types and query syntax, ensuring seamless migration and integration experience. It has been successfully applied in production environments, reliably managing over 3 billion vectors, making it an ideal foundational component for building next-generation AI applications and conducting massive similarity searches. |
| 12 | + |
| 13 | +== Installation |
| 14 | +Based on the development environment, users can choose the appropriate VectorChord installation method from the https://docs.vectorchord.ai/vectorchord/getting-started/installation.html[VectorChord installation] page. |
| 15 | + |
| 16 | +=== Source Installation |
| 17 | +In addition to the installation methods provided by the VectorChord community, the IvorySQL community also provides source code installation methods. The source code installation environment is Ubuntu 24.04(x86_64). |
| 18 | + |
| 19 | +Before compilation, ensure that clang and rust are already installed: |
| 20 | + |
| 21 | +clang version requirement >= 16, including libclang; |
| 22 | + |
| 23 | +rust version requirement >= 1.89, including cargo |
| 24 | + |
| 25 | +[TIP] |
| 26 | +IvorySQL 1.17 and above is already installed in the environment, with the installation path at /usr/local/ivorysql/ivorysql-1 |
| 27 | + |
| 28 | +==== Install Clang |
| 29 | + |
| 30 | +** Install clang 16 compiler and libclang development library |
| 31 | +---- |
| 32 | +sudo apt update |
| 33 | +sudo apt install clang-16 libclang-16-dev |
| 34 | +---- |
| 35 | + |
| 36 | +** Verify Installation |
| 37 | +---- |
| 38 | +$ clang-16 --version |
| 39 | +Ubuntu clang version 16.0.6 (23ubuntu4) |
| 40 | +Target: x86_64-pc-linux-gnu |
| 41 | +Thread model: posix |
| 42 | +InstalledDir: /usr/bin |
| 43 | +---- |
| 44 | + |
| 45 | +** Set Default Clang (Optional): Similar to GCC, you can set the default version: |
| 46 | +---- |
| 47 | +sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-16 100 |
| 48 | +sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-16 100 |
| 49 | +---- |
| 50 | + |
| 51 | +** Verify Default Version |
| 52 | +---- |
| 53 | +clang --version # Should display clang-16 |
| 54 | +clang++ --version |
| 55 | +---- |
| 56 | + |
| 57 | +** Set LIBCLANG_PATH: Usually automatically set after installing libclang-16-dev, but it's best to confirm or explicitly set it |
| 58 | +---- |
| 59 | +# Find the location of libclang.so (usually /usr/lib/llvm-16/lib/libclang.so.1 or similar) |
| 60 | +find /usr -name 'libclang.so*' 2>/dev/null |
| 61 | +
|
| 62 | +# Set environment variable |
| 63 | +export LIBCLANG_PATH=/usr/lib/llvm-16/lib # Usually setting the directory containing the file is sufficient |
| 64 | +
|
| 65 | +# To make it permanent, you can add the above export command to your shell configuration file (~/.bashrc or ~/.zshrc) |
| 66 | +---- |
| 67 | + |
| 68 | +==== Install Rust(>=1.89) and Cargo |
| 69 | +Following Vectorchord and Rust official recommendations, using rustup for installation is the best practice. |
| 70 | +Install rustup: |
| 71 | +---- |
| 72 | +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh |
| 73 | +# After running the script, it will prompt you. Press 1 to select default installation |
| 74 | +---- |
| 75 | + |
| 76 | +Activate environment: After installation, you need to make the new PATH settings take effect |
| 77 | +---- |
| 78 | +source "$HOME/.cargo/env" # Takes effect for current terminal session |
| 79 | +---- |
| 80 | + |
| 81 | +Verify installation: |
| 82 | +---- |
| 83 | +rustc --version # Should output something like rustc 1.xx.x (stable version number >= 1.89) |
| 84 | +cargo --version # Should output cargo version number |
| 85 | +---- |
| 86 | + |
| 87 | +=== Install VectorChord |
| 88 | + |
| 89 | +---- |
| 90 | +# Pull vectorchord source code |
| 91 | +curl -fsSL https://github.com/tensorchord/VectorChord/archive/refs/tags/0.5.1.tar.gz | tar -xz |
| 92 | +cd VectorChord-0.5.1 |
| 93 | +# Set pg_config path to PATH environment variable, e.g.: |
| 94 | +export PATH=/usr/local/ivorysql/ivorysql-1/bin/:$PATH |
| 95 | +make build |
| 96 | +make install |
| 97 | +---- |
| 98 | + |
| 99 | +== Configure ivorysql.conf File |
| 100 | +---- |
| 101 | +# Shared preload extensions |
| 102 | +shared_preload_libraries = 'vchord' |
| 103 | +---- |
| 104 | + |
| 105 | +== Restart Service |
| 106 | + |
| 107 | +---- |
| 108 | +pg_ctl restart -D ./data -l logfile |
| 109 | +---- |
| 110 | + |
| 111 | +== Create Extension and Confirm VectorChord Version |
| 112 | + |
| 113 | +Connect to the database with psql and execute the following commands: |
| 114 | +---- |
| 115 | +ivorysql=# CREATE EXTENSION IF NOT EXISTS vchord CASCADE; |
| 116 | +CREATE EXTENSION |
| 117 | +
|
| 118 | +ivorysql=# SELECT * FROM pg_available_extensions WHERE name = 'vchord'; |
| 119 | + name | default_version | installed_version | comment |
| 120 | +---------+-----------------+-------------------+-------------------------------------------------------------------------------------------- |
| 121 | + vchord | 0.5.1 | 0.5.1 | vchord: Vector database plugin for Postgres, written in Rust, specifically designed for LLM |
| 122 | +(1 row) |
| 123 | +---- |
| 124 | + |
| 125 | +== Usage |
| 126 | +For VectorChord usage, please refer to https://docs.vectorchord.ai/vectorchord/getting-started/overview.html[VectorChord official documentation] |
0 commit comments