Embeddings
5 nodes
On this page 5
Cosine Similarity
FunctionHow alike two embeddings are: 1 for the same direction, 0 for unrelated, -1 for opposite.
Signature
CosineSimilarity -> Number
first: Number Array
second: Number Arraydouble CosineSimilarity(double[] first, double[] second)
Parameters
| name | type | default | description |
|---|---|---|---|
| first | Number Array | — | An embedding. |
| second | Number Array | — | Another embedding of the same width. |
Returns
| Similarity | Number |
- Ships with
- Divooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Embeddings
- Package
- Machine Learning
Embed
FunctionA text's embedding.
Signature
Embed(model: Embedding Model, text: Text) -> Number Array
double[] Embed(EmbeddingModel model, string text)
Parameters
| name | type | default | description |
|---|---|---|---|
| model | Embedding Model | — | An embedding model. |
| text | Text | — | The text. |
Returns
| Embedding | Number Array |
- Ships with
- Divooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Embeddings
- Package
- Machine Learning
Embed Texts
FunctionSeveral texts' embeddings.
Signature
EmbedTexts -> Number Array Array
model: Embedding Model
texts: Text Arraydouble[][] EmbedTexts(EmbeddingModel model, string[] texts)
Parameters
| name | type | default | description |
|---|---|---|---|
| model | Embedding Model | — | An embedding model. |
| texts | Text Array | — | The texts. |
Returns
| Embeddings | Number Array Array |
- Ships with
- Divooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Embeddings
- Package
- Machine Learning
Load Embedding Model
FunctionLoads an embedding model and its tokenizer from a Hub repository or a folder.
Signature
LoadEmbeddingModel -> Embedding Model
model: Text
device: Compute Device
precision: Precision
backend: Model BackendEmbeddingModel LoadEmbeddingModel(
string model,
ComputeDevice device = ComputeDevice.Auto,
Precision precision = Precision.Auto,
ModelBackend backend = ModelBackend.TorchSharp)Parameters
| name | type | default | description |
|---|---|---|---|
| model | Text | — | A repository id such as sentence-transformers/all-MiniLM-L6-v2 or BAAI/bge-small-en-v1.5, or a folder. |
| device | Compute Device | Auto | Where it runs. |
| precision | Precision | Auto | The number format of its weights. |
| backend | Model Backend | Torch sharp |
Returns
| Model | Embedding Model |
- Ships with
- Divooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Embeddings
- Package
- Machine Learning
Rank By Similarity
FunctionOrders texts by how close in meaning each is to a query, closest first: semantic search over a short list.
Signature
RankBySimilarity -> (Ranked: Text Array, scores: Number Array)
model: Embedding Model
query: Text
candidates: Text Arraystring[] RankBySimilarity(
EmbeddingModel model,
string query,
string[] candidates,
out double[] scores)Parameters
| name | type | default | description |
|---|---|---|---|
| model | Embedding Model | — | An embedding model. |
| query | Text | — | What to look for. |
| candidates | Text Array | — | The texts to search. |
Returns
| Ranked | Text Array |
| scores | Number Array |
- Ships with
- Divooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Embeddings
- Package
- Machine Learning