app/core/qdrant_points.py aktualisiert
Some checks failed
Deploy mindnet to llm-node / deploy (push) Failing after 1s
Some checks failed
Deploy mindnet to llm-node / deploy (push) Failing after 1s
This commit is contained in:
parent
38fd7420ff
commit
643a672045
|
|
@ -4,24 +4,16 @@
|
||||||
Name: app/core/qdrant_points.py
|
Name: app/core/qdrant_points.py
|
||||||
Version: v1.2.0 (2025-09-05)
|
Version: v1.2.0 (2025-09-05)
|
||||||
|
|
||||||
Kurzbeschreibung:
|
Kurzbeschreibung
|
||||||
Erzeugt Qdrant-Points für Notes, Chunks, Edges.
|
Qdrant-Points für Notes/Chunks/Edges.
|
||||||
- Edges: 1D-Dummy-Vektor (Workaround).
|
NEU: Edge-ID berücksichtigt optional 'occ' (Occurrence je Match):
|
||||||
- **NEU**: Edge-ID berücksichtigt optional 'occ' (Occurrence-Index),
|
"{kind}:{src}->{tgt}#{seq}@{occ}"
|
||||||
um Mehrfach-Vorkommen von Wikilinks eindeutig zu machen.
|
|
||||||
|
|
||||||
Aufruf:
|
Aufruf
|
||||||
from app.core.qdrant_points import (
|
from app.core.qdrant_points import points_for_note, points_for_chunks, points_for_edges, upsert_batch
|
||||||
points_for_note, points_for_chunks, points_for_edges, upsert_batch
|
|
||||||
)
|
|
||||||
|
|
||||||
Kompatibilität:
|
Changelog
|
||||||
- Bestehende Edge-IDs bleiben gültig; neue Edges können ein '@{occ}'-Suffix in der ID haben.
|
v1.2.0: Edge-ID mit '@occ' falls vorhanden.
|
||||||
- Idempotenz weiterhin über UUIDv5 auf stabilem Key.
|
|
||||||
|
|
||||||
Changelog:
|
|
||||||
v1.2.0: Edge-ID-Logik erweitert: "{kind}:{src}->{tgt}#{seq}@{occ}" wenn 'occ' vorhanden.
|
|
||||||
v1.1.x: Stabilisierung Note-/Chunk-Upsert.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
@ -29,23 +21,13 @@ import uuid
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
from qdrant_client.http import models as rest
|
from qdrant_client.http import models as rest
|
||||||
|
|
||||||
|
|
||||||
def _names(prefix: str) -> Tuple[str, str, str]:
|
def _names(prefix: str) -> Tuple[str, str, str]:
|
||||||
return f"{prefix}_notes", f"{prefix}_chunks", f"{prefix}_edges"
|
return f"{prefix}_notes", f"{prefix}_chunks", f"{prefix}_edges"
|
||||||
|
|
||||||
|
|
||||||
def _to_uuid(stable_key: str) -> str:
|
def _to_uuid(stable_key: str) -> str:
|
||||||
"""Stabile UUIDv5 aus einem String-Key (deterministisch)."""
|
|
||||||
return str(uuid.uuid5(uuid.NAMESPACE_URL, stable_key))
|
return str(uuid.uuid5(uuid.NAMESPACE_URL, stable_key))
|
||||||
|
|
||||||
|
def points_for_note(prefix: str, note_payload: dict, note_vec: List[float] | None, dim: int) -> Tuple[str, List[rest.PointStruct]]:
|
||||||
def points_for_note(
|
|
||||||
prefix: str,
|
|
||||||
note_payload: dict,
|
|
||||||
note_vec: List[float] | None,
|
|
||||||
dim: int,
|
|
||||||
) -> Tuple[str, List[rest.PointStruct]]:
|
|
||||||
"""Notes-Collection: falls kein Note-Embedding -> Nullvektor der Länge dim."""
|
|
||||||
notes_col, _, _ = _names(prefix)
|
notes_col, _, _ = _names(prefix)
|
||||||
vector = note_vec if note_vec is not None else [0.0] * int(dim)
|
vector = note_vec if note_vec is not None else [0.0] * int(dim)
|
||||||
raw_note_id = note_payload.get("note_id") or note_payload.get("id") or "missing-note-id"
|
raw_note_id = note_payload.get("note_id") or note_payload.get("id") or "missing-note-id"
|
||||||
|
|
@ -53,18 +35,7 @@ def points_for_note(
|
||||||
pt = rest.PointStruct(id=point_id, vector=vector, payload=note_payload)
|
pt = rest.PointStruct(id=point_id, vector=vector, payload=note_payload)
|
||||||
return notes_col, [pt]
|
return notes_col, [pt]
|
||||||
|
|
||||||
|
def points_for_chunks(prefix: str, chunk_payloads: List[dict], vectors: List[List[float]]) -> Tuple[str, List[rest.PointStruct]]:
|
||||||
def points_for_chunks(
|
|
||||||
prefix: str,
|
|
||||||
chunk_payloads: List[dict],
|
|
||||||
vectors: List[List[float]],
|
|
||||||
) -> Tuple[str, List[rest.PointStruct]]:
|
|
||||||
"""
|
|
||||||
Chunks-Collection: erwartet pro Chunk einen Vektor.
|
|
||||||
Robustheit:
|
|
||||||
- Fehlt 'chunk_id', nutze 'id', sonst baue '${note_id}#${i}' (1-basiert).
|
|
||||||
- Schreibe die abgeleitete ID zurück in die Payload (pl['chunk_id']).
|
|
||||||
"""
|
|
||||||
_, chunks_col, _ = _names(prefix)
|
_, chunks_col, _ = _names(prefix)
|
||||||
points: List[rest.PointStruct] = []
|
points: List[rest.PointStruct] = []
|
||||||
for i, (pl, vec) in enumerate(zip(chunk_payloads, vectors), start=1):
|
for i, (pl, vec) in enumerate(zip(chunk_payloads, vectors), start=1):
|
||||||
|
|
@ -77,13 +48,12 @@ def points_for_chunks(
|
||||||
points.append(rest.PointStruct(id=point_id, vector=vec, payload=pl))
|
points.append(rest.PointStruct(id=point_id, vector=vec, payload=pl))
|
||||||
return chunks_col, points
|
return chunks_col, points
|
||||||
|
|
||||||
|
|
||||||
def points_for_edges(prefix: str, edge_payloads: List[dict]) -> Tuple[str, List[rest.PointStruct]]:
|
def points_for_edges(prefix: str, edge_payloads: List[dict]) -> Tuple[str, List[rest.PointStruct]]:
|
||||||
"""
|
"""
|
||||||
Edges-Collection mit 1D-Dummy-Vektor.
|
Edges-Collection mit 1D-Dummy-Vektor (keine Vektorsuche auf Edges).
|
||||||
ID-Bildung:
|
Stable-ID:
|
||||||
- Basis: "{kind}:{src}->{tgt}#{seq}"
|
Basis: "{kind}:{src}->{tgt}#{seq}"
|
||||||
- **Neu**: Falls 'occ' in Payload, erweitern zu "{...}@{occ}"
|
Neu: Falls 'occ' vorhanden -> "{…}@{occ}"
|
||||||
"""
|
"""
|
||||||
_, _, edges_col = _names(prefix)
|
_, _, edges_col = _names(prefix)
|
||||||
points: List[rest.PointStruct] = []
|
points: List[rest.PointStruct] = []
|
||||||
|
|
@ -94,7 +64,7 @@ def points_for_edges(prefix: str, edge_payloads: List[dict]) -> Tuple[str, List[
|
||||||
s = pl.get("source_id", "unknown-src")
|
s = pl.get("source_id", "unknown-src")
|
||||||
t = pl.get("target_id", "unknown-tgt")
|
t = pl.get("target_id", "unknown-tgt")
|
||||||
seq = pl.get("seq") or pl.get("order") or ""
|
seq = pl.get("seq") or pl.get("order") or ""
|
||||||
occ = pl.get("occ") # optionaler Occurrence-Index
|
occ = pl.get("occ")
|
||||||
base = f"{kind}:{s}->{t}#{seq}"
|
base = f"{kind}:{s}->{t}#{seq}"
|
||||||
edge_id = f"{base}@{occ}" if occ is not None else base
|
edge_id = f"{base}@{occ}" if occ is not None else base
|
||||||
pl["edge_id"] = edge_id
|
pl["edge_id"] = edge_id
|
||||||
|
|
@ -102,7 +72,6 @@ def points_for_edges(prefix: str, edge_payloads: List[dict]) -> Tuple[str, List[
|
||||||
points.append(rest.PointStruct(id=point_id, vector=[0.0], payload=pl))
|
points.append(rest.PointStruct(id=point_id, vector=[0.0], payload=pl))
|
||||||
return edges_col, points
|
return edges_col, points
|
||||||
|
|
||||||
|
|
||||||
def upsert_batch(client, collection: str, points: List[rest.PointStruct]) -> None:
|
def upsert_batch(client, collection: str, points: List[rest.PointStruct]) -> None:
|
||||||
if not points:
|
if not points:
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user