FAISS returns same score after I changed distance_strategy from Eucledian to Cosine #16538
Replies: 3 comments 2 replies
-
🤖 Based on the code you've provided, it seems like you're correctly setting the In FAISS, the distance metric is determined when the index is created and cannot be changed afterwards. The Therefore, if you want to use a different distance metric, you would need to create a new FAISS index with the desired distance metric. Unfortunately, there is no evidence of a method to create a new FAISS index with a specified distance metric in the provided context. Therefore, you would need to modify the LangChain code or create the index outside of LangChain and then load it. Please note that the cosine distance is not directly supported by FAISS. However, you can achieve the effect of cosine distance by normalizing your vectors (which it appears you are doing, as You can refer to the source code of LangChain's FAISS class here for more details. Regarding the I hope this helps! If you have any more questions, feel free to ask. SourcesThis response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
Related discussion: #16224 |
Beta Was this translation helpful? Give feedback.
-
Hi, I am facing the similar issue, even though I setted distance_strategy to cosine still whenever I prints distance metric used it shows distance strategy is 'euclidean'. |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
This is how I change the distance metrics:
and this is how I check the distance score:
Description
Im using LangChain x FAISS. And everytime I compare the distance score between the default euclidean and cosine, it will always give me the same score, so I dont know maybe I did something wrong (or not). I was expecting different scores. Could you check please?
System Info
langchain==0.1.0
langchain-community==0.0.11
langchain-core==0.1.8
platform: windows
Python 3.11.5
Beta Was this translation helpful? Give feedback.
All reactions