Skip to content

Commit 1a68ec9

Browse files
authored
server : honor --embd-normalize CLI arg (#23125)
The --embd-normalize flag was registered only for the embedding and debug examples, so llama-server rejected it and the /embedding handler used a hard-coded default of 2 (L2). Add LLAMA_EXAMPLE_SERVER to the flag's example set and read params.embd_normalize as the handler's default. The per-request "embd_normalize" body field continues to override.
1 parent a16cce8 commit 1a68ec9

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

common/arg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2808,7 +2808,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
28082808
[](common_params & params, int value) {
28092809
params.embd_normalize = value;
28102810
}
2811-
).set_examples({LLAMA_EXAMPLE_EMBEDDING, LLAMA_EXAMPLE_DEBUG}));
2811+
).set_examples({LLAMA_EXAMPLE_EMBEDDING, LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_DEBUG}));
28122812
add_opt(common_arg(
28132813
{"--embd-output-format"}, "FORMAT",
28142814
"empty = default, \"array\" = [[],[]...], \"json\" = openai style, \"json+\" = same \"json\" + cosine similarity matrix, \"raw\" = plain whitespace-delimited output (one embedding per line)",

tools/server/server-context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4527,7 +4527,7 @@ std::unique_ptr<server_res_generator> server_routes::handle_embeddings_impl(cons
45274527
}
45284528
}
45294529

4530-
int embd_normalize = 2; // default to Euclidean/L2 norm
4530+
int embd_normalize = params.embd_normalize;
45314531
if (body.count("embd_normalize") != 0) {
45324532
embd_normalize = body.at("embd_normalize");
45334533
if (meta->pooling_type == LLAMA_POOLING_TYPE_NONE) {

0 commit comments

Comments
 (0)