Index of every page on this site: llms.txt
All skills
semantica-agi avatar

/embed

@63eabcc
by Semanticasemantica-agi/semantica15k stars
1,750
Run it yourself

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.

Requires /semantica
  • 1 file
  • 6 KB
  • Updated 8 months ago
  • GitHub
Use this Skill: https://skilld.dev/gh/semantica-agi/semantica/embed

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈87 tokens for metadata: the name and description. ≈1.4k when used: this file.

Description uses 4.3% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈346 characters, or 4.3%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

/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.

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.

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.

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.

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.

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).

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.

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.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at 63eabcc. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 8 months ago

README badge

README badge for semantica-agi/semantica/embed