fix: kb_writer 파일명 경합 수정 + qdrant_id 일관성 보장
- kb_writer: uuid4 short hash로 파일명 경합 방지, counter 기반 중복 방어 제거 - kb_writer: qdrant_id 외부 수신 지원 (body.qdrant_id) - n8n: Set pid 노드 추가 — 분기 전 pid 한 번 생성, Handle Note/Embed & Save Memory에 전달 - Handle Note/Embed & Save Memory: 동일 pid를 kb_writer(qdrant_id)와 Qdrant point ID에 사용 - restore_kb.sh: DS1525+ → 맥미니 knowledge-base 복구 스크립트 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
19
kb_writer.py
19
kb_writer.py
@@ -9,6 +9,7 @@ import re
|
||||
import unicodedata
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.responses import JSONResponse
|
||||
@@ -46,31 +47,25 @@ async def save(request: Request):
|
||||
date_str = now.strftime("%Y-%m-%d")
|
||||
iso_str = now.isoformat()
|
||||
|
||||
# 파일명 생성
|
||||
# 파일명 생성 (uuid4 short hash로 경합 방지)
|
||||
slug = _slugify(title)
|
||||
uid = uuid4().hex[:6]
|
||||
if doc_type == "chat-memory":
|
||||
time_str = now.strftime("%H%M")
|
||||
filename = f"{date_str}T{time_str}-{_slugify(topic)}.md"
|
||||
filename = f"{date_str}T{time_str}-{uid}-{_slugify(topic)}.md"
|
||||
elif doc_type == "news":
|
||||
filename = f"{date_str}-{_slugify(source)}-{slug}.md"
|
||||
filename = f"{date_str}-{uid}-{_slugify(source)}-{slug}.md"
|
||||
else:
|
||||
filename = f"{date_str}-{slug}.md"
|
||||
filename = f"{date_str}-{uid}-{slug}.md"
|
||||
|
||||
# 디렉토리 생성
|
||||
type_dir = BASE_DIR / doc_type / month_dir
|
||||
type_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# 중복 파일명 처리
|
||||
filepath = type_dir / filename
|
||||
counter = 1
|
||||
while filepath.exists():
|
||||
stem = filename.rsplit(".", 1)[0]
|
||||
filepath = type_dir / f"{stem}-{counter}.md"
|
||||
counter += 1
|
||||
|
||||
# YAML frontmatter + 본문
|
||||
tags_yaml = ", ".join(f'"{t}"' for t in tags)
|
||||
qdrant_id = int(now.timestamp() * 1000)
|
||||
qdrant_id = body.get("qdrant_id") or int(now.timestamp() * 1000)
|
||||
|
||||
md_content = f"""---
|
||||
title: "{title}"
|
||||
|
||||
Reference in New Issue
Block a user