Fixes langchain-ai/langchain#33081 - FalkorDB package uses only Euclidean even if Cosine distance is specified #351
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Correct FalkorDB distance strategy handling and typo
What
This PR addresses multiple issues in the FalkorDB integration:
Minor typo & formatting
Corrected EULIDEAN_DISTANCE → EUCLIDEAN_DISTANCE in the distance_strategy validation error message.
Fixed minor formatting issues with quotation marks and backticks for consistency.
Bug fixes in falkordb-langchain distance strategy handling
create_new_index_on_relationship()
now passesself._distance_strategy
instead of always defaulting to Euclidean, so relationship indexes
are created with the caller’s chosen metric.
distance_strategy
parameter to__from
(from_documents
/from_texts
) and forward it when constructing aFalkorDBVector
,ensuring the configured metric is respected throughout.
similarity_search_with_score_by_vector()
to use eithervec.cosineDistance
orvec.euclideanDistance
depending onself._distance_strategy
when performing metadata-filtered searches.Tests
Added unittests to verify correct metric selection across index creation and search.
Why
Previously, FalkorDB integrations always defaulted to Euclidean distance, regardless of the user-specified distance_strategy. This caused incorrect behavior in scenarios where cosine similarity was intended.
Added coverage via unittests.
These changes fix incorrect metric assumptions and make distance selection
consistent across index creation and search.