<?php
// chatbot/rag/debug_search.php
require_once __DIR__ . '/search.php';
require_once dirname(__DIR__) . '/../apikey/google_vertex_api.txt'; // Path verify

$apiKeyPath = dirname(__DIR__, 2) . '/apikey/google_vertex_api.txt';
$apiKey = trim(file_get_contents($apiKeyPath));

echo "=== RAG Debug Tool ===\n";
echo "API Key Path: $apiKeyPath\n";
echo "API Key Length: " . strlen($apiKey) . "\n";

$search = new VectorSearch();

// Reflect into the object to check vector count
$reflection = new ReflectionClass($search);
$property = $reflection->getProperty('vectors');
$property->setAccessible(true);
$vectors = $property->getValue($search);

echo "Loaded Vectors Count: " . count($vectors) . "\n";

if (empty($vectors)) {
    echo "CRITICAL ERROR: No vectors loaded. Check vectors.json format or path.\n";
    exit;
}

$query = "개발 dump";
echo "Testing Query: '$query'\n";

// Run Search
try {
    $results = $search->search($query, $apiKey, 3);
    echo "Search Result Count: " . count($results) . "\n";
    print_r($results);
} catch (Exception $e) {
    echo "Search Error: " . $e->getMessage() . "\n";
}
?>
