Update default embedding model and modify request models in local_rag.py and unified_rag.py
This commit is contained in:
@@ -27,7 +27,7 @@ LIB_ROOT.mkdir(parents=True, exist_ok=True)
|
|||||||
|
|
||||||
RAW_CORPUS_PROFILE = "per-file-default-v1"
|
RAW_CORPUS_PROFILE = "per-file-default-v1"
|
||||||
PREPARE_PROFILE = "selective-enrich-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_MODEL = "qwen3:4b"
|
||||||
DEFAULT_ENRICH_MIN_CHARS = 240
|
DEFAULT_ENRICH_MIN_CHARS = 240
|
||||||
DEFAULT_ENRICH_MAX_TEXT = 6000
|
DEFAULT_ENRICH_MAX_TEXT = 6000
|
||||||
@@ -60,7 +60,7 @@ class UpdateFileEnrichmentRequest(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class EmbedLibraryRequest(BaseModel):
|
class EmbedLibraryRequest(BaseModel):
|
||||||
embed_model: str = DEFAULT_EMBED_MODEL
|
embed_model: Optional[str] = None
|
||||||
ollama: str = "http://localhost:11434"
|
ollama: str = "http://localhost:11434"
|
||||||
target_chars: int = 2000
|
target_chars: int = 2000
|
||||||
overlap_chars: int = 200
|
overlap_chars: int = 200
|
||||||
@@ -71,7 +71,7 @@ class LibraryContextRequest(BaseModel):
|
|||||||
prompt: str
|
prompt: str
|
||||||
top_k: int = 5
|
top_k: int = 5
|
||||||
ollama: str = "http://localhost:11434"
|
ollama: str = "http://localhost:11434"
|
||||||
embed_model: str = DEFAULT_EMBED_MODEL
|
embed_model: Optional[str] = None
|
||||||
gen_model: str = "qwen3:4b"
|
gen_model: str = "qwen3:4b"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ import requests
|
|||||||
import threading
|
import threading
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
|
try:
|
||||||
|
from backend.rag.ollama_embeddings import resolve_embed_model
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
from .ollama_embeddings import resolve_embed_model
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
# Utilities
|
# 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 ""
|
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:
|
def embed_query(ollama_url: str, model: str, text: str, timeout_s: int = 60) -> np.ndarray:
|
||||||
r = requests.post(
|
resolved_model, vec = resolve_embed_model(
|
||||||
f"{ollama_url.rstrip('/')}/api/embeddings",
|
ollama_url,
|
||||||
json={"model": model, "prompt": text},
|
model,
|
||||||
|
probe_text=text,
|
||||||
timeout=timeout_s,
|
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")
|
return np.array(vec, dtype="float32")
|
||||||
|
|
||||||
def load_meta(store_path: str) -> Dict[int, Dict]:
|
def load_meta(store_path: str) -> Dict[int, Dict]:
|
||||||
@@ -630,7 +631,7 @@ def run_query(shadow_index: Path, shadow_store: Path,
|
|||||||
query=query,
|
query=query,
|
||||||
answer=answer,
|
answer=answer,
|
||||||
ollama=opts.get("ollama", "http://localhost:11434"),
|
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),
|
shadow_candidates=opts.get("shadow_candidates", 400),
|
||||||
content_candidates=opts.get("content_candidates", 600),
|
content_candidates=opts.get("content_candidates", 600),
|
||||||
doc_top=opts.get("doc_top", 40),
|
doc_top=opts.get("doc_top", 40),
|
||||||
|
|||||||
Reference in New Issue
Block a user