"""
检查 Qdrant 中实际存储的数据结构
"""

import asyncio
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent.parent))

from app.core.config import get_settings
from app.core.qdrant_client import QdrantClient


async def check_qdrant_data():
    """检查 Qdrant 中的数据"""
    
    client = QdrantClient()
    qdrant = await client.get_client()
    
    tenant_id = "szmp@ash@2026"
    
    print(f"\n{'='*80}")
    print(f"检查租户 {tenant_id} 的 Qdrant 数据")
    print(f"{'='*80}")
    
    collections = await client.list_collections(tenant_id)
    print(f"\n找到 {len(collections)} 个集合:")
    for coll in collections:
        print(f"  - {coll}")
    
    for collection_name in collections[:3]:
        print(f"\n{'='*80}")
        print(f"检查集合: {collection_name}")
        print(f"{'='*80}")
        
        try:
            points = await client.scroll_points(
                collection_name=collection_name,
                limit=5,
            )
            
            print(f"\n找到 {len(points)} 条数据:")
            for i, point in enumerate(points, 1):
                payload = point.get('payload', {})
                print(f"\n  [{i}] id: {point.get('id')}")
                print(f"      metadata 字段:")
                for key, value in payload.items():
                    if key != 'text' and key != 'vector':
                        print(f"        {key}: {value}")
                
                text = payload.get('text', '')
                if text:
                    print(f"      text 预览: {text[:100]}...")
                    
        except Exception as e:
            print(f"  错误: {e}")


if __name__ == "__main__":
    asyncio.run(check_qdrant_data())
