# Vector Distance not consistent with external cosine similarity measure (Sklearn)

**URL:** <https://forum.weaviate.io/t/vector-distance-not-consistent-with-external-cosine-similarity-measure-sklearn/1112>\
**Category:** Support\
**Created:** [December 18, 2023, 12:41pm UTC](https://forum.weaviate.io/t/vector-distance-not-consistent-with-external-cosine-similarity-measure-sklearn/1112 "2023-12-18T12:41:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_Y](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/richard_y/32/719_2.png) [@Richard\_Y](https://forum.weaviate.io/u/Richard_Y)\
**Post date:** [December 18, 2023, 12:41pm UTC](https://forum.weaviate.io/t/vector-distance-not-consistent-with-external-cosine-similarity-measure-sklearn/1112/1 "2023-12-18T12:41:20Z")

</div>

In a nutshell this is what i’ve done:

1. Used this query to get articles that are close to an input prompt, with distance = 0.3:  
 ![image](https://canada1.discourse-cdn.com/flex027/uploads/weaviate/original/1X/ed0276690fa500715a0c784f140c605c31f3891d.png)
2. Saved the returned articles into a seperate class.
3. To validate, I took 100 random samples from the new class (included) and 100 articles that were not added to the new class (excluded)
4. I used sklearns cosine similarity implementation as so:

```auto
from sklearn.metrics.pairwise import cosine_similarity
# Calculate cosine similarity between each pair of vectors from the two lists
similarity_orig_to_prompt = cosine_similarity(list(dict_excluded_vectors.values()), [text_0_embed])
similarity_trimmed_to_prompt = cosine_similarity(list(dict_included_vectors.values()), [text_0_embed])

```

1. here were the average similarity measures:

Both groups pretty much had the same similarity score…  
(0.7117798016779362, 0.7196412496249364)

I am wondering why is this the case? It would be good to understand more about what is happening under the hood of with\_near\_vector. Is the distance metric used here comparable with SKLearn?

Thank you so much, this is becoming a blocker for me and may lead my to consider other options.

---

<div class="post-metadata">

**Author:** ![sebawita](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/sebawita/32/5_2.png) [@sebawita](https://forum.weaviate.io/u/sebawita)\
**Post date:** [February 15, 2024, 11:32am UTC](https://forum.weaviate.io/t/vector-distance-not-consistent-with-external-cosine-similarity-measure-sklearn/1112/2 "2024-02-15T11:32:03Z")

</div>

Hi @Richard_Y,

Sorry for the late response.  
We’ve missed your post.

The two distances seem pretty close: **0.71** 17 vs **0.71** 964.

Did you expect the results to be exactly the same?

Perhaps there are some differences in how SKLearn and Weaviate calculate cosine distance. 🤔

Do you happen to have the two vectors that you were comparing?
