New Tool Radar

Local AI

How to Set Embedding Pooling in llama-server with –pooling

Use llama-server --pooling with an embeddings model to get document vectors from the API.

Schematic illustration with three step boxes: Pick an embeddings model; Start with pooling; Request an embedding.

An embeddings model turns text into a vector, but it needs to know how to combine the token vectors into one: that choice is called pooling. llama-server takes –pooling with values such as mean, cls and last, and it must be set alongside –embedding. This guide starts the server with mean pooling and requests a vector.

Before you start

  • llama.cpp installed, with llama-server on your PATH.
  • A GGUF embeddings model, for example a BGE-M3 GGUF file.
  • curl to call the embeddings endpoint.

Pick the pooling method

Mean pooling averages all token vectors and is the usual default for search embeddings. Use mean unless the model card says otherwise; some models expect cls or last instead.

Start the server with embedding and pooling

Start the server with both flags:

llama-server -m bge-m3-q8_0.gguf --embedding --pooling mean --port 8080

The server loads the model in embedding mode. Without –embedding, the server runs as a chat model and the embeddings endpoint will not work.

Request an embedding

Send a short text to the embeddings endpoint:

curl http://localhost:8080/v1/embeddings -H "Content-Type: application/json" -d '{"input": "How do I reset my router?", "model": "bge-m3"}'

The reply contains a list of numbers: the vector for your text. Check that the length matches the model’s published dimension, 1024 for BGE-M3.

Worked example

Worked example: embed “How do I reset my router?” and “How do I restart my modem?” Both vectors should be close to each other (a high cosine similarity), while “What is the weather in Paris?” should be far from both. If all three look equally close, the pooling setting may be wrong for the model.

Expected result

UNTESTED in this guide: no server was run while writing it. The expected result is that the embeddings endpoint returns a 1024-number vector for BGE-M3, and the two router texts are closer to each other than to the weather text.

Limitations

Pooling only matters for embeddings models; the flag does nothing useful for a chat model. The vector dimension depends on the model, so check the model card before assuming 1024.

Sources

See all