app/core/qdrant_points.py aktualisiert
Some checks failed
Deploy mindnet to llm-node / deploy (push) Failing after 2s
Some checks failed
Deploy mindnet to llm-node / deploy (push) Failing after 2s
This commit is contained in:
parent
fa9fb27428
commit
9db5694dbf
|
|
@ -1,5 +1,5 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
import os
|
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
|
||||||
|
|
||||||
|
|
@ -8,39 +8,59 @@ 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 points_for_note(prefix: str, note_payload: dict, note_vec: List[float] | None, dim: int) -> Tuple[str, List[rest.PointStruct]]:
|
def _to_uuid(stable_key: str) -> str:
|
||||||
"""
|
"""
|
||||||
Liefert (collection_name, [PointStruct]) für die Notes-Collection.
|
Erzeuge eine stabile UUIDv5 aus einem stabilen String-Key (z. B. note_id, chunk_id, edge_id).
|
||||||
Falls kein Note-Embedding übergeben wurde, wird ein Nullvektor der Länge `dim` verwendet.
|
Wir verwenden NAMESPACE_URL, damit die UUIDs deterministisch sind.
|
||||||
Hintergrund: Die Notes-Collection ist in ensure_collections mit Vektor-Dimension angelegt.
|
"""
|
||||||
|
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]]:
|
||||||
|
"""
|
||||||
|
(collection_name, [PointStruct]) für die Notes-Collection.
|
||||||
|
Falls kein Note-Embedding vorhanden -> 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)
|
||||||
pt = rest.PointStruct(id=note_payload["note_id"], vector=vector, payload=note_payload)
|
# Qdrant-Point-ID MUSS int oder UUID sein -> aus note_id eine UUIDv5 machen
|
||||||
|
point_id = _to_uuid(note_payload["note_id"])
|
||||||
|
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]]:
|
||||||
"""
|
"""
|
||||||
Liefert (collection_name, [PointStruct]) für die Chunks-Collection.
|
(collection_name, [PointStruct]) für die Chunks-Collection.
|
||||||
Erwartet für jeden Chunk einen Embedding-Vektor (oder Nullvektor, wenn --skip-embed).
|
Erwartet pro Chunk einen Vektor (oder Nullvektor, wenn --skip-embed).
|
||||||
"""
|
"""
|
||||||
_, chunks_col, _ = _names(prefix)
|
_, chunks_col, _ = _names(prefix)
|
||||||
points: List[rest.PointStruct] = []
|
points: List[rest.PointStruct] = []
|
||||||
for pl, vec in zip(chunk_payloads, vectors):
|
for pl, vec in zip(chunk_payloads, vectors):
|
||||||
points.append(rest.PointStruct(id=pl["chunk_id"], vector=vec, payload=pl))
|
point_id = _to_uuid(pl["chunk_id"])
|
||||||
|
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]]:
|
||||||
"""
|
"""
|
||||||
Liefert (collection_name, [PointStruct]) für die Edges-Collection.
|
(collection_name, [PointStruct]) für die Edges-Collection.
|
||||||
Edges-Collection ist VEKTORENLOS angelegt → nur Payload.
|
Edges-Collection ist ohne Vektor angelegt -> nur Payload + UUID-IDs.
|
||||||
"""
|
"""
|
||||||
_, _, edges_col = _names(prefix)
|
_, _, edges_col = _names(prefix)
|
||||||
points: List[rest.PointStruct] = []
|
points: List[rest.PointStruct] = []
|
||||||
for pl in edge_payloads:
|
for pl in edge_payloads:
|
||||||
points.append(rest.PointStruct(id=pl["edge_id"], payload=pl))
|
point_id = _to_uuid(pl["edge_id"])
|
||||||
|
points.append(rest.PointStruct(id=point_id, payload=pl))
|
||||||
return edges_col, points
|
return edges_col, points
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user