feat: integrate RAG rag_jrxml submodule and fix Anthropic API key

Add rag submodule for semantic JRXML chunk retrieval, refactor
retrieve node to use RAGSearcher, and fix missing api_key in
Anthropic SDK client initialization.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-19 09:42:57 +08:00
parent 4416c20b77
commit b280c2b453
10 changed files with 248 additions and 115 deletions
+4 -18
View File
@@ -10,7 +10,6 @@ from typing import Dict
from dotenv import load_dotenv
from agent.state import AgentState
from backend.embeddings import get_embeddings
from backend.llm import get_llm
from backend.validation import validate_jrxml
@@ -422,26 +421,13 @@ def _now_iso() -> str:
def retrieve(state: AgentState) -> Dict:
"""在 Chroma 中搜索相关的 JRXML 模板和组件。"""
"""在 Chroma 中搜索相关的 JRXML 模板和组件(使用 rag_jrxml 语义分块管线)"""
try:
embeddings = get_embeddings()
from langchain_chroma import Chroma
from backend.rag_adapter import search_chunks
persist_dir = os.getenv("CHROMA_PERSIST_DIR", "./db/chroma")
if not os.path.exists(persist_dir) or not os.listdir(persist_dir):
state["retrieved_context"] = ""
return state
vectorstore = Chroma(
embedding_function=embeddings,
persist_directory=persist_dir,
)
user_input = state.get("user_input", "")
docs = vectorstore.similarity_search(user_input, k=5)
context_parts = []
for d in docs:
context_parts.append(d.page_content)
state["retrieved_context"] = "\n\n---\n\n".join(context_parts)
context = search_chunks(user_input, k=5)
state["retrieved_context"] = context
except Exception:
state["retrieved_context"] = ""
return state