Triangle inequality
Triangle inequality for cosine similarity

By applying the cosine function to the triangle inequality and reverse triangle inequality for arc lengths and employing the angle addition and subtraction formulas for cosines, it follows immediately that

sim (u, w) ≥ sim (u, v) ⋅ sim (v, w) − (1 − sim (u, v) 2) ⋅ (1 − sim (v, w) 2) {\displaystyle \operatorname {sim} (u,w)\geq \operatorname {sim} (u,v)\cdot \operatorname {sim} (v,w)-{\sqrt {\left(1-\operatorname {sim} (u,v)^{2}\right)\cdot \left(1-\operatorname {sim} (v,w)^{2}\right)}}}

and

sim (u, w) ≤ sim (u, v) ⋅ sim (v, w) + (1 − sim (u, v) 2) ⋅ (1 − sim (v, w) 2). {\displaystyle \operatorname {sim} (u,w)\leq \operatorname {sim} (u,v)\cdot \operatorname {sim} (v,w)+{\sqrt {\left(1-\operatorname {sim} (u,v)^{2}\right)\cdot \left(1-\operatorname {sim} (v,w)^{2}\right)}}\,.}

With these formulas, one needs to compute a square root for each triple of vectors { u, v, w } that is examined rather than arccos(sim(u, v)) for each pair of vectors { u, v } examined, and could be a performance improvement when the number of triples examined is less than the number of pairs examined.
length_constraints:number_paragraphs[2]