Skip to content

Get‑ShpCosineSimilarity

Raimund edited this page Jun 12, 2026 · 1 revision

SYNOPSIS

Computes the cosine similarity between two embedding vectors.

SYNTAX

Get-ShpCosineSimilarity [-Reference] <Double[]> [-Candidate] <Double[]> 
 [<CommonParameters>]

DESCRIPTION

Returns the cosine similarity (a value from -1 to 1, where 1 means identical direction) between a reference vector and a candidate vector, using pure PowerShell so no compiled dependency is needed. Pair it with Request-ShpEmbedding to rank texts by semantic similarity for search or retrieval; to score many candidates, pipe them through ForEach-Object. The two vectors must have the same length; a zero-magnitude vector yields a score of 0.

EXAMPLES

EXAMPLE 1

Get-ShpCosineSimilarity -Reference $a -Candidate $b

Returns the cosine similarity between vectors $a and $b.

EXAMPLE 2

$docs | ForEach-Object { Get-ShpCosineSimilarity -Reference $query -Candidate $_.Embedding }

Scores each document embedding against the query vector.

PARAMETERS

-Candidate

The candidate embedding vector to score. Mandatory.

Type: Double[]
Parameter Sets: (All)
Aliases:

Required: True
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Reference

The reference embedding vector to compare against. Mandatory.

Type: Double[]
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

System.Double

The cosine similarity score.

NOTES

RELATED LINKS

Clone this wiki locally