From 15016d3448f00aa91232e467fe57e5d16ee108e1 Mon Sep 17 00:00:00 2001 From: MerCry Date: Thu, 26 Feb 2026 19:05:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=80=82=E9=85=8Dqdrant-client=201.17.0?= =?UTF-8?q?=20API=E5=8F=98=E6=9B=B4=EF=BC=8Csearch=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E6=94=B9=E4=B8=BAquery=5Fpoints=20[AC-AISVC-50]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - qdrant-client 1.10+ 版本移除了 search() 方法,改用 query_points() - 使用 collection_exists() 替代 get_collections() 检查集合存在 - 更新返回结果处理:results.points 替代 results - 更新 pyproject.toml 版本约束为 >=1.9.0,<2.0.0 - 修正 README.md 中的 docker 命令示例 --- README.md | 4 ++-- ai-service/app/core/qdrant_client.py | 29 ++++++++++++++++------------ ai-service/pyproject.toml | 2 +- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 8d1dcb0..f001aee 100644 --- a/README.md +++ b/README.md @@ -114,10 +114,10 @@ docker exec -it ai-ollama ollama pull toshk0/nomic-embed-text-v2-moe:Q6_K ```bash # 检查服务状态 -docker compose ps +docker ps # 查看后端日志,找到自动生成的 API Key -docker compose logs -f ai-service | grep "Default API Key" +docker logs -f ai-service | grep "Default API Key" ``` > **重要**: 后端首次启动时会自动生成一个默认 API Key,请从日志中复制该 Key,用于前端配置。 diff --git a/ai-service/app/core/qdrant_client.py b/ai-service/app/core/qdrant_client.py index 85639d2..19b47f4 100644 --- a/ai-service/app/core/qdrant_client.py +++ b/ai-service/app/core/qdrant_client.py @@ -8,7 +8,7 @@ import logging from typing import Any from qdrant_client import AsyncQdrantClient -from qdrant_client.models import Distance, PointStruct, VectorParams, MultiVectorConfig +from qdrant_client.models import Distance, PointStruct, VectorParams, QueryRequest from app.core.config import get_settings @@ -61,8 +61,7 @@ class QdrantClient: collection_name = self.get_collection_name(tenant_id) try: - collections = await client.get_collections() - exists = any(c.name == collection_name for c in collections.collections) + exists = await client.collection_exists(collection_name) if not exists: if use_multi_vector: @@ -213,36 +212,42 @@ class QdrantClient: try: logger.info(f"[AC-AISVC-10] Searching in collection: {collection_name}") + exists = await client.collection_exists(collection_name) + if not exists: + logger.warning(f"[AC-AISVC-10] Collection {collection_name} does not exist") + continue + try: - results = await client.search( + results = await client.query_points( collection_name=collection_name, - query_vector=(vector_name, query_vector), + query=query_vector, + using=vector_name, limit=limit, with_vectors=with_vectors, + score_threshold=score_threshold, ) except Exception as e: - if "vector name" in str(e).lower() or "Not existing vector" in str(e): + if "vector name" in str(e).lower() or "Not existing vector" in str(e) or "using" in str(e).lower(): logger.info( f"[AC-AISVC-10] Collection {collection_name} doesn't have vector named '{vector_name}', " f"trying without vector name (single-vector mode)" ) - results = await client.search( + results = await client.query_points( collection_name=collection_name, - query_vector=query_vector, + query=query_vector, limit=limit, with_vectors=with_vectors, + score_threshold=score_threshold, ) else: raise logger.info( - f"[AC-AISVC-10] Collection {collection_name} returned {len(results)} raw results" + f"[AC-AISVC-10] Collection {collection_name} returned {len(results.points)} raw results" ) hits = [] - for result in results: - if score_threshold is not None and result.score < score_threshold: - continue + for result in results.points: hit = { "id": str(result.id), "score": result.score, diff --git a/ai-service/pyproject.toml b/ai-service/pyproject.toml index a11926f..c497c23 100644 --- a/ai-service/pyproject.toml +++ b/ai-service/pyproject.toml @@ -14,7 +14,7 @@ dependencies = [ "tenacity>=8.2.0", "sqlmodel>=0.0.14", "asyncpg>=0.29.0", - "qdrant-client>=1.7.0", + "qdrant-client>=1.9.0,<2.0.0", "tiktoken>=0.5.0", "openpyxl>=3.1.0", "python-docx>=1.1.0",