app/core/qdrant.py aktualisiert
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
afc969dc91
commit
da71d0b4fe
|
|
@ -1,4 +1,3 @@
|
||||||
'PY'
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
@ -17,26 +16,29 @@ class QdrantConfig:
|
||||||
dim: int = DEFAULT_DIM
|
dim: int = DEFAULT_DIM
|
||||||
|
|
||||||
def _collection_names(prefix: str) -> Tuple[str, str, str]:
|
def _collection_names(prefix: str) -> Tuple[str, str, str]:
|
||||||
notes = f"{prefix}_notes"
|
"""
|
||||||
chunks = f"{prefix}_chunks"
|
Liefert die standardisierten Collection-Namen für Notes, Chunks und Edges.
|
||||||
edges = f"{prefix}_edges"
|
"""
|
||||||
return notes, chunks, edges
|
return f"{prefix}_notes", f"{prefix}_chunks", f"{prefix}_edges"
|
||||||
|
|
||||||
def get_client(cfg: QdrantConfig) -> QdrantClient:
|
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)
|
return QdrantClient(url=cfg.url, api_key=cfg.api_key or None, prefer_grpc=False)
|
||||||
|
|
||||||
def ensure_collections(cfg: QdrantConfig) -> Tuple[str, str, str]:
|
def ensure_collections(cfg: QdrantConfig) -> Tuple[str, str, str]:
|
||||||
"""
|
"""
|
||||||
Idempotent: legt {prefix}_{notes,chunks,edges} an (falls fehlend)
|
Idempotent: legt {prefix}_notes, {prefix}_chunks, {prefix}_edges an,
|
||||||
und erzeugt sinnvolle Payload-Indizes.
|
falls sie fehlen, und erzeugt sinnvolle Payload-Indizes.
|
||||||
"""
|
"""
|
||||||
client = get_client(cfg)
|
client = get_client(cfg)
|
||||||
notes, chunks, edges = _collection_names(cfg.prefix)
|
notes, chunks, edges = _collection_names(cfg.prefix)
|
||||||
|
|
||||||
# Vektorkonfigs
|
# Vektorkonfiguration
|
||||||
note_vec = rest.VectorParams(size=cfg.dim, distance=rest.Distance.COSINE)
|
note_vec = rest.VectorParams(size=cfg.dim, distance=rest.Distance.COSINE)
|
||||||
chunk_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):
|
def _create_if_missing(name: str, vparam: rest.VectorParams):
|
||||||
try:
|
try:
|
||||||
|
|
@ -65,14 +67,18 @@ def ensure_collections(cfg: QdrantConfig) -> Tuple[str, str, str]:
|
||||||
field_schema=rest.PayloadSchemaParams(schema=kind),
|
field_schema=rest.PayloadSchemaParams(schema=kind),
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass # existiert schon
|
# Index existiert evtl. schon → ignorieren
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Notes-Collection
|
||||||
for f in ("note_id", "type", "status", "project", "area", "path", "tags"):
|
for f in ("note_id", "type", "status", "project", "area", "path", "tags"):
|
||||||
_ensure_index(notes, f, rest.PayloadSchemaType.KEYWORD)
|
_ensure_index(notes, f, rest.PayloadSchemaType.KEYWORD)
|
||||||
|
|
||||||
|
# Chunks-Collection
|
||||||
for f in ("note_id", "type", "tags", "section_title", "section_path", "path", "chunk_index"):
|
for f in ("note_id", "type", "tags", "section_title", "section_path", "path", "chunk_index"):
|
||||||
_ensure_index(chunks, f, rest.PayloadSchemaType.KEYWORD)
|
_ensure_index(chunks, f, rest.PayloadSchemaType.KEYWORD)
|
||||||
|
|
||||||
|
# Edges-Collection
|
||||||
for f in ("src_id", "dst_id", "edge_type", "scope"):
|
for f in ("src_id", "dst_id", "edge_type", "scope"):
|
||||||
_ensure_index(edges, f, rest.PayloadSchemaType.KEYWORD)
|
_ensure_index(edges, f, rest.PayloadSchemaType.KEYWORD)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user