@@ -577,13 +577,17 @@ def build_vector_query(self):
577577 f"Attribute { vector_filter .vector_attribute_name } is not declared with a vector index."
578578 )
579579
580+ if type (vector_filter .threshold ) not in [float , type (None )]:
581+ raise ValueError (f"Vector Filter Threshold must be a float or None." )
582+
580583 vector_filter .index_name = f"vector_index_{ source_class .__label__ } _{ vector_filter .vector_attribute_name } "
581584 vector_filter .node_set_label = source_class .__label__ .lower ()
582585
583586 self ._ast .vector_index_query = vector_filter
584587 self ._ast .return_clause = f"{ vector_filter .node_set_label } , score"
585588 self ._ast .result_class = source_class .__class__
586589
590+
587591 def build_fulltext_query (self ):
588592 """
589593 Query a free text indexed property on the node.
@@ -604,6 +608,9 @@ def build_fulltext_query(self):
604608 f"Attribute { full_text_filter .fulltext_attribute_name } is not declared with a full text index."
605609 )
606610
611+ if type (full_text_filter .threshold ) not in [float , type (None )]:
612+ raise ValueError (f"Full Text Filter Threshold must be a float or None." )
613+
607614 full_text_filter .index_name = f"fulltext_index_{ source_class .__label__ } _{ full_text_filter .fulltext_attribute_name } "
608615 full_text_filter .node_set_label = source_class .__label__ .lower ()
609616
@@ -1005,19 +1012,33 @@ def build_query(self) -> str:
10051012 if self ._ast .vector_index_query :
10061013 query += f"""CALL () {{
10071014 CALL db.index.vector.queryNodes("{ self ._ast .vector_index_query .index_name } ", { self ._ast .vector_index_query .topk } , { self ._ast .vector_index_query .vector } )
1008- YIELD node AS { self ._ast .vector_index_query .node_set_label } , score
1015+ YIELD node AS { self ._ast .vector_index_query .node_set_label } , score """
1016+
1017+ if self ._ast .vector_index_query .threshold :
1018+ query += f"""
1019+ WHERE score >= { self ._ast .vector_index_query .threshold }
1020+ """
1021+
1022+ query += f"""
10091023 RETURN { self ._ast .vector_index_query .node_set_label } , score
1010- }}"""
1024+ }}"""
10111025
10121026 # This ensures that we bring the context of the new nodeSet and score along with us for metadata filtering
10131027 query += f""" WITH { self ._ast .vector_index_query .node_set_label } , score"""
10141028
10151029 if self ._ast .fulltext_index_query :
10161030 query += f"""CALL () {{
10171031 CALL db.index.fulltext.queryNodes("{ self ._ast .fulltext_index_query .index_name } ", "{ self ._ast .fulltext_index_query .query_string } ")
1018- YIELD node AS { self ._ast .fulltext_index_query .node_set_label } , score
1032+ YIELD node AS { self ._ast .fulltext_index_query .node_set_label } , score"""
1033+
1034+ if self ._ast .fulltext_index_query .threshold :
1035+ query += f"""
1036+ WHERE score >= { self ._ast .fulltext_index_query .threshold }
1037+ """
1038+
1039+ query += f"""
10191040 RETURN { self ._ast .fulltext_index_query .node_set_label } , score LIMIT { self ._ast .fulltext_index_query .topk }
1020- }}
1041+ }}
10211042 """
10221043 # This ensures that we bring the context of the new nodeSet and score along with us for metadata filtering
10231044 query += f""" WITH { self ._ast .fulltext_index_query .node_set_label } , score"""
0 commit comments