Initial commit: RAG MCP Server with relationship graph

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>
This commit is contained in:
kappa
2026-02-03 11:05:45 +09:00
commit 2858e0a344
17 changed files with 1450 additions and 0 deletions

37
tools/stats.py Normal file
View File

@@ -0,0 +1,37 @@
"""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)}"