"""
检查课程知识库的 collection 是否存在
"""

import asyncio
import sys
from pathlib import Path

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

from qdrant_client import AsyncQdrantClient

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


async def check_course_kb_collection():
    """检查课程知识库的 collection 是否存在"""
    settings = get_settings()
    client = QdrantClient()
    qdrant = await client.get_client()
    
    tenant_id = "szmp@ash@2026"
    kb_id = "75c465fe-277d-455d-a30b-4b168adcc03b"
    
    collection_name = client.get_kb_collection_name(tenant_id, kb_id)
    print(f"课程知识库 collection name: {collection_name}")
    
    exists = await qdrant.collection_exists(collection_name)
    print(f"Collection exists: {exists}")
    
    if exists:
        points = await qdrant.scroll(
            collection_name=collection_name,
            limit=5,
            with_vectors=False,
        )
        print(f"\n课程知识库中有 {len(points)} 条数据:")
        for i, point in enumerate(points, 1):
            payload = point.get('payload', {})
            print(f"  [{i}] payload keys: {list(payload.keys())}")
            for key, value in payload.items():
                if key != 'text' and key != 'vector':
                    print(f"      {key}: {value}")
    else:
        print(f"课程知识库 collection 不存在!")


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