@@ -432,9 +432,9 @@ def _embedding_retrieval(
432432 Uses `CALL db.idx.vector.queryNodes` — FalkorDB's OpenCypher extension for
433433 ANN search. **No APOC is required.**
434434
435- Cosine scores are returned in `[-1, 1 ]`; when `scale_score=True` they are
435+ Cosine scores are returned as distance in `[0, 2 ]`; when `scale_score=True` they are
436436 scaled to `[0, 1]` using the formula:
437- `(score + 1) / 2`. Euclidean scores are transformed with a sigmoid .
437+ `1 - (score / 2) `. Euclidean scores are transformed with `1 / (1 + score)` .
438438
439439 :param query_embedding: Query vector as a plain Python list of floats.
440440 :param top_k: Maximum number of results to return.
@@ -452,7 +452,7 @@ def _embedding_retrieval(
452452YIELD node AS d, score
453453WHERE { where_clause }
454454RETURN d, score
455- ORDER BY score ASC
455+ ORDER BY score ASC, d.id ASC
456456"""
457457 params : dict [str , Any ] = {
458458 "top_k" : top_k ,
@@ -507,7 +507,7 @@ def _cypher_retrieval(
507507
508508 def _scale_to_unit_interval (self , score : float ) -> float :
509509 """
510- Scale a raw similarity score to the unit interval `[0, 2 ]`.
510+ Scale a raw similarity score to the unit interval `[0, 1 ]`.
511511
512512 Uses the following formulas:
513513 - Cosine: `1 - (score / 2)`
0 commit comments