---
title: "embed"
description: "Generate, inspect, and use node/text embeddings in Semantica — compute Node2Vec embeddings, find similar nodes, score link predictions, batch similarity, and pairwise similarity. Uses NodeEmbedder, SimilarityCalculator, LinkPredictor, and AgentContext. Sub-commands: compute, similar, similarity, predict-link, top-links, batch, pairwise."
canonical_url: "https://skilld.dev/gh/semantica-agi/semantica/embed"
last_updated: "2026-09-21T13:00:15.000Z"
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

---
name: embed
description: Generate, inspect, and use node/text embeddings in Semantica — compute Node2Vec embeddings, find similar nodes, score link predictions, batch similarity, and pairwise similarity. Uses NodeEmbedder, SimilarityCalculator, LinkPredictor, and AgentContext. Sub-commands: compute, similar, similarity, predict-link, top-links, batch, pairwise.
---

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install semantica-agi/semantica/embed`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/embed`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/semantica-agi/semantica/embed) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/embed`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/embed --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/embed --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# /semantica:embed

Generate and inspect graph embeddings. Usage: `/semantica:embed <sub-command> [args]`

`$ARGUMENTS` = sub-command + arguments.

---

## `compute [--labels <t1,t2>] [--rels <r1,r2>] [--dim N] [--walks N]`

Generate Node2Vec embeddings for graph nodes.

```python
from semantica.kg.node_embeddings import NodeEmbedder
from semantica.context import ContextGraph

graph = ContextGraph()
embedder = NodeEmbedder()

node_labels = labels_arg.split(",") if labels_arg else graph.get_all_node_types()
rel_types = rels_arg.split(",") if rels_arg else []

# All positional args required: graph_store, node_labels, relationship_types
embeddings = embedder.compute_embeddings(
    graph_store=graph,
    node_labels=node_labels,
    relationship_types=rel_types,
    embedding_dimension=int(dim_arg) if dim_arg else None,
    num_walks=int(walks_arg) if walks_arg else None,
)

# Store embeddings back on nodes
embedder.store_embeddings(
    graph_store=graph,
    embeddings=embeddings,
    property_name="node2vec_embedding",
)
```

Output:
```
Embeddings computed and stored.
  Nodes embedded:     N
  Embedding dim:      128
  Node types covered: [type1, type2, ...]
  
Sample (first 5 nodes):
  | Node | Type | Embedding dim | Stored |
```

---

## `similar <node_id> [--top N]`

Find the most similar nodes to a given node in embedding space.

```python
from semantica.kg.node_embeddings import NodeEmbedder
from semantica.context import ContextGraph, AgentContext

graph = ContextGraph()
embedder = NodeEmbedder()

# NodeEmbedder.find_similar_nodes uses the stored node2vec_embedding property
neighbors = embedder.find_similar_nodes(
    graph_store=graph,
    node_id=node_id,
    top_k=int(top_n) if top_n else 10,
    embedding_property="node2vec_embedding",
)

# Also use AgentContext for richer similarity with metadata
ctx = AgentContext(kg_algorithms=True)
entity_similar = ctx.find_similar_entities(
    entity_id=node_id,
    similarity_type="content",  # or "structural", "hybrid"
    top_k=int(top_n) if top_n else 10,
)
```

Return: `| Rank | Node ID | Type | Cosine Similarity | Shared Properties |`

---

## `similarity <n1> <n2> [--method cosine|euclidean|manhattan|correlation]`

Compute pairwise similarity between two nodes.

```python
from semantica.kg.similarity_calculator import SimilarityCalculator
from semantica.kg.node_embeddings import NodeEmbedder
from semantica.context import ContextGraph

graph = ContextGraph()
embedder = NodeEmbedder()
calc = SimilarityCalculator()

# Get embeddings for both nodes
v1 = embedder.find_similar_nodes(graph, n1, top_k=1)  # placeholder — use stored embedding
v2 = embedder.find_similar_nodes(graph, n2, top_k=1)

method = method_arg or "cosine"
if method == "cosine":
    score = calc.cosine_similarity(vector1=v1, vector2=v2)
elif method == "euclidean":
    score = calc.euclidean_distance(v1, v2)
elif method == "manhattan":
    score = calc.manhattan_distance(v1, v2)
elif method == "correlation":
    score = calc.correlation_similarity(v1, v2)
```

Output:
```
Similarity: "<n1>" ↔ "<n2>"
  Method:  cosine
  Score:   0.847

  Interpretation: HIGH similarity (>0.8)
  Shared neighbors:   K
  Common node types:  [types]
```

---

## `predict-link <n1> <n2> [--method cosine|jaccard|adamic-adar|common-neighbors]`

Score the likelihood of a relationship between two nodes.

```python
from semantica.kg.link_predictor import LinkPredictor
from semantica.context import ContextGraph

graph = ContextGraph()
predictor = LinkPredictor()

# score_link(graph_store, node_id1, node_id2, method=)
score = predictor.score_link(
    graph_store=graph,
    node_id1=n1,
    node_id2=n2,
    method=method_arg or None,
)
```

Output:
```
Link Prediction: "<n1>" → "<n2>"
  Method:  cosine
  Score:   0.723  (threshold: 0.5 → LIKELY)

  Recommendation: This link is LIKELY to be meaningful.
```

---

## `top-links <node_id> [--top N] [--method <method>]`

Find the top-N most likely new connections for a node.

```python
from semantica.kg.link_predictor import LinkPredictor
from semantica.context import ContextGraph

graph = ContextGraph()
predictor = LinkPredictor()

top = predictor.predict_top_links(
    graph_store=graph,
    node_id=node_id,
    top_k=int(top_n) if top_n else 10,
    method=method_arg or None,
)
```

Return: `| Rank | Target Node | Type | Score | Existing Link? |`

---

## `batch <query_node> [--against <n1,n2,...>] [--top N]`

Score similarity between a query node and a set of target nodes (or all nodes).

```python
from semantica.kg.similarity_calculator import SimilarityCalculator
from semantica.kg.node_embeddings import NodeEmbedder
from semantica.context import ContextGraph

graph = ContextGraph()
embedder = NodeEmbedder()
calc = SimilarityCalculator()

# Get query embedding and all target embeddings
query_vec = ...  # from stored node2vec_embedding
target_embeddings = {n: embedder.get_embedding(n) for n in targets}

scores = calc.batch_similarity(
    embeddings=target_embeddings,
    query_embedding=query_vec,
    top_k=int(top_n) if top_n else 20,
)
```

Return: `| Node | Type | Score |` sorted descending.

---

## `pairwise [--labels <t1,t2>] [--method cosine|euclidean]`

Compute all pairwise similarities among a set of nodes.

```python
from semantica.kg.similarity_calculator import SimilarityCalculator

calc = SimilarityCalculator()

pairwise = calc.pairwise_similarity(
    embeddings=embeddings_dict,
    method=method_arg or None,
)
```

Show as a heatmap summary — top-5 most similar pairs and bottom-5 most dissimilar pairs. Full matrix on request.

Also use `AgentContext.predict_decision_relationships(decision_id, top_k)` when working within decision graphs for relationship prediction enriched with KG algorithms.
