From da71d0b4fe24928cec69d9f85b6e54e7a96ba27a Mon Sep 17 00:00:00 2001 From: Lars Date: Wed, 3 Sep 2025 08:12:31 +0200 Subject: [PATCH] app/core/qdrant.py aktualisiert --- app/core/qdrant.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/app/core/qdrant.py b/app/core/qdrant.py index 86c2896..ffb52a3 100644 --- a/app/core/qdrant.py +++ b/app/core/qdrant.py @@ -1,4 +1,3 @@ -'PY' from __future__ import annotations from dataclasses import dataclass from typing import Tuple @@ -17,26 +16,29 @@ class QdrantConfig: dim: int = DEFAULT_DIM def _collection_names(prefix: str) -> Tuple[str, str, str]: - notes = f"{prefix}_notes" - chunks = f"{prefix}_chunks" - edges = f"{prefix}_edges" - return notes, chunks, edges + """ + Liefert die standardisierten Collection-Namen für Notes, Chunks und Edges. + """ + return f"{prefix}_notes", f"{prefix}_chunks", f"{prefix}_edges" def get_client(cfg: QdrantConfig) -> QdrantClient: + """ + Erstellt einen QdrantClient basierend auf der Config. + """ return QdrantClient(url=cfg.url, api_key=cfg.api_key or None, prefer_grpc=False) def ensure_collections(cfg: QdrantConfig) -> Tuple[str, str, str]: """ - Idempotent: legt {prefix}_{notes,chunks,edges} an (falls fehlend) - und erzeugt sinnvolle Payload-Indizes. + Idempotent: legt {prefix}_notes, {prefix}_chunks, {prefix}_edges an, + falls sie fehlen, und erzeugt sinnvolle Payload-Indizes. """ client = get_client(cfg) notes, chunks, edges = _collection_names(cfg.prefix) - # Vektorkonfigs + # Vektorkonfiguration note_vec = rest.VectorParams(size=cfg.dim, distance=rest.Distance.COSINE) chunk_vec = rest.VectorParams(size=cfg.dim, distance=rest.Distance.COSINE) - edge_vec = rest.VectorParams(size=1, distance=rest.Distance.COSINE) # Dummy-Vektor + edge_vec = rest.VectorParams(size=1, distance=rest.Distance.COSINE) # Dummy für edges def _create_if_missing(name: str, vparam: rest.VectorParams): try: @@ -65,14 +67,18 @@ def ensure_collections(cfg: QdrantConfig) -> Tuple[str, str, str]: field_schema=rest.PayloadSchemaParams(schema=kind), ) except Exception: - pass # existiert schon + # Index existiert evtl. schon → ignorieren + pass + # Notes-Collection for f in ("note_id", "type", "status", "project", "area", "path", "tags"): _ensure_index(notes, f, rest.PayloadSchemaType.KEYWORD) + # Chunks-Collection for f in ("note_id", "type", "tags", "section_title", "section_path", "path", "chunk_index"): _ensure_index(chunks, f, rest.PayloadSchemaType.KEYWORD) + # Edges-Collection for f in ("src_id", "dst_id", "edge_type", "scope"): _ensure_index(edges, f, rest.PayloadSchemaType.KEYWORD)