Softanza
StartFrançais
Softanza
Reference · stzVectorIndex

SetMetric()

:Euclidean compares positions, :Cosine compares directions. Text embeddings almost always want :Cosine.

Basic examples (1)

Softanza
aDocs = [
		[ 0.90, 0.10, 0.05, 0.00 ],   # 1: topic A
		[ 0.88, 0.14, 0.02, 0.01 ],   # 2: topic A, phrased differently
		[ 0.05, 0.02, 0.91, 0.10 ],   # 3: topic B
		[ 0.00, 0.01, 0.08, 0.95 ]    # 4: topic C
	]
oSearch = new stzVectorIndex(aDocs)
oSearch.SetMetric(:Cosine)
aHits = oSearch.Search([ 0.89, 0.12, 0.03, 0.00 ], 2)
# a query on topic A retrieves both topic-A documents
? (aHits[1][1] = 1 or aHits[1][1] = 2) and (aHits[2][1] = 1 or aHits[2][1] = 2)
# ...and both are highly similar
? oSearch.CosineFromDistance(aHits[1][2]) > 0.99
aHitC = oSearch.Search([ 0.00, 0.00, 0.10, 0.98 ], 1)
# a query on topic C retrieves topic C
? aHitC[1][1]
Output
1
1
4

run on 2026-10-02 04:23 inside the library at commit 0e72e2e2c; taken from numeric_vector_index_narrated.ring(opens in a new tab)

The extensions of this method

Each extension, and whether it exists for this method; an extension that exists combines with the others (FindSTCS).

Extension
Exists
What it adds · The names
Q
no
does what the method does, then returns the object, so the call can be chained
QQ
no
chains on the next, more specific type of object (the Q ladder)
QQQ
no
chains on the most specific type of object (the Q ladder)
QRT
no
returns the result as an object of the requested type
CS
no
takes a case-sensitivity flag
ST
no
takes the position to start from (StartingAt)
IB
no
takes bounds that are included (IncludingBounds)
XT
no
the extended form: more parameters than the base method
XTT
no
yet another extension: a further extended form, after XT
Z
no
includes the position in what it returns
ZZ
no
returns positions as sections, [start, end]
W
no
selects by a condition
WF
no
selects by a condition, with the expressive keywords (@NextItem, @PreviousItem...)
D
no
takes a direction, forward or backward (Directional)
F
no
takes a function (the condition or the update is given as a function); the forms document also uses F for the future form, which defers the action
Many
no
works on a collection of items instead of one (the plural form)
Except
no
takes exceptions, what to leave out (the exceptional form)
U
no
returns the result without duplication

Every example is a test file of the library, run inside the library for this page; only those whose output kept every promise their file wrote are shown.

See also