feat(backend): integrate document deletion and grounded speech providers

Enable replay-safe document deletion and public deployment model identifiers with the forward voice-model schema revision.

Add GapGPT dialogue and ElevenLabs speech routing, strict extractive grounding, ten-source retrieval and regression coverage.

Validation: 199 targeted provider-free tests passed. The full provider-free run stalled and was interrupted; PostgreSQL acceptance was not run because TEST_DATABASE_URL is unset.
This commit is contained in:
amirhosein mazaheri
2026-10-20 09:00:37 +03:30
parent 2bffb9476a
commit 42400495af
27 changed files with 1003 additions and 28 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ from typing import Any
from app.modules.knowledge.lexical import LEXICAL_POLICY
MAX_BRANCH_CANDIDATES = 50
MAX_CHUNKS = 5
MAX_CHUNKS = 10
MAX_EVIDENCE_CHARACTERS = 12000
RETRIEVAL_POLICY = f"exact-first-cosine-id-50x2-whole-5-12000/{LEXICAL_POLICY}"
+22 -3
View File
@@ -3,6 +3,7 @@ from array import array
from contextlib import ExitStack, contextmanager
from dataclasses import asdict
import json
import re
from uuid import UUID, uuid4
from pydantic import BaseModel, ConfigDict, Field, ValidationError, field_validator
@@ -75,12 +76,28 @@ def sql_error(exc):
and exc.connection_invalidated)))
def clean_search_query(text: str) -> str:
cleaned = text
patterns = [
r"شرکت\s+شهرک[‌\s]*های\s+صنعتی\s+(?:استان\s+)?اصفهان",
r"شهرک[‌\s]*های\s+صنعتی\s+(?:استان\s+)?اصفهان",
r"شرکت\s+شهرک[‌\s]*های\s+صنعتی",
]
for pat in patterns:
sub = re.sub(pat, "", cleaned, flags=re.IGNORECASE).strip()
sub = re.sub(r"^(در|از|به|برای)\s+", "", sub).strip()
sub = re.sub(r"\s+(در|از|به|برای)$", "", sub).strip()
if len(sub) >= 3:
cleaned = sub
return re.sub(r"\s+", " ", cleaned).strip()
class SearchInput(BaseModel):
model_config = ConfigDict(extra="forbid", strict=True)
query: str = Field(
min_length=1,
max_length=2000,
description="Clean, concise search terms or entity names only (e.g. 'آقای دانش' or 'معاون برنامه ریزی'). Do NOT include conversational filler, meta-narration, or 'کاربر می‌پرسد'."
description="Clean, concise search terms or entity names only (e.g. 'آقای دانش' or 'معاون برنامه ریزی'). Do NOT include conversational filler, meta-narration, or 'کاربر می‌پرسد'. Never append 'شهرک‌های صنعتی اصفهان' or expand 'شرکت'."
)
context: str | None = Field(
default=None,
@@ -93,8 +110,10 @@ class SearchInput(BaseModel):
def database_text(cls, value, info):
if value is not None:
validate_database_string(value)
if info.field_name == "query" and not value.strip():
raise ValueError("Search text cannot be blank")
if info.field_name == "query":
value = clean_search_query(value)
if not value.strip():
raise ValueError("Search text cannot be blank")
return value