Skip to content

search_preprocessing_workflow

django_spire.knowledge.intelligence.workflows.search_preprocessing_workflow

PREPROCESSING_CACHE_TIMEOUT = 3600 module-attribute

PreprocessedSearchQuery dataclass

corrected_query instance-attribute

expanded_terms instance-attribute

meaningful_words instance-attribute

original_query instance-attribute

search_phrases instance-attribute

all_search_terms property

primary_search_query property

preprocess_search_query

Source code in django_spire/knowledge/intelligence/workflows/search_preprocessing_workflow.py
def preprocess_search_query(
    query: str,
    use_cache: bool = True,
    llm_temperature: float = 0.3
) -> PreprocessedSearchQuery:
    if use_cache:
        cache_key = _get_cache_key(query)
        cached = cache.get(cache_key)

        if cached:
            return cached

    intel: PreprocessedQueryIntel = (
        SearchPreprocessingBot(llm_temperature=llm_temperature)
        .process(query=query)
    )

    result = PreprocessedSearchQuery(
        corrected_query=intel.corrected_query,
        expanded_terms=intel.expanded_terms,
        meaningful_words=intel.meaningful_words,
        original_query=query,
        search_phrases=intel.search_phrases,
    )

    if use_cache:
        cache.set(cache_key, result, PREPROCESSING_CACHE_TIMEOUT)

    return result