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
+24 -2
View File
@@ -1,4 +1,9 @@
"""嵌入模型工厂:支持本地 sentence-transformers 和云端 API。"""
"""嵌入模型工厂:支持本地 Sentence-Transformers 和云端 API。
调用方式:
get_embeddings() → LangChain 兼容的 embeddings 对象
get_st_embeddings() → 原始 SentenceTransformer 实例
"""
import os
from dotenv import load_dotenv
@@ -7,6 +12,7 @@ load_dotenv()
def get_embeddings():
"""返回 LangChain 兼容的 embeddings 对象(用于 langchain_chroma 等)。"""
backend = os.getenv("EMBED_BACKEND", "local")
if backend == "cloud":
from langchain_openai import OpenAIEmbeddings
@@ -22,5 +28,21 @@ def get_embeddings():
except ImportError:
from langchain_community.embeddings import HuggingFaceEmbeddings
model = os.getenv("LOCAL_EMBED_MODEL", "Qwen/Qwen3-Embedding-0.6B")
model = os.getenv("RAG_EMBED_MODEL", os.getenv("LOCAL_EMBED_MODEL", "Qwen/Qwen3-Embedding-0.6B"))
return HuggingFaceEmbeddings(model_name=model)
def get_st_model():
"""返回原始 SentenceTransformer 实例(与 rag_jrxml 子模块使用方式一致)。"""
import torch
from sentence_transformers import SentenceTransformer
model_name = os.getenv("RAG_EMBED_MODEL", os.getenv("LOCAL_EMBED_MODEL", "Qwen/Qwen3-Embedding-0.6B"))
use_gpu = os.getenv("RAG_USE_GPU", "true").lower() in ("true", "1")
use_fp16 = os.getenv("RAG_USE_FP16", "true").lower() in ("true", "1")
device = "cuda" if (use_gpu and torch.cuda.is_available()) else "cpu"
model = SentenceTransformer(model_name, device=device)
if device == "cuda" and use_fp16:
model = model.half()
return model