From e7c608589aee2f300cef1667bfb3d01a177bc636 Mon Sep 17 00:00:00 2001 From: Oskar Hane Date: Fri, 26 Apr 2024 14:22:01 +0200 Subject: [PATCH] Minor changes to the README --- src/neo4j_genai/queries.py | 56 -------------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 src/neo4j_genai/queries.py diff --git a/src/neo4j_genai/queries.py b/src/neo4j_genai/queries.py deleted file mode 100644 index 752677d5f..000000000 --- a/src/neo4j_genai/queries.py +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright (c) "Neo4j" -# Neo4j Sweden AB [https://neo4j.com] -# # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# # -# https://www.apache.org/licenses/LICENSE-2.0 -# # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from typing import Optional - -from neo4j_genai.types import SearchType - - -def get_search_query( - search_type: SearchType, - return_properties: Optional[list[str]] = None, - retrieval_query: Optional[str] = None, -): - query_map = { - SearchType.VECTOR: ( - "CALL db.index.vector.queryNodes($index_name, $top_k, $query_vector) " - ), - SearchType.HYBRID: ( - "CALL { " - "CALL db.index.vector.queryNodes($vector_index_name, $top_k, $query_vector) " - "YIELD node, score " - "RETURN node, score UNION " - "CALL db.index.fulltext.queryNodes($fulltext_index_name, $query_text, {limit: $top_k}) " - "YIELD node, score " - "WITH collect({node:node, score:score}) AS nodes, max(score) AS max " - "UNWIND nodes AS n " - "RETURN n.node AS node, (n.score / max) AS score " - "} " - "WITH node, max(score) AS score ORDER BY score DESC LIMIT $top_k " - ), - } - - base_query = query_map[search_type] - additional_query = "" - - if retrieval_query: - additional_query += retrieval_query - elif return_properties: - return_properties_cypher = ", ".join([f".{prop}" for prop in return_properties]) - additional_query += "YIELD node, score " - additional_query += f"RETURN node {{{return_properties_cypher}}} as node, score" - else: - additional_query += "RETURN node, score" - - return base_query + additional_query