updates on catalog search and suggestions in backend

This commit is contained in:
sriram
2026-08-20 13:03:16 +05:30
parent e224043e26
commit fbb1356e47
14 changed files with 1177 additions and 11 deletions

View File

@@ -357,3 +357,24 @@ RAG_MAX_CONTEXT_CHARS = int(os.getenv("RAG_MAX_CONTEXT_CHARS", "4000"))
# if you want an extra cutoff on top of that.
_raw_max_distance = os.getenv("RAG_MAX_DISTANCE", "").strip()
RAG_MAX_DISTANCE = float(_raw_max_distance) if _raw_max_distance else None
# ---------------------------------------------------------------------------
# Catalog search (GET /api/search) and suggest (GET /api/suggest)
# ---------------------------------------------------------------------------
# Deliberately separate from RAG_MAX_TOP_K above. That ceiling exists to protect
# the LLM prompt budget in /api/chat, and raising it would degrade every chat
# answer. /api/search feeds a product grid, which has no such budget - sharing
# the constant is what silently truncated every brand search to 15 products.
SEARCH_DEFAULT_TOP_K = int(os.getenv("SEARCH_DEFAULT_TOP_K", "60"))
# Mirrors the browse endpoints' le=100000 so a brand search can return exactly
# the same set as GET /api/brands/{brand}/products.
SEARCH_MAX_TOP_K = int(os.getenv("SEARCH_MAX_TOP_K", "100000"))
# Separate, much smaller ceiling for the hybrid path: semantic_search multiplies
# top_k by 5 per brand table when a category/price filter is present, and every
# read does SELECT * (which drags the vector(384) embedding column over the wire).
SEARCH_HYBRID_MAX_TOP_K = int(os.getenv("SEARCH_HYBRID_MAX_TOP_K", "100"))
SEARCH_LEXICAL_CANDIDATES = int(os.getenv("SEARCH_LEXICAL_CANDIDATES", "200"))
SUGGEST_DEFAULT_LIMIT = int(os.getenv("SUGGEST_DEFAULT_LIMIT", "8"))
SUGGEST_MIN_QUERY_LEN = int(os.getenv("SUGGEST_MIN_QUERY_LEN", "2"))
SUGGEST_FUZZY_MIN_RATIO = float(os.getenv("SUGGEST_FUZZY_MIN_RATIO", "0.72"))