Uploaded and retrived vectors are different #727
Answered
by
hash-f
paniabhisek
asked this question in
Q&A
|
I have uploaded my points of Code snippet: output: What is the reason behind this ? |
Answered by
hash-f
Aug 25, 2024
Replies: 1 comment
|
This is the expected behavior. Qdrant normalizes the vectors when they are stored to ensure that the distance calculations (like cosine similarity) are meaningful and consistent. When vectors are normalized, their magnitudes are scaled to 1, which simplifies the comparison process by focusing solely on the direction of the vectors rather than their magnitude. A quick example of how normalization works import numpy as np
def normalize_vector(vector):
norm = np.linalg.norm(vector)
if norm == 0:
return vector
return vector / norm
vector = np.array([0.05, 0.61, 0.76, 0.74])
normalized_vector = normalize_vector(vector)
print(normalized_vector)
# Output
# [0.04082755 0.49809612 0.62057877 0.60424775]While nomalization improves the performance it does not have any impact on the accuracy. from numpy import dot
from numpy.linalg import norm
def cosine_similarity(a, b):
return dot(a, b)/(norm(a)*norm(b))
vector = [0.05, 0.61, 0.76, 0.74]
normalied_vector = [0.04082754999399185, 0.4980961084365845, 0.6205787658691406, 0.6042477488517761]
print(cosine_similarity(vector, vector))
print(cosine_similarity(vector, normalied_vector))
# Output
# 1.0
# 1.0 |
0 replies
Answer selected by
paniabhisek
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the expected behavior.
Qdrant normalizes the vectors when they are stored to ensure that the distance calculations (like cosine similarity) are meaningful and consistent. When vectors are normalized, their magnitudes are scaled to 1, which simplifies the comparison process by focusing solely on the direction of the vectors rather than their magnitude.
A quick example of how normalization works