Update default embedding model and modify request models in local_rag.py and unified_rag.py

This commit is contained in:
2026-03-19 22:34:16 +01:00
parent dce97b45cb
commit e8b9a437d5
2 changed files with 13 additions and 12 deletions

View File

@@ -27,7 +27,7 @@ LIB_ROOT.mkdir(parents=True, exist_ok=True)
RAW_CORPUS_PROFILE = "per-file-default-v1"
PREPARE_PROFILE = "selective-enrich-v1"
DEFAULT_EMBED_MODEL = "dengcao/Qwen3-Embedding-0.6B:F16"
DEFAULT_EMBED_MODEL = "bge-m3:latest"
DEFAULT_ENRICH_MODEL = "qwen3:4b"
DEFAULT_ENRICH_MIN_CHARS = 240
DEFAULT_ENRICH_MAX_TEXT = 6000
@@ -60,7 +60,7 @@ class UpdateFileEnrichmentRequest(BaseModel):
class EmbedLibraryRequest(BaseModel):
embed_model: str = DEFAULT_EMBED_MODEL
embed_model: Optional[str] = None
ollama: str = "http://localhost:11434"
target_chars: int = 2000
overlap_chars: int = 200
@@ -71,7 +71,7 @@ class LibraryContextRequest(BaseModel):
prompt: str
top_k: int = 5
ollama: str = "http://localhost:11434"
embed_model: str = DEFAULT_EMBED_MODEL
embed_model: Optional[str] = None
gen_model: str = "qwen3:4b"

View File

@@ -31,6 +31,11 @@ import requests
import threading
from typing import Callable
try:
from backend.rag.ollama_embeddings import resolve_embed_model
except ModuleNotFoundError:
from .ollama_embeddings import resolve_embed_model
# -----------------------------
# Utilities
# -----------------------------
@@ -64,16 +69,12 @@ def pick_any_text(rec: Dict) -> str:
return rec.get("text") or rec.get("shadow_text") or rec.get("content") or rec.get("body") or ""
def embed_query(ollama_url: str, model: str, text: str, timeout_s: int = 60) -> np.ndarray:
r = requests.post(
f"{ollama_url.rstrip('/')}/api/embeddings",
json={"model": model, "prompt": text},
resolved_model, vec = resolve_embed_model(
ollama_url,
model,
probe_text=text,
timeout=timeout_s,
)
r.raise_for_status()
data = r.json()
vec = data.get("embedding") or (data.get("embeddings") or [None])[0]
if vec is None:
raise RuntimeError("Ollama /api/embeddings returned no vector.")
return np.array(vec, dtype="float32")
def load_meta(store_path: str) -> Dict[int, Dict]:
@@ -630,7 +631,7 @@ def run_query(shadow_index: Path, shadow_store: Path,
query=query,
answer=answer,
ollama=opts.get("ollama", "http://localhost:11434"),
embed_model=opts.get("embed_model", "dengcao/Qwen3-Embedding-0.6B:F16"),
embed_model=opts.get("embed_model", "bge-m3:latest"),
shadow_candidates=opts.get("shadow_candidates", 400),
content_candidates=opts.get("content_candidates", 600),
doc_top=opts.get("doc_top", 40),