Merged
Conversation
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
Contributor
Author
|
Greptile OverviewGreptile SummaryThis PR adds comprehensive embedding extraction functionality to lloyal.node, expanding the API to support text embedding models alongside the existing text generation capabilities. The implementation includes: Major Changes:
Architecture:
Testing:
Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant User as User Code
participant Addon as SessionContext (N-API)
participant Worker as EncodeWorker
participant Lloyal as liblloyal::embedding
participant Llama as llama.cpp
Note over User,Llama: Context Creation with Embedding Mode
User->>Addon: createContext({embeddings: true, poolingType: MEAN})
Addon->>Llama: llama_init_from_model(ctx_params.embeddings=true)
Llama-->>Addon: llama_context*
Addon-->>User: SessionContext
Note over User,Llama: Embedding Extraction Flow
User->>Addon: tokenize("Hello world")
Addon->>Worker: TokenizeWorker
Worker->>Lloyal: lloyal::tokenizer::tokenize()
Lloyal->>Llama: llama_tokenize()
Llama-->>Lloyal: tokens[]
Lloyal-->>Worker: tokens[]
Worker-->>Addon: Promise resolved
Addon-->>User: tokens[]
User->>Addon: kvCacheClear()
Addon->>Worker: KVCacheClearWorker
Worker->>Lloyal: lloyal::kv::clear_all()
Lloyal->>Llama: llama_memory_clear()
Llama-->>Lloyal: success
Lloyal-->>Worker: void
Worker-->>Addon: Promise resolved
Addon-->>User: void
User->>Addon: encode(tokens)
Addon->>Worker: EncodeWorker
Worker->>Lloyal: lloyal::decoder::encode()
Note over Lloyal: Marks ALL tokens with logits=true
Lloyal->>Llama: llama_decode()
Llama-->>Lloyal: success
Lloyal-->>Worker: void
Worker-->>Addon: Promise resolved
Addon-->>User: void
User->>Addon: getEmbeddings(normalize=true)
Addon->>Lloyal: lloyal::embedding::get(ctx, L2)
Lloyal->>Llama: llama_get_embeddings_seq(ctx, 0)
Llama-->>Lloyal: float* embeddings
Lloyal->>Lloyal: apply_l2_normalize()
Lloyal-->>Addon: vector<float>
Addon-->>User: Float32Array (L2-normalized)
Note over User,Llama: Dimension and Capability Checks
User->>Addon: getEmbeddingDimension()
Addon->>Lloyal: lloyal::embedding::dimension()
Lloyal->>Llama: llama_model_n_embd()
Llama-->>Lloyal: int32_t
Lloyal-->>Addon: dimension
Addon-->>User: number
User->>Addon: hasPooling()
Addon->>Lloyal: lloyal::embedding::has_pooling()
Lloyal->>Llama: llama_pooling_type()
Llama-->>Lloyal: pooling_type
Lloyal-->>Addon: bool
Addon-->>User: boolean
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.