Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Infiniflow Ragflow QueryBase

From Leeroopedia
Knowledge Sources
Domains Search, NLP
Last Updated 2026-02-12 06:00 GMT

Overview

Concrete abstract base class for search query construction with text analysis utilities for Chinese and English text processing provided by the RAGFlow common library.

Description

The QueryBase class provides static methods for detecting Chinese text, escaping special regex characters, removing common stop words in both Chinese and English, adding spaces between mixed CJK/Latin text, and an abstract question method for subclasses to implement query generation strategies.

Usage

Subclass QueryBase when implementing a new search query construction strategy that needs multilingual text preprocessing. The static utility methods can also be used standalone.

Code Reference

Source Location

Signature

class QueryBase:
    @staticmethod
    def is_chinese(line: str) -> bool:
        """Detect if text is primarily Chinese."""

    @staticmethod
    def sub_special_char(line: str) -> str:
        """Escape special regex characters."""

    @staticmethod
    def rmWWW(txt: str) -> str:
        """Remove common stop words (Chinese and English)."""

    @staticmethod
    def add_space_between_eng_zh(txt: str) -> str:
        """Add spaces between English and Chinese text."""

    def question(self, text: str, tbl: str, min_match: float):
        """Abstract method for query generation."""

Import

from common.query_base import QueryBase

I/O Contract

Inputs

Name Type Required Description
line str Yes Text to analyze for language detection
txt str Yes Text to preprocess
text str Yes Query text (for question method)
tbl str Yes Target table/index name
min_match float Yes Minimum match threshold

Outputs

Name Type Description
is_chinese() returns bool Whether text is primarily Chinese
rmWWW() returns str Text with stop words removed
question() returns varies Constructed query (subclass-defined)

Usage Examples

from common.query_base import QueryBase

is_zh = QueryBase.is_chinese("你好世界 hello")  # True
cleaned = QueryBase.rmWWW("the quick brown fox")  # "quick brown fox"
spaced = QueryBase.add_space_between_eng_zh("hello你好")  # "hello 你好"

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment