from typing import List, Dict, Any
from qdrant_client import QdrantClient
from jingrow.config import Config


def get_qdrant_client():
    """获取Qdrant客户端连接"""
    try:
        client = QdrantClient(host=Config.qdrant_host, port=Config.qdrant_port)
        client.get_collections()
        return client
    except Exception as e:
        return None


def search_vectors(collection_name: str, query_vector: List[float], limit: int = 10, 
                  score_threshold: float = 0.7) -> List[Dict[str, Any]]:
    """在Qdrant中搜索相似向量"""
    
    client = get_qdrant_client()
    if not client:
        return []
    
    try:
        search_result = client.search(
            collection_name=collection_name,
            query_vector=query_vector,
            limit=limit,
            score_threshold=score_threshold
        )
        
        results = []
        for hit in search_result:
            results.append({
                "id": hit.id,
                "score": hit.score,
                "payload": hit.payload
            })
        
        return results
    except Exception as e:
        return []


