PMFlow/backend/app/services/adaptive_rag_service/shared_part_01.py

16 lines
519 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Adaptive RAG shared lightweight text helpers."""
from __future__ import annotations
from .shared_imports import *
from .shared_utils import *
_LOOKUP_TRIM_CHARS = " \t\r\n,。,.!??::;;“”\"'()()[]【】<>《》`"
def normalize_lookup_fragment(value: Any, *, keep_spaces: bool = False, limit: int = 32) -> str:
text = str(value or "")
text = re.sub(r"\s+", " " if keep_spaces else "", text).strip(_LOOKUP_TRIM_CHARS)
if not text:
return ""
return text[: max(1, int(limit))]