function test_adjusted_topk
A test function that validates the adjusted top_k calculation by testing multiple base values against the number of supported languages and logging the results.
/tf/active/vicechatdev/docchat/test_multilanguage.py
78 - 93
simple
Purpose
This function serves as a unit test to verify that the config.get_adjusted_top_k() method correctly scales the top_k parameter based on the number of supported languages. It tests multiple base values (5, 10, 15, 20) and logs both the adjusted values and the multiplication factor for verification purposes. This is useful for ensuring that multi-language RAG systems properly adjust their retrieval parameters.
Source Code
def test_adjusted_topk():
"""Test adjusted top_k calculation"""
logger.info("")
logger.info("=" * 80)
logger.info("Testing Adjusted top_k Calculation")
logger.info("=" * 80)
num_languages = len(config.SUPPORTED_LANGUAGES)
logger.info(f"Number of supported languages: {num_languages}")
test_values = [5, 10, 15, 20]
for base_k in test_values:
adjusted = config.get_adjusted_top_k(base_k, num_languages)
logger.info(f" Base top_k={base_k} -> Adjusted top_k={adjusted} (x{adjusted/base_k:.1f})")
logger.info("=" * 80)
Return Value
This function does not return any value (implicitly returns None). It performs logging operations to output test results to the configured logger.
Dependencies
loggingconfig
Required Imports
import logging
import config
Usage Example
import logging
import config
# Setup logger
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO, format='%(message)s')
# Ensure config has required attributes
# config.SUPPORTED_LANGUAGES = ['en', 'es', 'fr', 'de']
# config.get_adjusted_top_k = lambda base_k, num_langs: base_k * num_langs
# Run the test
test_adjusted_topk()
# Expected output:
# ================================================================================
# Testing Adjusted top_k Calculation
# ================================================================================
# Number of supported languages: 4
# Base top_k=5 -> Adjusted top_k=20 (x4.0)
# Base top_k=10 -> Adjusted top_k=40 (x4.0)
# Base top_k=15 -> Adjusted top_k=60 (x4.0)
# Base top_k=20 -> Adjusted top_k=80 (x4.0)
# ================================================================================
Best Practices
- Ensure the logger is properly configured before calling this function to see the test output
- The config module must have both SUPPORTED_LANGUAGES and get_adjusted_top_k() defined before calling
- This function is designed for testing/debugging purposes and should not be used in production code paths
- The function assumes logger is available in the module scope - ensure it's defined as 'logger = logging.getLogger(__name__)' or similar
- Consider wrapping this in a proper test framework (pytest, unittest) for automated testing
- The test values [5, 10, 15, 20] are hardcoded - modify them if testing different ranges is needed
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_adjusted_top_k 76.3% similar
-
function test_config 52.9% similar
-
function test_language_detection_and_translation 52.6% similar
-
function test_rag_engine 44.2% similar
-
function test_incremental_indexing 43.3% similar