Skip to content

Commit 55f8150

Browse files
authored
Fix from_existing_graph method & normalize the cosine distance (#238)
fixes: - #237 - #236
1 parent 814a6f5 commit 55f8150

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

libs/community/langchain_community/vectorstores/falkordb_vector.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def _get_search_index_query(
137137
"CALL db.idx.vector.queryNodes($entity_label, "
138138
"$entity_property, $k, vecf32($embedding)) "
139139
"YIELD node, score "
140+
"WITH node, (2 - score) / 2 AS score "
140141
)
141142
elif search_type == SearchType.HYBRID:
142143
return (
@@ -1245,8 +1246,8 @@ def from_existing_graph(
12451246
f"MATCH (n:`{node_label}`) "
12461247
f"WHERE n.`{embedding_node_property}` IS null "
12471248
"AND any(k IN $props WHERE n[k] IS NOT null) "
1248-
"RETURN id(n) AS id, "
1249-
"coalesce(n.text, '') AS text "
1249+
"RETURN id(n) AS id, reduce(str='',"
1250+
"k IN $props | str + '\\n' + k + ':' + coalesce(n[k], '')) AS text "
12501251
"LIMIT 1000"
12511252
)
12521253
data = store._query(fetch_query, params={"props": text_node_properties})

0 commit comments

Comments
 (0)