"""Statistics and monitoring tools.""" from clients import get_index from utils.logging import get_logger from config import AUTO_LINK_THRESHOLD, AUTO_LINK_TOP_K logger = get_logger(__name__) def rag_stats() -> str: """ Return RAG database statistics. Returns: Formatted statistics or error message """ try: index = get_index() stats = index.describe_index_stats() total = stats.get("total_vector_count", 0) output = [ "=== RAG Statistics ===", f"Total documents: {total}", f"Dimension: {stats.get('dimension', 'N/A')}", f"Index fullness: {stats.get('index_fullness', 'N/A')}", "", "=== Auto-link Settings ===", f"Threshold: {AUTO_LINK_THRESHOLD}", f"Top-K candidates: {AUTO_LINK_TOP_K}" ] logger.info(f"Stats retrieved: {total} documents") return "\n".join(output) except Exception as e: logger.error(f"rag_stats failed: {str(e)}", exc_info=True) return f"Error: {str(e)}"