Features: - Vector search with Pinecone + Vertex AI embeddings - Document relationships (link, unlink, related, graph) - Auto-link with LLM analysis - Intelligent merge with Gemini Modular structure: - clients/: Pinecone, Vertex AI - tools/: core, relations, stats - utils/: validation, logging Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
"""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)}"
|