Dateien nach "scripts" hochladen
All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 3s
All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 3s
This commit is contained in:
parent
8b3b343645
commit
afd7675425
|
|
@ -294,32 +294,64 @@ def _resolve_dim(cfg) -> int:
|
||||||
|
|
||||||
|
|
||||||
# ---- Qdrant vector schema detection & point coercion ----
|
# ---- Qdrant vector schema detection & point coercion ----
|
||||||
|
|
||||||
def _get_vector_schema(client, collection_name: str):
|
def _get_vector_schema(client, collection_name: str):
|
||||||
"""
|
"""
|
||||||
Returns dict describing vector schema:
|
Returns dict describing vector schema:
|
||||||
{"kind": "single", "size": <int>} or {"kind": "named", "names": [..]}.
|
{"kind": "single", "size": <int>} or {"kind": "named", "names": [..]}.
|
||||||
Falls back to single if detection fails.
|
Fallbacks to single if detection fails. Honors env override MINDNET_VECTOR_NAME.
|
||||||
"""
|
"""
|
||||||
|
# Env override for preferred name
|
||||||
|
prefer = os.environ.get("MINDNET_VECTOR_NAME") or os.environ.get("QDRANT_VECTOR_NAME")
|
||||||
try:
|
try:
|
||||||
info = client.get_collection(collection_name=collection_name)
|
info = client.get_collection(collection_name=collection_name)
|
||||||
vecs = getattr(info, "vectors", None)
|
vecs = getattr(info, "vectors", None)
|
||||||
# Single-vector config
|
# Single-vector config (VectorParams)
|
||||||
if hasattr(vecs, "size") and isinstance(vecs.size, int):
|
if hasattr(vecs, "size") and isinstance(vecs.size, int):
|
||||||
return {"kind": "single", "size": vecs.size}
|
return {"kind": "single", "size": vecs.size}
|
||||||
# Named-vectors config
|
# Try common mappings for named vectors
|
||||||
cfg = getattr(vecs, "config", None)
|
def _try_names(obj):
|
||||||
if isinstance(cfg, dict) and cfg:
|
if obj is None:
|
||||||
names = list(cfg.keys())
|
return []
|
||||||
if names:
|
# direct dict
|
||||||
return {"kind": "named", "names": names}
|
if isinstance(obj, dict):
|
||||||
|
return list(obj.keys())
|
||||||
|
# object with dict-like attributes
|
||||||
|
for cand in ("config", "configs", "vectors", "map", "data"):
|
||||||
|
sub = getattr(obj, cand, None)
|
||||||
|
if isinstance(sub, dict) and sub:
|
||||||
|
return list(sub.keys())
|
||||||
|
# last resort: inspect __dict__ for dicts
|
||||||
|
try:
|
||||||
|
for v in getattr(obj, "__dict__", {}).values():
|
||||||
|
if isinstance(v, dict) and v:
|
||||||
|
return list(v.keys())
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return []
|
||||||
|
names = _try_names(vecs)
|
||||||
|
# Prefer known names if present
|
||||||
|
if names:
|
||||||
|
pref = None
|
||||||
|
if prefer and prefer in names:
|
||||||
|
pref = prefer
|
||||||
|
else:
|
||||||
|
for k in ("text", "default", "embedding", "content"):
|
||||||
|
if k in names:
|
||||||
|
pref = k
|
||||||
|
break
|
||||||
|
if pref is None:
|
||||||
|
pref = sorted(names)[0]
|
||||||
|
return {"kind": "named", "names": names, "primary": pref}
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
return {"kind": "single", "size": None}
|
return {"kind": "single", "size": None}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _coerce_points_for_collection(client, collection_name: str, points: list):
|
def _coerce_points_for_collection(client, collection_name: str, points: list):
|
||||||
"""
|
"""
|
||||||
If collection uses named vectors, wrap each point's .vector into .vectors{<name>: vector}.
|
If collection uses named vectors, wrap each point's .vector into .vector={name: vector}.
|
||||||
Leaves points without vectors (e.g., edges) untouched.
|
Leaves points without vectors (e.g., edges) untouched.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
|
@ -329,12 +361,18 @@ def _coerce_points_for_collection(client, collection_name: str, points: list):
|
||||||
names = schema.get("names") or []
|
names = schema.get("names") or []
|
||||||
if not names:
|
if not names:
|
||||||
return points
|
return points
|
||||||
primary = names[0]
|
primary = schema.get("primary") or names[0]
|
||||||
fixed = []
|
fixed = []
|
||||||
for pt in points:
|
for pt in points:
|
||||||
vec = getattr(pt, "vector", None)
|
vec = getattr(pt, "vector", None)
|
||||||
if vec is not None:
|
# Some client builds may store named vectors in .vectors already; keep if correct
|
||||||
fixed.append(rest.PointStruct(id=pt.id, vectors={primary: vec}, payload=pt.payload))
|
vectors_attr = getattr(pt, "vectors", None)
|
||||||
|
if isinstance(vectors_attr, dict) and vectors_attr:
|
||||||
|
fixed.append(pt)
|
||||||
|
continue
|
||||||
|
if vec is not None and not isinstance(vec, dict):
|
||||||
|
# convert to named map
|
||||||
|
fixed.append(rest.PointStruct(id=pt.id, vector={primary: vec}, payload=pt.payload))
|
||||||
else:
|
else:
|
||||||
fixed.append(pt)
|
fixed.append(pt)
|
||||||
return fixed
|
return fixed
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user