MCPcopy Create free account
hub / github.com/FastFlowLM/FastFlowLM / embed

Method embed

src/common/AutoEmbeddingModel/modeling_gemma_embedding.cpp:20–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18}
19
20std::vector<float> Gemma_Embedding::embed(std::string& text, embedding_task_type_t task_type) {
21 std::string task_prefix = this->_get_task_prefix(task_type);
22 std::string full_text = "<bos>" + task_prefix + text + "<eos>";
23 std::vector<int> tokens = this->tokenizer->encode(full_text);
24 if (tokens.size() > 2048) {
25 // cut to 2047 and add <eos> (1)
26 tokens.resize(2048);
27 tokens[2047] = 1;
28 }
29
30 buffer<bf16> y = this->embedding_model_impl->embed(tokens);
31 std::vector<float> result(y.size());
32 for (int i = 0; i < y.size(); i++) {
33 result[i] = static_cast<float>(y[i]);
34 }
35 return result;
36}

Callers 3

mainFunction · 0.80
handle_embeddingsMethod · 0.80
_shared_embedMethod · 0.80

Calls 4

_get_task_prefixMethod · 0.95
encodeMethod · 0.80
sizeMethod · 0.45
resizeMethod · 0.45

Tested by 1

mainFunction · 0.64