chore: sync deploy/rag_qdrant_sync_draft.json
This commit is contained in:
1 parent
d9f7dcb233
commit
548963eaa6
1 file changed
+1
@@ -0,0 +1 @@
|
|||||||
|
{"graph":{"nodes":[{"id":"9200000000001","type":"custom","position":{"x":40,"y":260},"positionAbsolute":{"x":40,"y":260},"width":242,"height":108,"selected":false,"sourcePosition":"right","targetPosition":"left","data":{"type":"start","title":"开始","desc":"","selected":false,"variables":[{"type":"text-input","variable":"force","label":"force(填true强制全量重嵌入)","required":false,"options":[],"default":"","hint":"","placeholder":""}]}},{"id":"9200000000002","type":"custom","position":{"x":340,"y":260},"positionAbsolute":{"x":340,"y":260},"width":242,"height":220,"selected":false,"sourcePosition":"right","targetPosition":"left","data":{"type":"code","title":"采集文档指纹与语义分块","desc":"","code_language":"python3","code":"import requests, json, hashlib, re\n\nGITEA = \"http://gitea:3000\"\nREPO = \"admin/mini-erp-fabric-demo\"\nGH = {\"Authorization\": \"token 77c6bd2fdab535b2720821d36b4cfb74aa3bf87c\"}\n\ndef sha256(s):\n return hashlib.sha256(s.encode(\"utf-8\")).hexdigest()\n\ndef raw(path):\n r = requests.get(GITEA + \"/api/v1/repos/\" + REPO + \"/raw/\" + path, headers=GH, timeout=20)\n r.raise_for_status()\n return r.text\n\ndef chunk_doc(path, text):\n lines = text.split(\"\\n\")\n sections = []\n stack = []\n buf = []\n def flush():\n if buf:\n body = \"\\n\".join(buf).strip()\n if body:\n title = \" / \".join(stack) if stack else path\n sections.append((title, body))\n buf.clear()\n for ln in lines:\n m = re.match(r\"^(#{1,4})\\s+(.*)\", ln)\n if m:\n flush()\n lvl = len(m.group(1))\n stack[:] = stack[:lvl-1] + [m.group(2).strip()]\n else:\n buf.append(ln)\n flush()\n chunks = []\n for title, body in sections:\n piece = title + \"\\n\" + body\n if len(piece) <= 1000:\n chunks.append({\"title\": title, \"text\": piece})\n else:\n paras = body.split(\"\\n\\n\")\n cur = \"\"\n for p in paras:\n if len(cur) + len(p) > 850 and cur:\n chunks.append({\"title\": title, \"text\": title + \"\\n\" + cur.strip()})\n cur = cur[-120:] + \"\\n\\n\" + p\n else:\n cur += (\"\\n\\n\" if cur else \"\") + p\n if cur.strip():\n chunks.append({\"title\": title, \"text\": title + \"\\n\" + cur.strip()})\n for i, c in enumerate(chunks):\n c[\"idx\"] = i\n return chunks\n\ndef main(force: str):\n tree = requests.get(GITEA + \"/api/v1/repos/\" + REPO + \"/git/trees/main?recursive=true\", headers=GH, timeout=20).json()\n paths = sorted(t[\"path\"] for t in tree.get(\"tree\", []) if t[\"path\"].startswith(\"docs/\") and t[\"path\"].endswith(\".md\") and t[\"type\"] == \"blob\")\n docs = {}\n for p in paths:\n docs[p] = raw(p)\n doc_hashes = {p: sha256(t) for p, t in docs.items()}\n global_hash = sha256(json.dumps(doc_hashes, sort_keys=True))\n prev = {}\n state_sha = \"\"\n try:\n meta = requests.get(GITEA + \"/api/v1/repos/\" + REPO + \"/contents/05_sync/rag_state.json\", headers=GH, timeout=20).json()\n state_sha = meta.get(\"sha\", \"\")\n import base64\n prev = json.loads(base64.b64decode(meta[\"content\"]).decode(\"utf-8\"))\n except Exception:\n prev = {}\n prev_hashes = prev.get(\"doc_hashes\", {})\n changed = [p for p in paths if doc_hashes[p] != prev_hashes.get(p)]\n deleted = [p for p in prev_hashes if p not in doc_hashes]\n skip = (force or \"\").strip().lower() != \"true\" and not changed and not deleted\n changed_docs = [json.dumps({\"path\": p, \"doc_hash\": doc_hashes[p], \"chunks\": chunk_doc(p, docs[p])}, ensure_ascii=False) for p in changed]\n return {\"skip\": skip, \"global_hash\": global_hash, \"state_sha\": state_sha,\n \"prev_state_json\": json.dumps(prev, ensure_ascii=False),\n \"changed_docs\": changed_docs, \"deleted_paths\": deleted,\n \"doc_hashes_json\": json.dumps(doc_hashes, ensure_ascii=False),\n \"chunk_counts_json\": json.dumps({p: len(chunk_doc(p, docs[p])) for p in paths}, ensure_ascii=False)}","variables":[{"variable":"force","value_selector":["9200000000001","force"],"value_type":"string"}],"outputs":{"skip":{"type":"boolean","children":null},"global_hash":{"type":"string","children":null},"state_sha":{"type":"string","children":null},"prev_state_json":{"type":"string","children":null},"changed_docs":{"type":"array[string]","children":null},"deleted_paths":{"type":"array[string]","children":null},"doc_hashes_json":{"type":"string","children":null},"chunk_counts_json":{"type":"string","children":null}},"selected":false}},{"id":"9200000000003","type":"custom","position":{"x":700,"y":260},"positionAbsolute":{"x":700,"y":260},"width":242,"height":130,"selected":false,"sourcePosLine truncated
|
||||||
Reference in new issue
Block a user