|
117 | 117 |
|
118 | 118 |
|
119 | 119 | def _get_hybrid_query(neo4j_version_is_5_23_or_above: bool) -> str:
|
120 |
| - if neo4j_version_is_5_23_or_above: |
121 |
| - return ( |
122 |
| - f"CALL () {{ {VECTOR_INDEX_QUERY} " |
123 |
| - f"WITH collect({{node:node, score:score}}) AS nodes, max(score) AS vector_index_max_score " |
124 |
| - f"UNWIND nodes AS n " |
125 |
| - f"RETURN n.node AS node, (n.score / vector_index_max_score) AS score " |
126 |
| - f"UNION " |
127 |
| - f"{FULL_TEXT_SEARCH_QUERY} " |
128 |
| - f"WITH collect({{node:node, score:score}}) AS nodes, max(score) AS ft_index_max_score " |
129 |
| - f"UNWIND nodes AS n " |
130 |
| - f"RETURN n.node AS node, (n.score / ft_index_max_score) AS score }} " |
131 |
| - f"WITH node, max(score) AS score ORDER BY score DESC LIMIT $top_k" |
132 |
| - ) |
133 |
| - else: |
134 |
| - return ( |
135 |
| - f"CALL {{ {VECTOR_INDEX_QUERY} " |
136 |
| - f"WITH collect({{node:node, score:score}}) AS nodes, max(score) AS vector_index_max_score " |
137 |
| - f"UNWIND nodes AS n " |
138 |
| - f"RETURN n.node AS node, (n.score / vector_index_max_score) AS score " |
139 |
| - f"UNION " |
140 |
| - f"{FULL_TEXT_SEARCH_QUERY} " |
141 |
| - f"WITH collect({{node:node, score:score}}) AS nodes, max(score) AS ft_index_max_score " |
142 |
| - f"UNWIND nodes AS n " |
143 |
| - f"RETURN n.node AS node, (n.score / ft_index_max_score) AS score }} " |
144 |
| - f"WITH node, max(score) AS score ORDER BY score DESC LIMIT $top_k" |
145 |
| - ) |
| 120 | + call_prefix = "CALL () { " if neo4j_version_is_5_23_or_above else "CALL { " |
| 121 | + query_body = ( |
| 122 | + f"{VECTOR_INDEX_QUERY} " |
| 123 | + "WITH collect({node:node, score:score}) AS nodes, max(score) AS vector_index_max_score " |
| 124 | + "UNWIND nodes AS n " |
| 125 | + "RETURN n.node AS node, (n.score / vector_index_max_score) AS score " |
| 126 | + "UNION " |
| 127 | + f"{FULL_TEXT_SEARCH_QUERY} " |
| 128 | + "WITH collect({node:node, score:score}) AS nodes, max(score) AS ft_index_max_score " |
| 129 | + "UNWIND nodes AS n " |
| 130 | + "RETURN n.node AS node, (n.score / ft_index_max_score) AS score } " |
| 131 | + "WITH node, max(score) AS score ORDER BY score DESC LIMIT $top_k" |
| 132 | + ) |
| 133 | + return call_prefix + query_body |
146 | 134 |
|
147 | 135 |
|
148 | 136 | def _get_filtered_vector_query(
|
|
0 commit comments