normalization

This commit is contained in:
Roy Han
2024-06-28 17:19:04 -07:00
parent 5213c12354
commit c111d8bb51
4 changed files with 63 additions and 11 deletions

View File

@@ -3185,8 +3185,16 @@ int main(int argc, char **argv) {
responses = std::vector<json>(1, result.result_json);
}
json embeddings = json::array();
for (auto & elem : responses) {
embeddings.push_back(json_value(elem, "embedding", json::array()));
if (body["normalize"]) {
for (auto & elem : responses) {
std::vector<float> embedding = elem.at("embedding").get<std::vector<float>>();
embedding = normalize_vector(embedding, embedding.size());
embeddings.push_back(embedding);
}
} else {
for (auto & elem : responses) {
embeddings.push_back(elem.at("embedding"));
}
}
// send the result
json result = json{{"embedding", embeddings}};