Dateien nach "tests" hochladen
All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 3s

This commit is contained in:
Lars 2025-11-16 17:42:08 +01:00
parent 2f86f493d6
commit d22fd77b22

View File

@ -1,12 +1,21 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""
tests/ensure_indexes_and_show.py (compat v1.0.1)
Erzwingt ensure_payload_indexes(...) und zeigt danach payload_schema je Collection.
Kompatibel mit qdrant-client Versionen ohne 'with_payload_schema' im Wrapper.
"""
from __future__ import annotations from __future__ import annotations
import json import json
import os
import urllib.request
import urllib.error
from typing import Any, Dict
from app.core.qdrant import QdrantConfig, get_client, ensure_payload_indexes, collection_names from app.core.qdrant import QdrantConfig, get_client, ensure_payload_indexes, collection_names
from __future__ import annotations
import json, os, urllib.request, urllib.error
from typing import Any, Dict
def _safe_model_dump(obj: Any) -> Dict[str, Any]: def _safe_model_dump(obj: Any) -> Dict[str, Any]:
if hasattr(obj, "model_dump"): if hasattr(obj, "model_dump"):
@ -15,6 +24,7 @@ def _safe_model_dump(obj: Any) -> Dict[str, Any]:
return obj.dict() return obj.dict()
return obj if isinstance(obj, dict) else {} return obj if isinstance(obj, dict) else {}
def _cfg_base_url(cfg) -> str: def _cfg_base_url(cfg) -> str:
if getattr(cfg, "url", None): if getattr(cfg, "url", None):
return cfg.url.rstrip("/") return cfg.url.rstrip("/")
@ -22,6 +32,7 @@ def _cfg_base_url(cfg) -> str:
port = getattr(cfg, "port", None) or os.getenv("QDRANT_PORT") or "6333" port = getattr(cfg, "port", None) or os.getenv("QDRANT_PORT") or "6333"
return f"http://{host}:{port}" return f"http://{host}:{port}"
def _http_get(url: str, api_key: str | None) -> Dict[str, Any]: def _http_get(url: str, api_key: str | None) -> Dict[str, Any]:
req = urllib.request.Request(url, method="GET") req = urllib.request.Request(url, method="GET")
if api_key: if api_key:
@ -32,7 +43,9 @@ def _http_get(url: str, api_key: str | None) -> Dict[str, Any]:
data = resp.read() data = resp.read()
return json.loads(data.decode("utf-8")) return json.loads(data.decode("utf-8"))
def get_collection_payload_schema(client, cfg, name: str) -> Dict[str, Any] | None: def get_collection_payload_schema(client, cfg, name: str) -> Dict[str, Any] | None:
# Strategy 1: OpenAPI client with flag
try: try:
oc = getattr(client, "openapi_client", None) oc = getattr(client, "openapi_client", None)
if oc is not None and hasattr(oc, "collections_api"): if oc is not None and hasattr(oc, "collections_api"):
@ -42,6 +55,7 @@ def get_collection_payload_schema(client, cfg, name: str) -> Dict[str, Any] | No
return (d.get("result") or {}).get("payload_schema") return (d.get("result") or {}).get("payload_schema")
except Exception: except Exception:
pass pass
# Strategy 2: wrapper
try: try:
info = client.get_collection(collection_name=name) info = client.get_collection(collection_name=name)
d = _safe_model_dump(info) d = _safe_model_dump(info)
@ -50,6 +64,7 @@ def get_collection_payload_schema(client, cfg, name: str) -> Dict[str, Any] | No
return ps return ps
except Exception: except Exception:
pass pass
# Strategy 3: direct HTTP
try: try:
base = _cfg_base_url(cfg) base = _cfg_base_url(cfg)
url = f"{base}/collections/{name}?with_payload_schema=true" url = f"{base}/collections/{name}?with_payload_schema=true"
@ -58,6 +73,7 @@ def get_collection_payload_schema(client, cfg, name: str) -> Dict[str, Any] | No
except Exception: except Exception:
return None return None
def main(): def main():
cfg = QdrantConfig.from_env() cfg = QdrantConfig.from_env()
client = get_client(cfg) client = get_client(cfg)
@ -68,5 +84,6 @@ def main():
res[name] = get_collection_payload_schema(client, cfg, name) res[name] = get_collection_payload_schema(client, cfg, name)
print(json.dumps(res, ensure_ascii=False, indent=2)) print(json.dumps(res, ensure_ascii=False, indent=2))
if __name__ == "__main__": if __name__ == "__main__":
main() main()