Obsidian + Claude → PanAI 3.5 集成架构

整体定位:双向知识流

Obsidian Vault(思想笔记库)
↕ 双向同步
PanAI 3.5(RAG 检索引擎)
↕ 深度推理
Claude API(神学分析层)

Obsidian 不仅是文档来源,更是 PanAI 输出结果的着陆场——分析结论、Golden Path 提取、Scripture Alignment 评分都可以写回 Obsidian 成为永久笔记。

层次一:Obsidian → PanAI 文档入库

1a. 本地文件夹监听(最简方案)

# FastAPI: vault_watcher.py
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import frontmatter # pip install python-frontmatter

class ObsidianVaultHandler(FileSystemEventHandler):
def __init__(self, ingest_fn):
self.ingest = ingest_fn

def on_modified(self, event):
if event.src_path.endswith(“.md”):
self.process_note(event.src_path)

def process_note(self, path: str):
with open(path, “r”, encoding=”utf-8″) as f:
post = frontmatter.load(f)

# 提取 YAML frontmatter 作为 metadata
metadata = {
“title”: post.get(“title”, path.split(“/”)[-1]),
“tags”: post.get(“tags”, []),
“tradition”: post.get(“tradition”, “nee-lee”),
“source”: post.get(“source”, “obsidian”),
“aliases”: post.get(“aliases”, [])
}
content = post.content

# 送入 PanAI 入库管道
self.ingest(content=content, metadata=metadata)

# 启动监听
def watch_vault(vault_path: str):
handler = ObsidianVaultHandler(ingest_fn=panai_ingest)
observer = Observer()
observer.schedule(handler, vault_path, recursive=True)
observer.start()

1b. Obsidian 标签驱动的选择性同步

在 Obsidian 笔记的 frontmatter 中加标签控制入库:


title: 神圣分赐与人类灵魂
tags: [#panai-sync, divine-dispensing, human-spirit]
tradition: nee-lee
type: concept-note
status: ready

只有含 #panai-sync 的笔记才进入 PanAI,保留个人草稿隐私。

层次二:Obsidian 内直接调用 Claude + PanAI

2a. Obsidian Copilot 插件配置

Obsidian Copilot 插件支持自定义 API endpoint:

设置 → Copilot → Custom Model
Base URL: http://localhost:8000/v1 ← PanAI 的 OpenAI 兼容接口
API Key: panai-local-key
Model: panai-rag-claude

在 PanAI FastAPI 中暴露 OpenAI 兼容层:

# FastAPI: openai_compat.py
from fastapi import APIRouter

router = APIRouter(prefix=”/v1″)

@router.post(“/chat/completions”)
async def openai_compat_chat(request: OpenAIRequest):
# 1. 从 Elasticsearch 检索相关文档
context_docs = await es_retrieve(
query=request.messages[-1].content,
top_k=5,
filter={“tradition”: “nee-lee”}
)

# 2. 构建增强 prompt
augmented_prompt = build_rag_prompt(
query=request.messages[-1].content,
context=context_docs,
system=PANAI_SYSTEM_PROMPT
)

# 3. 调用 Claude
claude_response = await call_claude(augmented_prompt)

# 4. 返回 OpenAI 格式
return {
“id”: “panai-” + uuid4().hex,
“object”: “chat.completion”,
“choices”: [{
“message”: {
“role”: “assistant”,
“content”: claude_response
}
}],
“model”: “panai-rag-claude”
}

2b. Obsidian Smart Connections 插件

Smart Connections 插件可以直接指向本地 Ollama/Qwen2.5 做语义检索,与 PanAI 并行运行:

设置 → Smart Connections
Embedding Model: Ollama / nomic-embed-text
Chat Model: Ollama / qwen2.5:14b
Local Server: http://localhost:11434

这样 Obsidian 内部就有两条查询通道:

• Smart Connections:轻量本地语义搜索(Qwen 2.5)
• Copilot → PanAI:带 RAG 的深度神学分析(Claude)

层次三:PanAI 输出写回 Obsidian(最具价值)

分析结论自动生成 Obsidian 笔记,形成知识闭环:

# FastAPI: obsidian_writer.py
from pathlib import Path
from datetime import datetime
import yaml

class ObsidianWriter:
def __init__(self, vault_path: str):
self.vault = Path(vault_path)

def write_analysis(
self,
query: str,
result: dict,
note_type: str = “panai-output”
):
# 根据分析类型选择目标文件夹
folder_map = {
“golden_path”: “PanAI/GoldenPath”,
“scripture_alignment”:”PanAI/ScriptureAlignment”,
“four_dimension”: “PanAI/FourDimension”,
“q_five_step”: “PanAI/QFiveStep”
}
target_folder = self.vault / folder_map.get(note_type, “PanAI/General”)
target_folder.mkdir(parents=True, exist_ok=True)

# 构建 frontmatter
meta = {
“title”: result.get(“title”, query[:40]),
“created”: datetime.now().isoformat(),
“query”: query,
“type”: note_type,
“sources”: result.get(“sources”, []),
“score”: result.get(“score”), # 四维评分
“tags”: [“panai-output”, note_type]
}

# 构建笔记正文
body = self._format_result(result, note_type)

# 写入 .md 文件
filename = f”{datetime.now().strftime(‘%Y%m%d%H%M’)}_{query[:30]}.md”
note_path = target_folder / filename

with open(note_path, “w”, encoding=”utf-8″) as f:
f.write(“—\n”)
f.write(yaml.dump(meta, allow_unicode=True))
f.write(“—\n\n”)
f.write(body)

return str(note_path)

def _format_result(self, result: dict, note_type: str) -> str:
if note_type == “golden_path”:
return f”””## 黄金路径分析

### 五步提取
{result.get(‘five_steps’, ”)}

### 经文对齐层
{result.get(‘alignment_layer’, ”)}

### 来源文献
{self._format_sources(result.get(‘sources’, []))}

### 原始答案
{result.get(‘answer’, ”)}
“””
elif note_type == “four_dimension”:
scores = result.get(“scores”, {})
return f”””## 四维有机框架评分

| 维度 | 得分 |
|——|——|
| 生命流动 | {scores.get(‘life_flow’, ‘N/A’)} |
| 神圣分赐 | {scores.get(‘divine_dispensing’, ‘N/A’)} |
| 教会建造 | {scores.get(‘church_building’, ‘N/A’)} |
| 末世指向 | {scores.get(‘eschatological’, ‘N/A’)} |

### 分析说明
{result.get(‘analysis’, ”)}
“””
# 通用格式
return result.get(“answer”, “”)

def _format_sources(self, sources: list) -> str:
return “\n”.join([
f”- [[{s[‘title’]}]] ({s.get(‘author’, ”)}, {s.get(‘year’, ”)})”
for s in sources
])

层次四:Obsidian Canvas 作为 Neo4j 可视化前端

将 Neo4j 知识图谱导出为 Obsidian Canvas 格式:

# 将 Neo4j 子图导出为 Obsidian Canvas
async def export_to_canvas(concept: str) -> dict:
# 查询 Neo4j 概念子图
result = await neo4j.run(“””
MATCH (c:Concept {name: $concept})-[r]-(related)
RETURN c, r, related LIMIT 30
“””, concept=concept)

# 转换为 Obsidian Canvas JSON 格式
nodes, edges = [], []
for i, record in enumerate(result):
nodes.append({
“id”: record[“c”][“name”],
“type”: “text”,
“text”: f”## {record[‘c’][‘name’]}\n{record[‘c’].get(‘definition’,’‘)}”,
“x”: (i % 5) * 300,
“y”: (i // 5) * 200,
“width”: 250,
“height”: 120
})
edges.append({
“id”: f”edge-{i}”,
“fromNode”: record[“c”][“name”],
“toNode”: record[“related”][“name”],
“label”: record[“r”].type
})

canvas = {“nodes”: nodes, “edges”: edges}

# 写入 Obsidian vault
canvas_path = Path(VAULT_PATH) / f”PanAI/Maps/{concept}.canvas”
with open(canvas_path, “w”) as f:
json.dump(canvas, f, ensure_ascii=False, indent=2)

return canvas

完整集成架构图

Obsidian Vault
├── 📁 PanAI/
│ ├── GoldenPath/ ← Claude 分析写回
│ ├── ScriptureAlignment/ ← L1-L5 评分写回
│ ├── FourDimension/ ← 四维框架评分写回
│ └── Maps/*.canvas ← Neo4j 子图可视化

├── 📝 神学笔记 (#panai-sync) ──► PanAI /ingest

└── 🔌 插件层
├── Copilot → PanAI OpenAI兼容层 → Claude RAG
└── Smart Connections → Ollama/Qwen2.5 本地语义搜索

▼ ▲
PanAI 3.5 FastAPI
├── Elasticsearch(全文)
├── Neo4j(知识图谱)
└── Claude API(深度推理)

推荐的 Obsidian 插件组合

|插件 |用途 |与 PanAI 关系 |
|———————|——-——|——————-|
|**Copilot** |对话界面 |调用 PanAI OpenAI 兼容层|
|**Smart Connections**|本地语义搜索 |Qwen2.5 双轨 |
|**Dataview** |查询 PanAI 输出笔记|结构化展示分析结果 |
|**Templater** |触发 PanAI 分析 |笔记模板自动调用 API |
|**Canvas** |知识图谱可视化 |Neo4j 子图着陆 |

快速启动清单

# 1. PanAI 暴露 OpenAI 兼容接口
# 在 main.py 中添加
app.include_router(openai_compat_router)

# 2. 启动 vault 监听(与 FastAPI 同进程)
vault_watcher.watch_vault(“/path/to/obsidian/vault”)

# 3. .env 添加
OBSIDIAN_VAULT_PATH=/Users/sam/ObsidianVault
OBSIDIAN_OUTPUT_FOLDER=PanAI

# 4. Obsidian Copilot 设置
# Base URL: http://localhost:8000/v1
# Model: panai-rag-claude

最高价值的集成点是层次三——让 PanAI 的 Golden Path 和四维框架分析结果自动写回 Obsidian,逐渐形成一个以 Nee-Lee 神学为核心的永久知识库。你现在 Obsidian Vault 的文件夹结构是否已经有既定分类?可以据此设计更精确的写回路径。