From 66e458065f94dfe247db417310c5eb3c005fa6d9 Mon Sep 17 00:00:00 2001 From: Oskar Hane Date: Mon, 6 May 2024 11:39:57 +0200 Subject: [PATCH] Add debug logging in retrievers We do not set any basic config on the loggers, but leave that for aplication developers to keep the log format consistent with their existing ones. --- src/neo4j_genai/retrievers/hybrid.py | 13 +++++++++++++ src/neo4j_genai/retrievers/vector.py | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/neo4j_genai/retrievers/hybrid.py b/src/neo4j_genai/retrievers/hybrid.py index a9311d06..3ca0cbb3 100644 --- a/src/neo4j_genai/retrievers/hybrid.py +++ b/src/neo4j_genai/retrievers/hybrid.py @@ -21,6 +21,10 @@ from neo4j_genai.retrievers.base import Retriever from neo4j_genai.types import HybridSearchModel, SearchType, HybridCypherSearchModel from neo4j_genai.neo4j_queries import get_search_query +import logging +import json + +logger = logging.getLogger(__name__) class HybridRetriever(Retriever): @@ -83,6 +87,9 @@ def search( search_query = get_search_query(SearchType.HYBRID, self.return_properties) + logger.debug(f"HybridRetriever Cypher parameters: {json.dumps(parameters)}") + logger.debug(f"HybridRetriever Cypher query: {search_query}") + records, _, _ = self.driver.execute_query(search_query, parameters) return records @@ -157,5 +164,11 @@ def search( search_query = get_search_query( SearchType.HYBRID, retrieval_query=self.retrieval_query ) + + logger.debug( + f"HybridCypherRetriever Cypher parameters: {json.dumps(parameters)}" + ) + logger.debug(f"HybridCypherRetriever Cypher query: {search_query}") + records, _, _ = self.driver.execute_query(search_query, parameters) return records diff --git a/src/neo4j_genai/retrievers/vector.py b/src/neo4j_genai/retrievers/vector.py index 771ce352..5dfcc61c 100644 --- a/src/neo4j_genai/retrievers/vector.py +++ b/src/neo4j_genai/retrievers/vector.py @@ -26,6 +26,10 @@ SearchType, ) from neo4j_genai.neo4j_queries import get_search_query +import logging +import json + +logger = logging.getLogger(__name__) class VectorRetriever(Retriever): @@ -92,6 +96,9 @@ def search( search_query = get_search_query(SearchType.VECTOR, self.return_properties) + logger.debug(f"VectorRetriever Cypher parameters: {json.dumps(parameters)}") + logger.debug(f"VectorRetriever Cypher query: {search_query}") + records, _, _ = self.driver.execute_query(search_query, parameters) try: @@ -178,5 +185,11 @@ def search( search_query = get_search_query( SearchType.VECTOR, retrieval_query=self.retrieval_query ) + + logger.debug( + f"VectorCypherRetriever Cypher parameters: {json.dumps(parameters)}" + ) + logger.debug(f"VectorCypherRetriever Cypher query: {search_query}") + records, _, _ = self.driver.execute_query(search_query, parameters) return records