diff --git a/app/core/qdrant_points.py b/app/core/qdrant_points.py index fa1089b..0b92cbc 100644 --- a/app/core/qdrant_points.py +++ b/app/core/qdrant_points.py @@ -143,13 +143,45 @@ def _coerce_for_collection(client: QdrantClient, collection_name: str, points: L except Exception: return points + +def _try_upsert_with_names(client: QdrantClient, collection: str, points: List[rest.PointStruct]) -> None: + schema = _get_vector_schema(client, collection) + if schema.get("kind") != "named": + raise + names = schema.get("names") or [] + # prefer env-defined names first + pref = _preferred_name(names) + order = [pref] + [n for n in names if n != pref] + for name in order: + converted: List[rest.PointStruct] = [] + for pt in points: + vec = getattr(pt, "vector", None) + if isinstance(vec, dict) and name in vec: + converted.append(pt) + elif vec is not None: + converted.append(rest.PointStruct(id=pt.id, vectors={name: vec}, payload=pt.payload)) + else: + converted.append(pt) + try: + client.upsert(collection_name=collection, points=converted, wait=True) + return + except Exception: + continue + raise # --------------------- Qdrant ops --------------------- def upsert_batch(client: QdrantClient, collection: str, points: List[rest.PointStruct]) -> None: if not points: return pts = _coerce_for_collection(client, collection, points) - client.upsert(collection_name=collection, points=pts, wait=True) + try: + client.upsert(collection_name=collection, points=pts, wait=True) + except Exception as e: + msg = str(e) + if "Not existing vector name" in msg or "named vector" in msg: + _try_upsert_with_names(client, collection, points) + else: + raise # --- Optional search helpers ---