3 Vector server
Robin edited this page 2026-11-22 06:37:56 +01:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Your own vector server

The search by meaning finds the pages that answer a question even when they use other words ("prices" finds the page about "rates"). It needs a vector server: a service that turns each passage of your site into a list of numbers describing its meaning (a vector).

You can use OpenAI's service, or run your own server: free to use, and your content never leaves your machines. This page shows how to run one with llama.cpp in Docker, behind nginx with HTTPS and a key.

Need help setting it up? Contact LRob.

What you need

  • A Linux server with Docker. A small one is enough: 2 CPU cores and 2 GB of memory run the small model at about 10 passages per second, without a graphics card.
  • A domain name pointing to it, for example vectors.example.com, and nginx with a certificate.
  • One model file in the GGUF format.

1. Choose a model

The plugin has a preset for each of these models: choose the same one in Knowledge base › Search by meaning › Vector model, and it fills the other fields for you.

Model Languages Size Length read Notes
multilingual-e5-small ~100 384 dimensions, ~120 MB 1,200 characters Fast; a good start
multilingual-e5-base ~100 768 dimensions, ~280 MB 1,200 characters More precise, twice slower
EmbeddingGemma 300M 100+ 768 dimensions, ~300 MB 5,000 characters Long passages
Nomic Embed Text v2 ~100 768 dimensions 1,200 characters
BGE-M3 100+ 1,024 dimensions, ~600 MB 8,000 characters The most precise, the slowest

Get the model as a GGUF file: download one already converted, or convert the original model with llama.cpp's convert_hf_to_gguf.py. A q8_0 file keeps almost all of the precision at half the size.

Put the file in a folder of the server, for example /srv/vectors/models/.

2. Run the server

Write a long random key in a file only root can read:

mkdir -p /srv/vectors
openssl rand -hex 32 > /srv/vectors/api-key
chmod 600 /srv/vectors/api-key

Start llama.cpp's server, from its official image, listening on the machine only:

docker run -d --name vectors --restart unless-stopped \
  -p 127.0.0.1:8080:8080 \
  -v /srv/vectors/models:/models:ro \
  -v /srv/vectors/api-key:/run/api-key:ro \
  ghcr.io/ggml-org/llama.cpp:server \
  -m /models/multilingual-e5-small-q8_0.gguf \
  --embeddings --pooling mean \
  -c 512 -b 512 -ub 512 \
  --host 0.0.0.0 --port 8080 \
  --api-key-file /run/api-key
  • --embeddings: the server computes vectors instead of writing text.
  • -c 512 -b 512 -ub 512: the longest text the model reads, in tokens (512 for e5 and Nomic, 2,048 for EmbeddingGemma and BGE-M3: set the three numbers to it).
  • --api-key-file: every request must carry the key.

Check that it answers:

curl -s http://127.0.0.1:8080/v1/embeddings \
  -H "Authorization: Bearer $(cat /srv/vectors/api-key)" \
  -H 'Content-Type: application/json' \
  -d '{"input": ["query: test"]}' | head -c 200

3. Put nginx in front, with HTTPS

server {
    listen 443 ssl;
    http2 on;
    server_name vectors.example.com;

    ssl_certificate     /etc/letsencrypt/live/vectors.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/vectors.example.com/privkey.pem;

    # Only the address of your website's server (optional, recommended).
    # allow 192.0.2.10;
    # deny all;

    location /v1/embeddings {
        proxy_pass http://127.0.0.1:8080;
        proxy_read_timeout 120s;
        client_max_body_size 8m;
    }

    location / {
        return 404;
    }
}

Reload nginx (nginx -t && systemctl reload nginx).

4. Connect the plugin

In Chatbot › Knowledge base › Search by meaning:

  1. Vector model: the model you run (for example Your server: multilingual-e5-small).
  2. Server address: https://vectors.example.com/v1
  3. Key: the content of /srv/vectors/api-key, or in wp-config.php: define( 'LROB_CHATBOT_EMBEDDINGS_KEY', '…' );
  4. Save Changes, then Test: it answers with the number of dimensions and the time taken.

The vectors of your site are then computed in the background; Knowledge base › Index shows the progress. A change of model computes them all again.

The length read is counted with a margin: text full of figures, addresses or code takes more tokens per character. A passage the server still refuses as too long is shortened and sent again, never left without a vector; the Knowledge base shows how many were shortened (their end is still found by the exact-word search).

Good to know

  • Speed. With the small model on 2 cores, about 10 passages per second. Measured on a site of 200 contents: 1,511 passages, keywords in 5 seconds, vectors in 155 seconds; then only the changed passages.
  • Memory. The server keeps the model in memory: about the size of the GGUF file, plus a little.
  • Updates. docker pull ghcr.io/ggml-org/llama.cpp:server, then remove and start the container again. The vectors stay valid as long as the model file is the same.
  • Security. The server only answers with the key, and nginx exposes nothing but /v1/embeddings. The texts sent are the public content of your site and the visitors' questions.