From 76bec8e1d788d169ee7428516d64ee8e3c37a306 Mon Sep 17 00:00:00 2001 From: Oskar Hane Date: Tue, 7 May 2024 11:20:07 +0200 Subject: [PATCH] Add debug logging in retrievers (#28) * 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. * Drop value serialization and leave that to the logger * Add string placeholder in logger message * Improve log message --- src/neo4j_genai/retrievers/hybrid.py | 10 ++++++++++ src/neo4j_genai/retrievers/vector.py | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/neo4j_genai/retrievers/hybrid.py b/src/neo4j_genai/retrievers/hybrid.py index a9311d069..0690555a2 100644 --- a/src/neo4j_genai/retrievers/hybrid.py +++ b/src/neo4j_genai/retrievers/hybrid.py @@ -21,6 +21,9 @@ 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 + +logger = logging.getLogger(__name__) class HybridRetriever(Retriever): @@ -83,6 +86,9 @@ def search( search_query = get_search_query(SearchType.HYBRID, self.return_properties) + logger.debug("HybridRetriever Cypher parameters: %s", parameters) + logger.debug("HybridRetriever Cypher query: %s", search_query) + records, _, _ = self.driver.execute_query(search_query, parameters) return records @@ -157,5 +163,9 @@ def search( search_query = get_search_query( SearchType.HYBRID, retrieval_query=self.retrieval_query ) + + logger.debug("HybridCypherRetriever Cypher parameters: %s", parameters) + logger.debug("HybridCypherRetriever Cypher query: %s", 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 771ce3520..954cd04ed 100644 --- a/src/neo4j_genai/retrievers/vector.py +++ b/src/neo4j_genai/retrievers/vector.py @@ -26,6 +26,9 @@ SearchType, ) from neo4j_genai.neo4j_queries import get_search_query +import logging + +logger = logging.getLogger(__name__) class VectorRetriever(Retriever): @@ -92,6 +95,9 @@ def search( search_query = get_search_query(SearchType.VECTOR, self.return_properties) + logger.debug("VectorRetriever Cypher parameters: %s", parameters) + logger.debug("VectorRetriever Cypher query: %s", search_query) + records, _, _ = self.driver.execute_query(search_query, parameters) try: @@ -178,5 +184,9 @@ def search( search_query = get_search_query( SearchType.VECTOR, retrieval_query=self.retrieval_query ) + + logger.debug("VectorCypherRetriever Cypher parameters: %s", parameters) + logger.debug("VectorCypherRetriever Cypher query: %s", search_query) + records, _, _ = self.driver.execute_query(search_query, parameters) return records