MVP stage 3: media assets (video, atom_assets, publications, idempotent)

This commit is contained in:
neo committed 2026-09-14 14:48:26 +05:00
1 parent 845fa70af7
commit e48158b033
2 files changed
+269 -4

No files matched your search

+9 -4
View File
@@ -188,9 +188,10 @@ def ensure_project(conn, project: str) -> str:
def insert_atoms(conn, project_id: str, atoms: list[Atom]) -> int:
"""Вставить атомы в atoms. Возвращает количество."""
"""Вставить атомы в atoms. Дубли проекта — удалить перед вставкой. Возвращает количество."""
n = 0
with conn.cursor() as cur:
cur.execute("DELETE FROM atoms WHERE project_id = %s", (project_id,))
for atom in atoms:
row = atom.to_row()
cur.execute("""
@@ -242,9 +243,13 @@ def generate_web_version(atom: Atom) -> str:
# ---------------------------------------------------------------------------
# Qdrant
# ---------------------------------------------------------------------------
def ensure_collection(client: QdrantClient) -> None:
if client.collection_exists(COLLECTION):
def clear_collection(client: QdrantClient) -> None:
"""Полностью очистить коллекцию Qdrant (идемпотентность stage 1)."""
import os
if os.environ.get("QDRANT_KEEP"):
return
if client.collection_exists(COLLECTION):
client.delete_collection(collection_name=COLLECTION)
client.create_collection(
collection_name=COLLECTION,
vectors_config=VectorParams(size=DIM, distance=Distance.COSINE),
@@ -305,7 +310,7 @@ def main():
# 3. Qdrant (эмбеддинги + дедуп)
start = time.time()
client = QdrantClient(host="127.0.0.1", port=6333)
ensure_collection(client)
clear_collection(client)
n_emb = upsert_qdrant(client, all_atoms)
print(f" ✓ Qdrant: {n_emb} эмбеддингов за {time.time()-start:.1f}с (~{ (time.time()-start)/n_emb*1000:.0f}ms/atom)")